From 2c423822470ea23884991b5533be513473e3e4a1 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 9 Apr 2023 09:07:40 +0800 Subject: [PATCH] fix(remote_judger/luogu): cdn cc firewall --- remote_judger/src/providers/luogu.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/remote_judger/src/providers/luogu.ts b/remote_judger/src/providers/luogu.ts index 374cf7c..af570f7 100644 --- a/remote_judger/src/providers/luogu.ts +++ b/remote_judger/src/providers/luogu.ts @@ -193,7 +193,20 @@ export default class LuoguProvider implements IBasicProvider { } async safeGet(url: string) { - const res = await this.get(url); + const res = await this.get(url).ok(res => res.status < 400); + + if ([302, 301].includes(res.status)) { + if (res.header['set-cookie']) { + Array.from(res.header['set-cookie']).forEach((cookie: string) => { + const name = cookie.split('=')[0]; + const value = cookie.split('=')[1].split(';')[0]; + + this.setCookie(name, value); + }); + } + + return await this.get(url); + } if (res.text.startsWith('