|
2 | 2 | import { LRUCache } from 'lru-cache'; |
3 | 3 | import moment from 'moment'; |
4 | 4 | import { |
5 | | - _, avatar, BadRequestError, ContestModel, ContestNotEndedError, Context, db, findFileSync, |
| 5 | + _, avatar, ContestModel, ContestNotEndedError, Context, db, findFileSync, |
6 | 6 | ForbiddenError, fs, Handler, InvalidTokenError, ObjectId, param, parseTimeMS, PERM, ProblemConfig, ProblemModel, |
7 | 7 | randomstring, Schema, SettingModel, STATUS, STATUS_SHORT_TEXTS, STATUS_TEXTS, |
8 | 8 | SystemModel, TokenModel, Types, UserModel, Zip, |
@@ -89,12 +89,6 @@ export function apply(ctx: Context, config: ReturnType<typeof Config>) { |
89 | 89 | }); |
90 | 90 |
|
91 | 91 | async function generateCdpZip(tdoc) { |
92 | | - const serverUrl = SystemModel.get('server.url'); |
93 | | - try { |
94 | | - new URL(serverUrl); |
95 | | - } catch (e) { |
96 | | - throw new BadRequestError('Server URL not set'); |
97 | | - } |
98 | 92 | let token = 0; |
99 | 93 | const getFeed = (type: string, data: any) => ({ |
100 | 94 | type, id: data.id, data, token: `t${token++}`, |
@@ -168,7 +162,7 @@ export function apply(ctx: Context, config: ReturnType<typeof Config>) { |
168 | 162 | group_ids: i.group.map((j) => groupId[j]), |
169 | 163 | organization_id: orgId[i.organization], |
170 | 164 | photo: [{ href: `contest/${tdoc._id}/teams/${i.team_id}/photo`, filename: 'photo.png', mime: 'image/png', width: 1920, height: 1080 }], |
171 | | - logo: [{ href: new URL(i.avatar, serverUrl).toString(), filename: 'logo.webp', mime: 'image/webp', width: 128, height: 128 }], |
| 165 | + logo: [{ href: new URL(i.avatar, SystemModel.get('server.url')).toString(), filename: 'logo.webp', mime: 'image/webp', width: 128, height: 128 }], |
172 | 166 | })), |
173 | 167 | ...tdoc.pids.map((i, idx) => getFeed('problems', { |
174 | 168 | id: `${i}`, label: String.fromCharCode(65 + idx), name: pdict[i].title, ordinal: idx, |
@@ -268,17 +262,11 @@ export function apply(ctx: Context, config: ReturnType<typeof Config>) { |
268 | 262 | async display({ tdoc }) { |
269 | 263 | if (!this.user.own(tdoc)) this.checkPerm(PERM.PERM_EDIT_CONTEST); |
270 | 264 | if (!ContestModel.isDone(tdoc)) throw new ContestNotEndedError(); |
271 | | - const serverUrl = SystemModel.get('server.url'); |
272 | | - try { |
273 | | - new URL(serverUrl); |
274 | | - } catch (e) { |
275 | | - throw new BadRequestError('Server URL not set'); |
276 | | - } |
277 | 265 | const [tokenId] = await TokenModel.add( |
278 | 266 | TokenModel.TYPE_EXPORT, 600, |
279 | 267 | { domainId: tdoc.domainId, contestId: tdoc._id }, |
280 | 268 | ); |
281 | | - const source = new URL(`/d/${tdoc.domainId}/contest/${tdoc._id}/resolver-cdp/${tokenId}`, serverUrl).toString(); |
| 269 | + const source = new URL(`/d/${tdoc.domainId}/contest/${tdoc._id}/resolver-cdp/${tokenId}`, SystemModel.get('server.url')).toString(); |
282 | 270 | const target = new URL('https://resolver.hydrooj.com'); |
283 | 271 | target.searchParams.set('source', source); |
284 | 272 | target.searchParams.set('mode', tdoc.rule === 'oi' ? 'oi' : 'acm'); |
|
0 commit comments