MCPcopy Index your code
hub / github.com/hydro-dev/Hydro / post

Method post

packages/hydrooj/src/handler/problem.ts:1007–1028  ·  view source on GitHub ↗
(
        domainId: string, title: string, content: string, pid: string | number = '',
        hidden = false, difficulty = 0, tag: string[] = [],
    )

Source from the content-addressed store, hash-verified

1005 @post('difficulty', Types.PositiveInt, (i) => +i <= 10, true)
1006 @post('tag', Types.Content, true, null, parseCategory)
1007 async post(
1008 domainId: string, title: string, content: string, pid: string | number = '',
1009 hidden = false, difficulty = 0, tag: string[] = [],
1010 ) {
1011 if (typeof pid !== 'string') pid = `P${pid}`;
1012 if (pid && await problem.get(domainId, pid)) throw new ProblemAlreadyExistError(pid);
1013 const docId = await problem.add(domainId, pid, title, content, this.user._id, tag ?? [], { hidden, difficulty });
1014 const files = new Set(Array.from(content.matchAll(/file:\/\/([\w-]+\.[a-zA-Z0-9]+)/g)).map((i) => i[1]));
1015 const tasks = [];
1016 for (const file of files) {
1017 if (this.user._files.find((i) => i.name === file)) {
1018 tasks.push(
1019 storage.rename(`user/${this.user._id}/${file}`, `problem/${domainId}/${docId}/additional_file/${file}`, this.user._id)
1020 .then(() => problem.addAdditionalFile(domainId, docId, file, '', this.user._id, true)),
1021 user.setById(this.user._id, { _files: this.user._files.filter((i) => i.name !== file) }),
1022 );
1023 }
1024 }
1025 await Promise.all(tasks);
1026 this.response.body = { pid: pid || docId };
1027 this.response.redirect = this.url('problem_files', { pid: pid || docId });
1028 }
1029}
1030
1031export const ProblemApi = {

Callers

nothing calls this directly

Calls 10

findMethod · 0.80
thenMethod · 0.80
renameMethod · 0.80
addAdditionalFileMethod · 0.80
setByIdMethod · 0.80
urlMethod · 0.80
getMethod · 0.45
addMethod · 0.45
pushMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected