Browse Source

更好的匿名

pull/4/head
欧醚 4 years ago
parent
commit
95ff45bb7d
2 changed files with 21 additions and 14 deletions
  1. +18
    -14
      app/controllers/api/v1/statuses_controller.rb
  2. +3
    -0
      config/initializers/new_features.rb

+ 18
- 14
app/controllers/api/v1/statuses_controller.rb View File

@ -1,5 +1,21 @@
# frozen_string_literal: true
class AnonTag
@@namelist = (f = Rails.configuration.x.anon_namelist) ? File.readlines(f).collect(&:strip) : ['Alice', 'Bob', 'Carol', 'Dave']
@@used_name = []
@@map = {}
def self.get_or_generate(pid)
if !@@map[pid]
@@map[pid] = (@@namelist - @@used_name).sample()
@@used_name.append(@@map[pid])
end
@@map[pid]
end
end
class Api::V1::StatusesController < Api::BaseController
include Authorization
@ -38,22 +54,10 @@ class Api::V1::StatusesController < Api::BaseController
render json: @context, serializer: REST::ContextSerializer, relationships: StatusRelationshipsPresenter.new(statuses, current_user&.account_id)
end
def to_cn(n)
case Time.new.wday
when 0, 3
"秦汉魏晋隋唐宋元明清"[n % 10] + [n % 20873, n % 20899].map{|i| i+0x4e00}.pack('U*')
when 1, 4, 6
"甲乙丙丁戊己庚辛壬癸"[n % 10] + [n % 20873, n % 20899].map{|i| i+0x4e00}.pack('U*')
else
"鼠牛虎兔龙蛇马羊猴鸡狗猪" [n % 12] + [n % 20873, n % 20899].map{|i| i+0x4e00}.pack('U*')
end
end
def create
p Rails.configuration.x.anon_tag
anon = Rails.configuration.x.anon_acc && status_params[:status].end_with?(Rails.configuration.x.anon_tag)
anon = Rails.configuration.x.anon_acc && status_params[:status].end_with?(Rails.configuration.x.anon_tag) && AnonTag.get_or_generate(current_user.account_id)
sender = anon ? Account.find(Rails.configuration.x.anon_acc) : current_user.account
st_text = anon ? ("$#{to_cn(7919**(current_account.id + 1000 * Time.new.day) % 1000000007)}:\n" + status_params[:status][0..4990]) : status_params[:status]
st_text = anon ? ("[#{anon}]:\n#{status_params[:status]}"[0..5000]) : status_params[:status]
@status = PostStatusService.new.call(sender,
text: st_text,

+ 3
- 0
config/initializers/new_features.rb View File

@ -1,7 +1,10 @@
# frozen_string_literal: true
Rails.application.configure do
config.x.email_default_domain = ENV.fetch('EMAIL_DEFAULT_DOMAIN') { '???.edu.cn' }
config.x.tree_address = ENV.fetch('TREE_ADDRESS') {''}
config.x.anon_tag = ENV.fetch('ANON_TAG') {'[mask]'}
config.x.anon_acc = ENV.fetch('ANON_ACC') {''}
config.x.anon_namelist = ENV.fetch('ANON_NAME_LIST') {''}
end

Loading…
Cancel
Save