@hydrooj/fps-importer
Advanced tools
Comparing version 1.0.4 to 1.0.6
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
@@ -8,2 +20,9 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -21,6 +40,16 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const server_1 = require("hydrooj/dist/service/server"); | ||
const utils_1 = require("hydrooj/dist/utils"); | ||
const file = __importStar(require("hydrooj/dist/model/file")); | ||
const builtin_1 = require("hydrooj/dist/model/builtin"); | ||
class FpsProblemImportHandler extends server_1.Handler { | ||
async get() { | ||
this.response.template = 'problem_import_fps.html'; | ||
async get(domainId, ufid) { | ||
if (ufid) { | ||
const stream = await file.get(ufid); | ||
const buf = await utils_1.streamToBuffer(stream); | ||
// @ts-ignore | ||
await this.post({ domainId, input: buf.toString() }); | ||
await file.del(ufid); | ||
} | ||
else | ||
this.response.template = 'problem_import_fps.html'; | ||
} | ||
@@ -65,5 +94,5 @@ async post(domainId, input) { | ||
} | ||
const file = path_1.default.resolve(os_1.default.tmpdir(), 'hydro', `${Math.random()}.zip`); | ||
const f = path_1.default.resolve(os_1.default.tmpdir(), 'hydro', `${Math.random()}.zip`); | ||
await new Promise((resolve, reject) => { | ||
testdata.writeZip(file, (err) => { | ||
testdata.writeZip(f, (err) => { | ||
if (err) | ||
@@ -74,5 +103,5 @@ reject(err); | ||
}); | ||
await problem.setTestdata(domainId, pid, file); | ||
await problem.setTestdata(domainId, pid, f); | ||
await problem.edit(domainId, pid, { html: true }); | ||
await fs_extra_1.default.unlink(file); | ||
await fs_extra_1.default.unlink(f); | ||
} | ||
@@ -84,3 +113,6 @@ this.response.body = { count: result.fps.item.length }; | ||
__decorate([ | ||
server_1.param('input', server_1.Types.String) | ||
server_1.param('ufid', server_1.Types.ObjectID, true) | ||
], FpsProblemImportHandler.prototype, "get", null); | ||
__decorate([ | ||
server_1.param('input', server_1.Types.String, true) | ||
], FpsProblemImportHandler.prototype, "post", null); | ||
@@ -87,0 +119,0 @@ async function apply() { |
@@ -7,2 +7,3 @@ /* eslint-disable no-await-in-loop */ | ||
import xml2js from 'xml2js'; | ||
import { ObjectID } from 'mongodb'; | ||
import { LocalProblemConfig } from 'hydrooj'; | ||
@@ -12,10 +13,19 @@ import { | ||
} from 'hydrooj/dist/service/server'; | ||
import { streamToBuffer } from 'hydrooj/dist/utils'; | ||
import * as file from 'hydrooj/dist/model/file'; | ||
import { PERM } from 'hydrooj/dist/model/builtin'; | ||
class FpsProblemImportHandler extends Handler { | ||
async get() { | ||
this.response.template = 'problem_import_fps.html'; | ||
@param('ufid', Types.ObjectID, true) | ||
async get(domainId: string, ufid?: ObjectID) { | ||
if (ufid) { | ||
const stream = await file.get(ufid); | ||
const buf = await streamToBuffer(stream); | ||
// @ts-ignore | ||
await this.post({ domainId, input: buf.toString() }); | ||
await file.del(ufid); | ||
} else this.response.template = 'problem_import_fps.html'; | ||
} | ||
@param('input', Types.String) | ||
@param('input', Types.String, true) | ||
async post(domainId: string, input: string) { | ||
@@ -80,5 +90,5 @@ const result = await xml2js.parseStringPromise(input); | ||
} | ||
const file = path.resolve(os.tmpdir(), 'hydro', `${Math.random()}.zip`); | ||
const f = path.resolve(os.tmpdir(), 'hydro', `${Math.random()}.zip`); | ||
await new Promise((resolve, reject) => { | ||
testdata.writeZip(file, (err) => { | ||
testdata.writeZip(f, (err) => { | ||
if (err) reject(err); | ||
@@ -88,5 +98,5 @@ resolve(); | ||
}); | ||
await problem.setTestdata(domainId, pid, file); | ||
await problem.setTestdata(domainId, pid, f); | ||
await problem.edit(domainId, pid, { html: true }); | ||
await fs.unlink(file); | ||
await fs.unlink(f); | ||
} | ||
@@ -93,0 +103,0 @@ this.response.body = { count: result.fps.item.length }; |
{ | ||
"name": "@hydrooj/fps-importer", | ||
"version": "1.0.4", | ||
"version": "1.0.6", | ||
"description": "Import FPS problems", | ||
@@ -13,2 +13,3 @@ "main": "package.json", | ||
"hydrooj": "^2.12.22", | ||
"mongodb": "^3.6.1", | ||
"xml2js": "^0.4.23" | ||
@@ -15,0 +16,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
589621
241
5
+ Addedmongodb@^3.6.1