From b0ff456a4f28ea7e5aa758b65f9c9cf805acd625 Mon Sep 17 00:00:00 2001 From: undefined Date: Fri, 30 Apr 2021 01:05:32 +0800 Subject: [PATCH] remove useless package --- packages/syzoj-ng-api/handler.ts | 7 -- packages/syzoj-ng-api/handlers/problem.ts | 130 ---------------------- packages/syzoj-ng-api/package.json | 9 -- 3 files changed, 146 deletions(-) delete mode 100644 packages/syzoj-ng-api/handler.ts delete mode 100644 packages/syzoj-ng-api/handlers/problem.ts delete mode 100644 packages/syzoj-ng-api/package.json diff --git a/packages/syzoj-ng-api/handler.ts b/packages/syzoj-ng-api/handler.ts deleted file mode 100644 index 51a2f9e6c..000000000 --- a/packages/syzoj-ng-api/handler.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { apply as ApplyProblemHandler } from './handlers/problem'; - -export async function apply() { - await ApplyProblemHandler(); -} - -global.Hydro.handler.syzojApi = apply; diff --git a/packages/syzoj-ng-api/handlers/problem.ts b/packages/syzoj-ng-api/handlers/problem.ts deleted file mode 100644 index 515d71384..000000000 --- a/packages/syzoj-ng-api/handlers/problem.ts +++ /dev/null @@ -1,130 +0,0 @@ -import { FilterQuery } from 'mongodb'; -import { Pdoc } from 'hydrooj/dist/interface'; -import problem from 'hydrooj/dist/model/problem'; -import record from 'hydrooj/dist/model/record'; -import user from 'hydrooj/dist/model/user'; -import { PERM, PRIV } from 'hydrooj/dist/model/builtin'; -import { - Route, Handler, Types, post, -} from 'hydrooj/dist/service/server'; - -export class QueryProblemSetAPIHandler extends Handler { - @post('locale', Types.String, true) - @post('keyword', Types.String, true) - @post('ownerId', Types.Int, true) - @post('nonpublic', Types.Boolean, true) - @post('tagsIds', Types.Array, true) - @post('skipCount', Types.UnsignedInt, true) - @post('takeCount', Types.UnsignedInt, true) - async post( - domainId: string, locale: string, $search: string, - owner: number, nonpublic = false, tags = [], - skip = 0, take = 0, - ) { - if ( - (!this.user.hasPerm(PERM.PERM_VIEW_PROBLEM)) - || (nonpublic && !this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN)) - ) { - this.response.body = { error: 'PERMISSION_DENIED' }; - return; - } - const query: FilterQuery = {}; - if ($search) query.$text = { $search }; - if (tags?.length) query.$and = tags.map((tag) => ({ tag })); - if (owner) query.owner = owner; - if (!nonpublic) query.hidden = false; - const [raw, count] = await Promise.all([ - problem.getMulti(domainId, query).sort({ pid: 1, docId: 1 }) - .skip(skip).limit(take) - .toArray(), - problem.getMulti(domainId, query).count(), - ]); - const result = []; - for (const doc of raw) { - // eslint-disable-next-line no-await-in-loop - const [rdoc] = await record - .getUserInProblemMulti(domainId, this.user._id, doc.docId) - .sort({ _id: -1 }) - .limit(1) - .toArray(); - let locales = []; - try { - const ct = typeof doc.content === 'string' ? JSON.parse(doc.content) : doc.content; - if (ct instanceof Array) locales = [this.session.viewLang || this.user.viewLang]; - else locales = Object.keys(ct); - } catch (e) { - locales = [this.session.viewLang || this.user.viewLang]; - } - result.push({ - meta: { - id: doc.docId, - displayId: doc.pid, - type: 'Traditional', - isPublic: !doc.hidden, - publicTime: doc._id.getTimestamp(), - ownerId: doc.owner, - locales, - submissionCount: doc.nSubmit, - acceptedSubmissionCount: doc.nAccept, - }, - title: doc.title, - tags: [], // TODO - resultLocale: this.session.viewLang || this.user.viewLang, - submission: rdoc - ? { - id: rdoc._id, - isPublic: !doc.hidden, - codeLanguage: rdoc.lang, - answerSize: rdoc.code.length, - score: rdoc.score, - status: rdoc.status, - submitTime: rdoc._id.getTimestamp(), - timeUsed: rdoc.time, - memoryUsed: rdoc.memory, - } - : null, - }); - } - this.response.body = { - result, - count, - permissions: { - createProblem: this.user.hasPerm(PERM.PERM_CREATE_PROBLEM), - manageTags: this.user.hasPerm(PERM.PERM_EDIT_PROBLEM), - filterByOwner: this.user.hasPerm(PERM.PERM_VIEW_PROBLEM), - filterNonpublic: this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN), - }, - }; - if (owner) { - const udoc = await user.getById(domainId, owner); - this.response.body.filterOwner = { - id: udoc._id, - username: udoc.uname, - email: udoc.mail, - nickname: udoc.displayName || udoc.uname, - bio: udoc.bio, - avatar: { - type: udoc.avatar.split(':')[0], - key: udoc.avatar.split(':')[1], - }, - isAdmin: udoc.hasPriv(PRIV.PRIV_MANAGE_ALL_DOMAIN) || udoc.hasPerm(PERM.PERM_ADMIN), - acceptedProblemCount: udoc.nAccept, - submissionCount: udoc.nSubmit, - rating: udoc.rating, - registrationTime: udoc.regat, - }; - } - if (tags) { - this.response.body.filterTags = tags.map((tag) => ({ - id: tag, - name: tag, - color: '1', - nameLocale: locale, - })); - } - } -} - -export async function apply() { - Route('syzoj_api_problem_queryProblemSet', '/api/problem/queryProblemSet', QueryProblemSetAPIHandler); -} diff --git a/packages/syzoj-ng-api/package.json b/packages/syzoj-ng-api/package.json deleted file mode 100644 index 8dd9f936b..000000000 --- a/packages/syzoj-ng-api/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "@hydrooj/syzoj-ng-api", - "version": "0.0.2", - "description": "A syzoj-ng API interface", - "main": "package.json", - "repository": "https://github.com/hydro-dev/Hydro.git", - "author": "undefined ", - "license": "AGPL-3.0.only" -} \ No newline at end of file