Browse Source

feat: support anonymous

closed-social-glitch-2
欧醚 1 year ago
parent
commit
35719f6040
2 changed files with 29 additions and 2 deletions
  1. +19
    -2
      app/controllers/api/v1/statuses_controller.rb
  2. +10
    -0
      config/initializers/new_feature.rb

+ 19
- 2
app/controllers/api/v1/statuses_controller.rb View File

@ -50,10 +50,27 @@ class Api::V1::StatusesController < Api::BaseController
render json: @context, serializer: REST::ContextSerializer, relationships: StatusRelationshipsPresenter.new(statuses, current_user&.account_id) render json: @context, serializer: REST::ContextSerializer, relationships: StatusRelationshipsPresenter.new(statuses, current_user&.account_id)
end end
def generate_anon_name(input, namelist, note)
name = namelist[Digest::SHA2.hexdigest(input).to_i(16) % namelist.size]
name.in?(note) ? nil : name
end
def create def create
ori_text = status_params[:status]
anon = Rails.configuration.x.anon
anon_name = anon.acc &&
ori_text.strip.end_with?(anon.tag, "#{anon.tag} 👁️") &&
generate_anon_name(
current_user.account.username + anon.salt + 5.hours.ago.strftime('%D'),
anon.namelist,
Account.find(anon.acc).note
)
sender = anon_name ? Account.find(anon.acc) : current_user.account
st_text = anon_name ? "[#{anon_name}]:\n#{ori_text}" : ori_text
@status = PostStatusService.new.call( @status = PostStatusService.new.call(
current_user.account,
text: status_params[:status],
sender,
text: st_text,
thread: @thread, thread: @thread,
media_ids: status_params[:media_ids], media_ids: status_params[:media_ids],
sensitive: status_params[:sensitive], sensitive: status_params[:sensitive],

+ 10
- 0
config/initializers/new_feature.rb View File

@ -0,0 +1,10 @@
# frozen_string_literal: true
Rails.application.configure do
config.x.email_default_domain = ENV.fetch('EMAIL_DEFAULT_DOMAIN', '')
config.x.email_regex = ENV.fetch('EMAIL_REGEX', nil)
config.x.anon.tag = ENV.fetch('ANON_TAG', '[mask]')
config.x.anon.acc = ENV.fetch('ANON_ACC', nil)
config.x.anon.namelist = ENV['ANON_NAME_LIST'] ? File.readlines(ENV['ANON_NAME_LIST']).collect(&:strip) : ['Alice', 'Bob', 'Carol', 'Dave']
config.x.anon.salt = (1..42).map { ('a'..'z').to_a.sample }.join
end

Loading…
Cancel
Save