Skip to content

Commit

Permalink
Merge pull request #3667 from pooza/4_31_2
Browse files Browse the repository at this point in the history
4.31.2
  • Loading branch information
pooza committed May 3, 2024
2 parents e1ddf48 + 1cca98c commit ecd048d
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.0
ruby-version: 3.3.1
- name: apt install
run: |
sudo apt update
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.0
3.3.1
9 changes: 5 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ GEM
mongo (2.20.0)
bson (>= 4.14.1, < 6.0.0)
multi_json (1.15.0)
multi_xml (0.6.0)
multi_xml (0.7.1)
bigdecimal (~> 3.1)
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
mutex_m (0.2.0)
Expand Down Expand Up @@ -340,7 +341,7 @@ GEM
sassc (2.4.0)
ffi (~> 1.9)
securerandom (0.3.1)
sequel (5.79.0)
sequel (5.80.0)
bigdecimal
set (1.1.0)
sidekiq (7.2.4)
Expand Down Expand Up @@ -429,7 +430,7 @@ DEPENDENCIES
yamllint

RUBY VERSION
ruby 3.3.0p0
ruby 3.3.1p55

BUNDLED WITH
2.5.7
2.5.9
2 changes: 1 addition & 1 deletion app/lib/mulukhiya/controller/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class APIController < Controller

get '/program/works/:id/episodes' do
raise Ginseng::AuthError, 'Unauthorized' unless annict = account_class.info_account.annict
@renderer.message = annict.episodes(params[:id]).map do |episode|
@renderer.message = annict.episodes(params[:id].to_i).map do |episode|
episode.merge(
url: episode['url'].to_s,
hashtag_url: episode['hashtag_uri'].to_s,
Expand Down
33 changes: 14 additions & 19 deletions app/lib/mulukhiya/service/annict_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ class AnnictService
include SNSMethods
attr_reader :timestamps, :sns

INVALID_KEYWORD = '__??!!__'.freeze

def initialize(token = nil, guest: true)
@token = (token.decrypt rescue token)
@guest = guest
Expand Down Expand Up @@ -39,22 +37,19 @@ def account
end

def works(keyword = nil)
keywords = [keyword] if keyword.present?
keywords = self.class.keywords unless keywords.present?
keywords = [INVALID_KEYWORD] unless keywords.present?
all = keywords.inject([]) do |entries, title|
works = query(:works, {title:}).dig('data', 'searchWorks', 'edges').map do |work|
self.class.create_work_info(work['node'])
end
entries.concat(works)
titles = keyword.split(/\s+/) if keyword.present?
titles = self.class.keywords unless titles.present?
return [] unless titles.present?
works = query(:works, {titles:}).dig('data', 'searchWorks', 'edges').map do |work|
self.class.create_work_info(work['node'])
end
all.concat(account[:works]) if viewers_works?
all.uniq! {|v| v['annictId']}
return all.sort_by {|v| (v['seasonYear'].to_i * 100_000) + v['annictId']}.reverse
works.concat(account[:works]) if viewers_works?
works.uniq! {|v| v['annictId']}
return works.sort_by {|v| (v['seasonYear'].to_i * 100_000) + v['annictId']}.reverse
end

def episodes(id)
return unless entries = query(:episodes, {id:}).dig('data', 'searchWorks', 'nodes')
return unless entries = query(:episodes, {ids: [id]}).dig('data', 'searchWorks', 'nodes')
all = []
entries.map {|v| v.dig('episodes', 'nodes')}.each do |episodes|
episodes.each do |episode|
Expand Down Expand Up @@ -315,13 +310,13 @@ def crawlable?(activity, params)
return keywords.any? {|v| activity.to_json.include?(v)}
end

def query(template, params = {})
path = File.join(Environment.dir, 'app/query/annict', "#{template}.graphql.erb")
template = Template.new(path)
template.params = params
def query(template, variables = nil)
query = File.read(File.join(Environment.dir, 'app/query/annict', "#{template}.graphql"))
body = {query:}
body[:variables] = variables.deep_stringify_keys if variables
endpoint = Ginseng::URI.parse(config['/annict/urls/api/graphql'])
response = graphql_service.post(endpoint.path, {
body: {query: template.to_s},
body: body.to_json,
headers: {Authorization: "Bearer #{@token}"},
timeout: config['/annict/timeout'],
}).parsed_response
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
query {
viewer {
annictId
name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
query {
viewer {
annictId
name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
searchWorks (annictIds: [<%= params[:id].to_i.to_json %>]) {
query ($ids: [Int!]) {
searchWorks (annictIds: $ids) {
nodes {
annictId
title
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
query ($titles: [String!]) {
viewer {
annictId
name
Expand All @@ -14,10 +14,7 @@
}
}
}
searchWorks (
titles: <%= params[:title].to_json %>,
orderBy: {field: SEASON, direction: DESC}
) {
searchWorks (titles: $titles, orderBy: {field: SEASON, direction: DESC}) {
edges {
node {
annictId
Expand Down
2 changes: 1 addition & 1 deletion config/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ package:
- tkoishi@b-shock.co.jp
license: MIT
url: https://github.com/pooza/mulukhiya-toot-proxy
version: 4.31.1
version: 4.31.2
parser:
note:
fields:
Expand Down

0 comments on commit ecd048d

Please sign in to comment.