commit
efc9ffcb80
@ -0,0 +1,61 @@ |
||||
# frozen_string_literal: true |
||||
|
||||
class StatusesIndex < Chewy::Index |
||||
settings index: { refresh_interval: '15m' }, analysis: { |
||||
filter: { |
||||
english_stop: { |
||||
type: 'stop', |
||||
stopwords: '_english_', |
||||
}, |
||||
english_stemmer: { |
||||
type: 'stemmer', |
||||
language: 'english', |
||||
}, |
||||
english_possessive_stemmer: { |
||||
type: 'stemmer', |
||||
language: 'possessive_english', |
||||
}, |
||||
}, |
||||
analyzer: { |
||||
content: { |
||||
tokenizer: 'uax_url_email', |
||||
filter: %w( |
||||
english_possessive_stemmer |
||||
lowercase |
||||
asciifolding |
||||
cjk_width |
||||
english_stop |
||||
english_stemmer |
||||
), |
||||
}, |
||||
}, |
||||
} |
||||
|
||||
define_type ::Status.without_reblogs do |
||||
crutch :mentions do |collection| |
||||
data = ::Mention.where(status_id: collection.map(&:id)).pluck(:status_id, :account_id) |
||||
data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } |
||||
end |
||||
|
||||
crutch :favourites do |collection| |
||||
data = ::Favourite.where(status_id: collection.map(&:id)).pluck(:status_id, :account_id) |
||||
data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } |
||||
end |
||||
|
||||
crutch :reblogs do |collection| |
||||
data = ::Status.where(reblog_of_id: collection.map(&:id)).pluck(:reblog_of_id, :account_id) |
||||
data.each.with_object({}) { |(id, name), result| (result[id] ||= []).push(name) } |
||||
end |
||||
|
||||
root date_detection: false do |
||||
field :account_id, type: 'long' |
||||
|
||||
field :text, type: 'text', value: ->(status) { [status.spoiler_text, Formatter.instance.plaintext(status)].join("\n\n") } do |
||||
field :stemmed, type: 'text', analyzer: 'content' |
||||
end |
||||
|
||||
field :searchable_by, type: 'long', value: ->(status, crutches) { status.searchable_by(crutches) } |
||||
field :created_at, type: 'date' |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,22 @@ |
||||
enabled = ENV['ES_ENABLED'] == 'true' |
||||
host = ENV.fetch('ES_HOST') { 'localhost' } |
||||
port = ENV.fetch('ES_PORT') { 9200 } |
||||
fallback_prefix = ENV.fetch('REDIS_NAMESPACE') { nil } |
||||
prefix = ENV.fetch('ES_PREFIX') { fallback_prefix } |
||||
|
||||
Chewy.settings = { |
||||
host: "#{host}:#{port}", |
||||
prefix: prefix, |
||||
enabled: enabled, |
||||
journal: false, |
||||
} |
||||
|
||||
Chewy.root_strategy = enabled ? :sidekiq : :bypass |
||||
|
||||
module Chewy |
||||
class << self |
||||
def enabled? |
||||
settings[:enabled] |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,11 @@ |
||||
HTTP/1.1 200 OK |
||||
Server: nginx/1.6.2 |
||||
Date: Sun, 20 Mar 2016 11:13:16 GMT |
||||
Content-Type: application/jrd+json |
||||
Transfer-Encoding: chunked |
||||
Connection: keep-alive |
||||
Access-Control-Allow-Origin: * |
||||
Vary: Accept-Encoding,Cookie |
||||
Strict-Transport-Security: max-age=31536000; includeSubdomains; |
||||
|
||||
{"subject":"acct:localhost@kickass.zone","aliases":["https:\/\/kickass.zone\/user\/7477","https:\/\/kickass.zone\/gargron","https:\/\/kickass.zone\/index.php\/user\/7477","https:\/\/kickass.zone\/index.php\/gargron"],"links":[{"rel":"http:\/\/webfinger.net\/rel\/profile-page","type":"text\/html","href":"https:\/\/kickass.zone\/gargron"},{"rel":"http:\/\/gmpg.org\/xfn\/11","type":"text\/html","href":"https:\/\/kickass.zone\/gargron"},{"rel":"describedby","type":"application\/rdf+xml","href":"https:\/\/kickass.zone\/gargron\/foaf"},{"rel":"http:\/\/apinamespace.org\/atom","type":"application\/atomsvc+xml","href":"https:\/\/kickass.zone\/api\/statusnet\/app\/service\/gargron.xml"},{"rel":"http:\/\/apinamespace.org\/twitter","href":"https:\/\/kickass.zone\/api\/"},{"rel":"http:\/\/specs.openid.net\/auth\/2.0\/provider","href":"https:\/\/kickass.zone\/gargron"},{"rel":"http:\/\/schemas.google.com\/g\/2010#updates-from","type":"application\/atom+xml","href":"https:\/\/kickass.zone\/api\/statuses\/user_timeline\/7477.atom"},{"rel":"magic-public-key","href":"data:application\/magic-public-key,RSA.1ZBkHTavLvxH3FzlKv4O6WtlILKRFfNami3_Rcu8EuogtXSYiS-bB6hElZfUCSHbC4uLemOA34PEhz__CDMozax1iI_t8dzjDnh1x0iFSup7pSfW9iXk_WU3Dm74yWWW2jildY41vWgrEstuQ1dJ8vVFfSJ9T_tO4c-T9y8vDI8=.AQAB"},{"rel":"salmon","href":"https:\/\/kickass.zone\/main\/salmon\/user\/7477"},{"rel":"http:\/\/salmon-protocol.org\/ns\/salmon-replies","href":"https:\/\/kickass.zone\/main\/salmon\/user\/7477"},{"rel":"http:\/\/salmon-protocol.org\/ns\/salmon-mention","href":"https:\/\/kickass.zone\/main\/salmon\/user\/7477"},{"rel":"http:\/\/ostatus.org\/schema\/1.0\/subscribe","template":"https:\/\/kickass.zone\/main\/ostatussub?profile={uri}"}]} |
@ -1,4 +1,71 @@ |
||||
require 'rails_helper' |
||||
|
||||
RSpec.describe FetchRemoteAccountService do |
||||
let(:url) { 'https://example.com' } |
||||
let(:prefetched_body) { nil } |
||||
let(:protocol) { :ostatus } |
||||
subject { FetchRemoteAccountService.new.call(url, prefetched_body, protocol) } |
||||
|
||||
let(:actor) do |
||||
{ |
||||
'@context': 'https://www.w3.org/ns/activitystreams', |
||||
id: 'https://example.com/alice', |
||||
type: 'Person', |
||||
preferredUsername: 'alice', |
||||
name: 'Alice', |
||||
summary: 'Foo bar', |
||||
inbox: 'http://example.com/alice/inbox', |
||||
} |
||||
end |
||||
|
||||
let(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice' }] } } |
||||
let(:xml) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'xml', 'mastodon.atom')) } |
||||
|
||||
shared_examples 'return Account' do |
||||
it { is_expected.to be_an Account } |
||||
end |
||||
|
||||
context 'protocol is :activitypub' do |
||||
let(:prefetched_body) { Oj.dump(actor) } |
||||
let(:protocol) { :activitypub } |
||||
|
||||
before do |
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) |
||||
end |
||||
|
||||
include_examples 'return Account' |
||||
end |
||||
|
||||
context 'protocol is :ostatus' do |
||||
let(:prefetched_body) { xml } |
||||
let(:protocol) { :ostatus } |
||||
|
||||
before do |
||||
stub_request(:get, "https://kickass.zone/.well-known/webfinger?resource=acct:localhost@kickass.zone").to_return(request_fixture('webfinger-hacker3.txt')) |
||||
stub_request(:get, "https://kickass.zone/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt')) |
||||
end |
||||
|
||||
include_examples 'return Account' |
||||
end |
||||
|
||||
context 'when prefetched_body is nil' do |
||||
context 'protocol is :activitypub' do |
||||
before do |
||||
stub_request(:get, url).to_return(status: 200, body: Oj.dump(actor), headers: { 'Content-Type' => 'application/activity+json' }) |
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: Oj.dump(webfinger), headers: { 'Content-Type': 'application/jrd+json' }) |
||||
end |
||||
|
||||
include_examples 'return Account' |
||||
end |
||||
|
||||
context 'protocol is :ostatus' do |
||||
before do |
||||
stub_request(:get, url).to_return(status: 200, body: xml, headers: { 'Content-Type' => 'application/atom+xml' }) |
||||
stub_request(:get, "https://kickass.zone/.well-known/webfinger?resource=acct:localhost@kickass.zone").to_return(request_fixture('webfinger-hacker3.txt')) |
||||
stub_request(:get, "https://kickass.zone/api/statuses/user_timeline/7477.atom").to_return(request_fixture('feed.txt')) |
||||
end |
||||
|
||||
include_examples 'return Account' |
||||
end |
||||
end |
||||
end |
||||
|
Loading…
Reference in new issue