MCPcopy Create free account
hub / github.com/hydro-dev/Hydro / get

Method get

packages/hydrooj/src/handler/problem.ts:380–424  ·  view source on GitHub ↗
(...args: any[])

Source from the content-addressed store, hash-verified

378 @query('tid', Types.ObjectId, true)
379 @query('pjax', Types.Boolean)
380 async get(...args: any[]) {
381 // Navigate to current additional file download
382 // e.g. ![img](file://a.jpg) will navigate to ![img](./pid/file/a.jpg)
383 if (!this.request.json || args[2]) {
384 this.response.body.pdoc.content = this.response.body.pdoc.content
385 .replace(/file:\/\/([^ \n)\\"]+)/g, (str: string) => {
386 const info = str.match(/file:\/\/([^ \n)\\"]+)/);
387 const fileinfo = info[1];
388 let filename = fileinfo.split('?')[0]; // remove querystring
389 try {
390 filename = decodeURIComponent(filename);
391 } catch (e) { }
392 if (!this.pdoc.additional_file?.find((i) => i.name === filename)) return str;
393 if (!args[1]) return `./${this.pdoc.docId}/file/${fileinfo}`;
394 return `./${this.pdoc.docId}/file/${fileinfo}${fileinfo.includes('?') ? '&' : '?'}tid=${args[1]}`;
395 });
396 }
397 this.response.body.page_name = this.tdoc
398 ? this.tdoc.rule === 'homework'
399 ? 'homework_detail_problem'
400 : 'contest_detail_problem'
401 : 'problem_detail';
402 if (args[2]) {
403 const data = { pdoc: this.pdoc, tdoc: this.tdoc };
404 this.response.body = {
405 title: this.renderTitle(this.response.body.page_name),
406 fragments: [
407 { html: await this.renderHTML('partials/problem_description.html', data) },
408 ],
409 raw: data,
410 };
411 }
412 if (!this.response.body.tdoc) {
413 if (this.psdoc?.rid) {
414 this.response.body.rdoc = await record.get(this.args.domainId, this.psdoc.rid);
415 }
416 [this.response.body.ctdocs, this.response.body.htdocs] = (await Promise.all([
417 contest.getRelated(this.args.domainId, this.pdoc.docId),
418 contest.getRelated(this.args.domainId, this.pdoc.docId, 'homework'),
419 ])).map((tdocs) => tdocs.filter((tdoc) =>
420 this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_CONTEST) || !tdoc.assign?.length
421 || new Set(tdoc.assign).intersection(new Set(this.user.group)).size,
422 ));
423 }
424 }
425
426 @param('pid', Types.UnsignedInt)
427 async postRejudge(domainId: string, pid: number) {

Callers

nothing calls this directly

Calls 6

findMethod · 0.80
renderTitleMethod · 0.80
renderHTMLMethod · 0.80
hasPermMethod · 0.80
getMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected