migrate: add optional solution field

This commit is contained in:
undefined committed 2022-05-20 09:11:56 +08:00
1 parent bcf0938f90
commit 8582de2560
2 files changed
+18 -3

No files matched your search

+5 -3
View File
@@ -1,17 +1,19 @@
{ {
"name": "@hydrooj/migrate", "name": "@hydrooj/migrate",
"version": "0.1.0", "version": "0.1.1",
"main": "package.json", "main": "package.json",
"repository": "git@github.com:hydro-dev/Hydro.git", "repository": "git@github.com:hydro-dev/Hydro.git",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"devDependencies": { "devDependencies": {
"@types/mongodb": "^3.6.20", "@types/mongodb": "^3.6.20",
"@types/mysql": "^2.15.21" "@types/mysql": "^2.15.21",
"@types/turndown": "^5.0.1"
}, },
"dependencies": { "dependencies": {
"@hydrooj/utils": "workspace:*", "@hydrooj/utils": "workspace:*",
"mongodb": "^3.7.3", "mongodb": "^3.7.3",
"mysql": "^2.18.1" "mysql": "^2.18.1",
"turndown": "^7.1.1"
} }
} }
+13
View File
@@ -3,6 +3,7 @@
import fs from 'fs-extra'; import fs from 'fs-extra';
import { ObjectID } from 'mongodb'; import { ObjectID } from 'mongodb';
import mysql from 'mysql'; import mysql from 'mysql';
import TurndownService from 'turndown';
import { STATUS } from '@hydrooj/utils/lib/status'; import { STATUS } from '@hydrooj/utils/lib/status';
import { noop, Time } from '@hydrooj/utils/lib/utils'; import { noop, Time } from '@hydrooj/utils/lib/utils';
import { NotFoundError } from 'hydrooj/src/error'; import { NotFoundError } from 'hydrooj/src/error';
@@ -13,9 +14,15 @@ import * as contest from 'hydrooj/src/model/contest';
import domain from 'hydrooj/src/model/domain'; import domain from 'hydrooj/src/model/domain';
import problem from 'hydrooj/src/model/problem'; import problem from 'hydrooj/src/model/problem';
import record from 'hydrooj/src/model/record'; import record from 'hydrooj/src/model/record';
import SolutionModel from 'hydrooj/src/model/solution';
import * as system from 'hydrooj/src/model/system'; import * as system from 'hydrooj/src/model/system';
import user from 'hydrooj/src/model/user'; import user from 'hydrooj/src/model/user';
const turndown = new TurndownService({
codeBlockStyle: 'fenced',
bulletListMarker: '-',
});
const statusMap = { const statusMap = {
4: STATUS.STATUS_ACCEPTED, 4: STATUS.STATUS_ACCEPTED,
5: STATUS.STATUS_WRONG_ANSWER, 5: STATUS.STATUS_WRONG_ANSWER,
@@ -145,6 +152,8 @@ export async function run({
accepted int 11 Y 总ac次数 accepted int 11 Y 总ac次数
submit int 11 Y 总提交次数 submit int 11 Y 总提交次数
solved int 11 Y 解答(未用) solved int 11 Y 解答(未用)
solution #optional
*/ */
const pidMap: Record<string, number> = {}; const pidMap: Record<string, number> = {};
const [[{ 'count(*)': pcount }]] = await query('SELECT count(*) FROM `problem`'); const [[{ 'count(*)': pcount }]] = await query('SELECT count(*) FROM `problem`');
@@ -183,6 +192,10 @@ export async function run({
maintainer, maintainer,
html: true, html: true,
}); });
if (pdoc.solution) {
const md = turndown.turndown(pdoc.solution);
await SolutionModel.add(domainId, pidMap[pdoc.problem_id], 1, md);
}
} }
} }