From 46cb2e31ddce59bbb15fcbf42c19d4b03ddb4927 Mon Sep 17 00:00:00 2001 From: undefined Date: Wed, 24 Feb 2021 22:05:32 +0800 Subject: [PATCH] migrate-vijos: support to latest ver --- packages/migrate-vijos/package.json | 6 ++-- packages/migrate-vijos/script.ts | 47 ++--------------------------- 2 files changed, 5 insertions(+), 48 deletions(-) diff --git a/packages/migrate-vijos/package.json b/packages/migrate-vijos/package.json index 847f31e8d..1ee90cdc2 100644 --- a/packages/migrate-vijos/package.json +++ b/packages/migrate-vijos/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/migrate-vijos", - "version": "1.3.9", + "version": "1.4.0", "main": "package.json", "repository": "git@github.com:hydro-dev/Hydro.git", "author": "undefined ", @@ -10,14 +10,12 @@ "build": "tsc" }, "devDependencies": { - "@types/js-yaml": "^4.0.0", "@types/mongodb": "^3.6.7" }, "peerDependencies": { - "hydrooj": "2.14.x" + "hydrooj": "^2.17.22" }, "dependencies": { - "js-yaml": "^4.0.0", "mongodb": "^3.6.4" } } \ No newline at end of file diff --git a/packages/migrate-vijos/script.ts b/packages/migrate-vijos/script.ts index 1ce83f201..cef6a06ce 100644 --- a/packages/migrate-vijos/script.ts +++ b/packages/migrate-vijos/script.ts @@ -1,18 +1,11 @@ /* eslint-disable no-await-in-loop */ -// @ts-nocheck import { Rdoc, TestCase, Mdoc, Drrdoc, TrainingNode, } from 'hydrooj'; -import fs from 'fs'; -import os from 'os'; -import path from 'path'; -import yaml from 'js-yaml'; -import mongodb, { ObjectID, Db, Cursor } from 'mongodb'; +import mongodb, { Db, Cursor } from 'mongodb'; const dst = global.Hydro.service.db; -const { file, discussion, document } = global.Hydro.model; -const { testdataConfig } = global.Hydro.lib; -// TODO handle usage_userfile +const { discussion, document } = global.Hydro.model; // TODO output enhancement const map = {}; @@ -337,22 +330,6 @@ async function fix(doc) { { _id: doc._id }, { $set: { pid: doc.pid || doc.docId.toString(), content: addSpace(doc.content) } }, ); - if (doc.data && doc.data instanceof ObjectID) { - const r = await file.get(doc.data); - const p = path.resolve(os.tmpdir(), 'hydro', `migrate.vijos.${doc._id}.zip`); - const w = fs.createWriteStream(p); - await new Promise((resolve, reject) => { - w.on('finish', resolve); - w.on('error', reject); - r.pipe(w); - }); - const config = yaml.load(await testdataConfig.readConfig(p)); - await dst.collection('document').updateOne( - { _id: doc._id }, - { $set: { config } }, - ); - fs.unlinkSync(p); - } } async function fixProblem(report: Function) { @@ -421,24 +398,6 @@ async function removeInvalidPid(report: Function) { } } -async function userfileUsage(src: Db, report: Function) { - const count = await src.collection('domain.user').find().count(); - await report({ progress: 1, message: `userfileUsage: ${count}` }); - const total = Math.floor(count / 50); - for (let i = 0; i <= total; i++) { - const docs = await src.collection('domain.user') - .find().skip(i * 50).limit(50) - .toArray(); - const t = []; - for (const doc of docs) { - if (doc.userfile_usage) { - t.push(dst.collection('user').updateOne({ _id: doc.uid }, { $set: { usage: doc.userfile_usage } })); - } - } - await Promise.all(t); - } -} - async function task(name: any, src: Db, report: Function) { const count = await cursor[name](src).count(); await report({ progress: 1, message: `${name}: ${count}` }); @@ -550,8 +509,8 @@ export async function run({ await fixProblem(report); await discussionNode(src, report); await message(src, report); - await userfileUsage(src, report); await removeInvalidPid(report); + await global.Hydro.model.system.set('db.ver', 1); return true; }