From 192657c54ba4a06b6f5afff3e39904c193eef9fb Mon Sep 17 00:00:00 2001 From: Z Date: Fri, 10 Jul 2020 11:02:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E8=AE=B0=E5=8C=BF=E5=90=8D=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E5=88=B7=E6=96=B0=20=E8=B6=85=E8=BF=87=E4=B8=80?= =?UTF-8?q?=E5=A4=A9=E6=9C=AA=E4=BD=BF=E7=94=A8=E8=87=AA=E5=8A=A8=E5=88=B7?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/statuses_controller.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb index fbb165c8e..f1ff8b506 100644 --- a/app/controllers/api/v1/statuses_controller.rb +++ b/app/controllers/api/v1/statuses_controller.rb @@ -4,14 +4,23 @@ class AnonTag @@namelist = (f = Rails.configuration.x.anon_namelist) ? File.readlines(f).collect(&:strip) : ['Alice', 'Bob', 'Carol', 'Dave'] @@used_name = [] @@map = {} + @@last_use = Time.now def self.get_or_generate(pid) + if Time.now - @@last_use > 1.day + @@last_use = Time.now + @@map = {} + @@used_name = [] + end + + pre = @@map.empty? ? '*' : '' + if !@@map[pid] @@map[pid] = (@@namelist - @@used_name).sample() @@used_name.append(@@map[pid]) end - @@map[pid] + pre + @@map[pid] end end