Skip to content

Commit

Permalink
Merge branch 'cc004:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
666dechaoge authored Oct 16, 2024
2 parents b5cc7a4 + c5164a2 commit ae37f48
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions autopcr/db/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,9 +981,9 @@ def get_rank_promote_equip_demand(self, unit_id: int, start_rank: int, start_ran
(flow(self.unit_promotion_equip_count[unit_id].items())
.where(lambda x: x[0] >= start_rank and x[0] < target_rank)
.select(lambda x: x[1])
.sum(seed=Counter())) -
Counter((eInventoryType(eInventoryType.Equip), int(getattr(self.unit_promotion[unit_id][start_rank], f"equip_slot_{i}"))) for i in range(1, 7) if start_rank_equip_slot[i - 1]) +
Counter((eInventoryType(eInventoryType.Equip), int(getattr(self.unit_promotion[unit_id][target_rank], f"equip_slot_{i}"))) for i in range(1, 7) if target_rank_equip_slot[i - 1])
.sum(seed=Counter())) +
Counter((eInventoryType(eInventoryType.Equip), int(getattr(self.unit_promotion[unit_id][target_rank], f"equip_slot_{i}"))) for i in range(1, 7) if target_rank_equip_slot[i - 1]) -
Counter((eInventoryType(eInventoryType.Equip), int(getattr(self.unit_promotion[unit_id][start_rank], f"equip_slot_{i}"))) for i in range(1, 7) if start_rank_equip_slot[i - 1])
)
return ret

Expand Down
12 changes: 7 additions & 5 deletions autopcr/http_server/httpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def __init__(self, host = '0.0.0.0', port = 2, qq_mod = False):

self.web = Blueprint('web', __name__, static_folder=static_path)

# version check & rate limit
self.api_limit = Blueprint('api_limit', __name__, url_prefix = "/api")
self.api = Blueprint('api', __name__, url_prefix = "/api")

self.app = Blueprint('app', __name__, url_prefix = "/daily")
Expand All @@ -37,6 +39,7 @@ def __init__(self, host = '0.0.0.0', port = 2, qq_mod = False):

self.app.register_blueprint(self.web)
self.app.register_blueprint(self.api)
self.app.register_blueprint(self.api_limit)

self.host = host
self.port = port
Expand Down Expand Up @@ -76,16 +79,15 @@ async def inner(*args, **kwargs):

def configure_routes(self):

@self.api.before_request
@self.api_limit.before_request
async def check_app_version():
return None
version = request.headers.get('X-App-Version', None)
if version != APP_VERSION:
return f"后端期望前端版本为{APP_VERSION},请更新", 400
else:
return None

@self.api.errorhandler(RateLimitExceeded)
@self.api_limit.errorhandler(RateLimitExceeded)
async def handle_rate_limit_exceeded_error(error):
return "您冲得太快了,休息一下吧", 429

Expand Down Expand Up @@ -391,7 +393,7 @@ async def validate(): # TODO think to check login or not
validate_ok_dict[id] = ValidateInfo.from_dict(data)
return "", 200

@self.api.route('/login/qq', methods = ['POST'])
@self.api_limit.route('/login/qq', methods = ['POST'])
@rate_limit(1, timedelta(seconds=1))
@rate_limit(3, timedelta(minutes=1))
async def login_qq():
Expand All @@ -408,7 +410,7 @@ async def login_qq():
else:
return "无效的QQ或密码", 400

@self.api.route('/register', methods = ['POST'])
@self.api_limit.route('/register', methods = ['POST'])
@rate_limit(1, timedelta(minutes=1))
async def register():
data = await request.get_json()
Expand Down
2 changes: 1 addition & 1 deletion autopcr/module/modules/gacha.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async def do_task(self, client: pcrclient):
if res.campaign_info.fg10_exec_cnt == 0:
raise SkipError("今日份免费十连已使用")
cnt = res.campaign_info.fg10_exec_cnt
free_gacha_ids = set(gacha.gacha_id for gacha in gacha_list)
free_gacha_ids = set(gacha.gacha_id for gacha in gacha_list) & set(db.gacha_data)
open_gacha_ids = set(gacha.id for gacha in res.gacha_info)
open_free_gacha_ids = free_gacha_ids & open_gacha_ids
close_free_gacha_ids = free_gacha_ids - open_gacha_ids
Expand Down

0 comments on commit ae37f48

Please sign in to comment.