Skip to content

Commit

Permalink
Merge pull request #923 from pooza/3_5_10
Browse files Browse the repository at this point in the history
3.5.10
  • Loading branch information
pooza committed Apr 3, 2020
2 parents d956962 + 097c27a commit aef1525
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Expand Up @@ -287,7 +287,7 @@ GEM
thread_safe (0.3.6)
thwait (0.1.0)
tilt (2.0.10)
tzinfo (1.2.6)
tzinfo (1.2.7)
thread_safe (~> 0.1)
unf (0.1.4)
unf_ext
Expand Down
2 changes: 1 addition & 1 deletion app/lib/mulukhiya/controller.rb
Expand Up @@ -19,7 +19,7 @@ class Controller < Ginseng::Web::Sinatra
@renderer.status = 422
@renderer.message = errors
elsif webhook = Webhook.create(params[:digest])
results = webhook.toot(params)
results = webhook.post(params)
@renderer.message = results.response.parsed_response
@renderer.status = results.response.code
else
Expand Down
1 change: 0 additions & 1 deletion app/lib/mulukhiya/controller/misskey_controller.rb
Expand Up @@ -8,7 +8,6 @@ class MisskeyController < Controller
@sns.token = params[:i]
end
@results.account = @sns.account
params[Environment.controller_class.status_field] ||= params[MastodonController.status_field]
end

post '/api/notes/create' do
Expand Down
7 changes: 4 additions & 3 deletions app/lib/mulukhiya/handler/amazon_url_nowplaying_handler.rb
Expand Up @@ -23,9 +23,10 @@ def updatable?(keyword)
def update(keyword)
return unless item = @items[keyword]
push(item.dig('ItemInfo', 'Title', 'DisplayValue'))
return unless contributor = item.dig('ItemInfo', 'ByLineInfo', 'Contributors')&.first
push(contributor['Name'])
tags.concat(ArtistParser.new(contributor['Name']).parse)
return unless contributors = item.dig('ItemInfo', 'ByLineInfo', 'Contributors')
contributors = contributors.map {|v| v['Name']}.join(', ')
push(contributors)
tags.concat(ArtistParser.new(contributors).parse)
end
end
end
4 changes: 4 additions & 0 deletions app/lib/mulukhiya/service/mastodon_service.rb
Expand Up @@ -13,6 +13,10 @@ def initialize(uri = nil, token = nil)
@token = token
end

alias note toot

alias post toot

def search(keyword, params = {})
params[:limit] ||= @config['/mastodon/search/limit']
return super(keyword, params)
Expand Down
2 changes: 2 additions & 0 deletions app/lib/mulukhiya/service/misskey_service.rb
Expand Up @@ -44,6 +44,8 @@ def note(body, params = {})

alias toot note

alias post note

def favourite(id, params = {})
headers = params[:headers] || {}
headers['X-Mulukhiya'] = package_class.full_name unless mulukhiya_enable?
Expand Down
8 changes: 6 additions & 2 deletions app/lib/mulukhiya/webhook.rb
Expand Up @@ -28,19 +28,23 @@ def to_json(opts = nil)
return @json
end

def toot(status)
def post(status)
status = {text: status} if status.is_a?(String)
body = {
Environment.controller_class.status_field => status[:text],
'visibility' => visibility,
'attachments' => status[:attachments] || [],
}
Handler.exec_all(:pre_webhook, body, {results: results, sns: @sns})
results.response = @sns.toot(body)
results.response = @sns.post(body)
Handler.exec_all(:post_webhook, body, {results: results, sns: @sns})
return results
end

alias toot post

alias note post

def self.create_digest(uri, token)
return Digest::SHA1.hexdigest({
sns: uri.to_s,
Expand Down
2 changes: 1 addition & 1 deletion app/lib/mulukhiya/worker/announcement_worker.rb
Expand Up @@ -13,7 +13,7 @@ def perform
return unless executable?
entries.each do |entry|
next if cache.member?(entry['id'])
service.toot(
service.post(
Environment.controller_class.status_field => create_body(entry, :sanitized),
'visibility' => Environment.controller_class.visibility_name('unlisted'),
)
Expand Down
2 changes: 1 addition & 1 deletion config/application.yaml
@@ -1,5 +1,5 @@
package:
version: 3.5.9
version: 3.5.10
url: https://github.com/pooza/mulukhiya-toot-proxy
description: 投稿内容の更新等を行うプロキシ。通称「モロヘイヤ」。
authors:
Expand Down
8 changes: 2 additions & 6 deletions test/webhook.rb
@@ -1,9 +1,5 @@
module Mulukhiya
class WebhookTest < TestCase
def setup
@account = Environment.test_account
end

def test_all
Webhook.all do |hook|
assert_kind_of(Webhook, hook)
Expand All @@ -12,7 +8,7 @@ def test_all

def test_create
Webhook.all do |hook|
assert_not_nil(Webhook.create(hook.digest))
assert_kind_of(Webhook, Webhook.create(hook.digest))
end
end

Expand All @@ -36,7 +32,7 @@ def test_uri

def test_to_json
Webhook.all do |hook|
assert(hook.to_json.present?)
assert_kind_of(Hash, JSON.parse(hook.to_json))
end
end
end
Expand Down
70 changes: 40 additions & 30 deletions views/config.slim
Expand Up @@ -31,11 +31,12 @@ html lang='ja'
.field-update-button-container
button v-on:click='updateDropbox' 更新
section
h3 Webhook
.field-container v-if='access_token'
h4 アクセストークン
textarea id='token_text' class='short' = '{{access_token}}'
i class='fas fa-clipboard' v-on:click='copyToken'
h3 Slack互換webhook
.inline-field-container
h4 トークン
input id='webhook_token_text' placeholder='webhookのアクセストークン' v-model='webhook_token' maxlength='256'
.field-update-button-container
button v-on:click='updateWebhook' 更新
.field-container v-if='webhook_url'
h4 URL
textarea id='webhook_text' = '{{webhook_url}}'
Expand Down Expand Up @@ -63,7 +64,7 @@ html lang='ja'
.then(e => {
this.result = jsyaml.safeDump(e.data.config)
if (e.data.config.webhook) {
this.access_token = e.data.config.webhook.token
this.webhook_token = e.data.config.webhook.token
this.webhook_url = e.data.config.webhook.url
this.curl_sample = `curl -H 'Content-Type: application/json' -X POST -d '{"text":"わたしが斬るのは、あなたじゃない!\\n絶ち切るのは弱さ。切り拓くは未来。心を貫く勇気の刃。\\nそれがわたし。王女様からもらった名前、キュアソードよ!"}' ${e.data.config.webhook.url}`
}
Expand All @@ -83,11 +84,6 @@ html lang='ja'
}
},
methods: {
copyToken: function () {
'use strict'
document.getElementById('token_text').select()
document.execCommand('copy')
},
copyWehbook: function () {
'use strict'
document.getElementById('webhook_text').select()
Expand All @@ -100,20 +96,16 @@ html lang='ja'
},
updateGrowi: function () {
'use strict'
const values = {
status: {
command: 'user_config',
growi: {url: null, token: null},
},
token: localStorage.getItem('mulukhiya_token'),
}
const values = {token: localStorage.getItem('mulukhiya_token')}
const command = {command: 'user_config', growi: {url: null, token: null}}
if (this.growi_url) {
values.status.growi.url = this.growi_url
command.growi.url = this.growi_url
}
if (this.growi_token) {
values.status.growi.token = this.growi_token
command.growi.token = this.growi_token
}
values.status = JSON.stringify(values.status)
values.status = JSON.stringify(command)
values.text = JSON.stringify(command)
document.body.style.cursor = 'wait'
axios.post('/mulukhiya/config', values)
.then(e => {
Expand All @@ -127,26 +119,44 @@ html lang='ja'
},
updateDropbox: function () {
'use strict'
const values = {
status: {
command: 'user_config',
dropbox: {token: null},
},
token: localStorage.getItem('mulukhiya_token'),
}
const values = {token: localStorage.getItem('mulukhiya_token')}
const command = {command: 'user_config', dropbox: {token: null}}
if (this.dropbox_token) {
values.status.dropbox.token = this.dropbox_token
command.dropbox.token = this.dropbox_token
}
values.status = JSON.stringify(command)
values.text = JSON.stringify(command)
document.body.style.cursor = 'wait'
axios.post('/mulukhiya/config', values)
.then(e => {
document.body.style.cursor = 'auto'
this.result = jsyaml.safeDump(e.data.config)
this.message = null
}).catch(e => {
document.body.style.cursor = 'auto'
this.message = e.response.data.error || e.message
})
},
updateWebhook: function () {
'use strict'
const values = {token: localStorage.getItem('mulukhiya_token')}
const command = {command: 'user_config', webhook: {token: null}}
if (this.webhook_token) {
command.webhook.token = this.webhook_token
}
values.status = JSON.stringify(values.status)
values.status = JSON.stringify(command)
values.text = JSON.stringify(command)
document.body.style.cursor = 'wait'
axios.post('/mulukhiya/config', values)
.then(e => {
document.body.style.cursor = 'auto'
this.result = jsyaml.safeDump(e.data.config)
this.message = null
this.webhook_url = e.data.config.webhook.url
}).catch(e => {
document.body.style.cursor = 'auto'
this.message = e.response.data.error || e.message
this.webhook_url = null
})
},
},
Expand Down
2 changes: 1 addition & 1 deletion views/default.sass
Expand Up @@ -137,7 +137,7 @@ textarea.short
border: 1px solid black
border-radius: 4px
display: inline-block
width: 500px
width: 600px
font-size: 1em
font-family: Inconsolata, monospace

Expand Down

0 comments on commit aef1525

Please sign in to comment.