使用export = 替换export default

This commit is contained in:
undefined committed 2020-08-21 20:07:23 +08:00
1 parent 12af2f7542
commit c63643d349
15 files changed
+38 -25

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.12.20",
"version": "2.12.21",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
+11 -11
View File
@@ -396,23 +396,23 @@ export interface Service {
}
export interface Lib {
download: typeof import('./lib/download').default,
'hash.hydro': typeof import('./lib/hash.hydro').default,
i18n: typeof import('./lib/i18n').default,
download: typeof import('./lib/download'),
'hash.hydro': typeof import('./lib/hash.hydro'),
i18n: typeof import('./lib/i18n'),
'import.syzoj': typeof import('./lib/import.syzoj').syzoj,
jwt: typeof import('./lib/jwt'),
logger: typeof import('./lib/logger').default,
logger: typeof import('./lib/logger'),
mail: typeof import('./lib/mail'),
md5: typeof import('./lib/md5').default,
md5: typeof import('./lib/md5'),
misc: typeof import('./lib/misc'),
nav: typeof import('./lib/nav').default,
paginate: typeof import('./lib/paginate').default,
rank: typeof import('./lib/rank').default,
rating: typeof import('./lib/rating').default,
nav: typeof import('./lib/nav'),
paginate: typeof import('./lib/paginate'),
rank: typeof import('./lib/rank'),
rating: typeof import('./lib/rating'),
testdataConfig: typeof import('./lib/testdataConfig'),
sha1: typeof import('./lib/sha1').default,
sha1: typeof import('./lib/sha1'),
sysinfo: typeof import('./lib/sysinfo'),
'testdata.convert.ini': typeof import('./lib/testdata.convert.ini').default,
'testdata.convert.ini': typeof import('./lib/testdata.convert.ini'),
useragent: typeof import('./lib/useragent'),
validator: typeof import('./lib/validator'),
[key: string]: any
+3 -1
View File
@@ -11,9 +11,11 @@ async function _download(url: string, path: string, retry: number) {
return path;
}
export default function download(url: string, path?: string, retry = 3) {
function download(url: string, path?: string, retry = 3) {
if (path) return _download(url, path, retry);
return superagent.get(url).retry(retry);
}
export = download;
global.Hydro.lib.download = download;
+3 -1
View File
@@ -1,7 +1,9 @@
import crypto from 'crypto';
export default function hash(password: string, salt: string) {
function hash(password: string, salt: string) {
return crypto.pbkdf2Sync(password, salt, 100000, 64, 'sha256').toString('hex').substr(0, 64);
}
export = hash;
global.Hydro.lib['hash.hydro'] = hash;
+5 -1
View File
@@ -1,3 +1,5 @@
import { Dictionary } from 'lodash';
const locales = {};
declare global {
@@ -45,12 +47,14 @@ String.prototype.translate = function translate(...languages: string[]) {
return this;
};
export default function load(data) {
function load(data: Dictionary<string>) {
for (const i in data) {
if (!locales[i]) locales[i] = data[i];
else locales[i] = Object.assign(locales[i], data[i]);
}
}
export = load;
global.Hydro.locales = locales;
global.Hydro.lib.i18n = load;
+1 -1
View File
@@ -38,4 +38,4 @@ const exp = new Logger();
global.Hydro.lib.logger = exp;
export default exp;
export = exp;
+2 -1
View File
@@ -130,8 +130,9 @@ function rstr2hex(input) {
return output;
}
export default function md5(s: string) {
function md5(s: string) {
return rstr2hex(rstrMD5(unescape(encodeURIComponent(s))));
}
export = md5;
global.Hydro.lib.md5 = md5;
+1 -1
View File
@@ -54,4 +54,4 @@ Item('domain_dashboard', null, 'domain', PERM.PERM_EDIT_DOMAIN);
Item('manage_dashboard', null, 'manage', PRIV.PRIV_EDIT_SYSTEM);
global.Hydro.lib.nav = Item;
export default Item;
export = Item;
+3 -1
View File
@@ -1,7 +1,7 @@
import { Cursor } from 'mongodb';
import { ValidationError } from '../error';
export default async function paginate(
async function paginate(
cursor: Cursor, page: number, pageSize: number,
): Promise<[any[]/* docs */, number/* numPages */, number/* count */]> {
if (page <= 0) throw new ValidationError('page');
@@ -13,4 +13,6 @@ export default async function paginate(
return [pageDocs, numPages, count];
}
export = paginate;
global.Hydro.lib.paginate = paginate;
+1 -1
View File
@@ -11,4 +11,4 @@ function* ranked<T>(diter: T[], equ = (a: T, b: T) => a === b): Generator<[numbe
}
global.Hydro.lib.rank = ranked;
export default ranked;
export = ranked;
+3 -1
View File
@@ -107,7 +107,7 @@ interface RatingOutputUser {
uid: number,
}
export default function calculate(users: RatingInputUser[]): RatingOutputUser[] {
function calculate(users: RatingInputUser[]): RatingOutputUser[] {
let last_idx = 0;
let last_rank = 1;
for (let i = 1; i < users.length; i++) {
@@ -124,4 +124,6 @@ export default function calculate(users: RatingInputUser[]): RatingOutputUser[]
return calculator.calculate() as RatingOutputUser[];
}
export = calculate;
global.Hydro.lib.rating = calculate;
+1 -1
View File
@@ -7,4 +7,4 @@ function sha1(content: string) {
}
global.Hydro.lib.sha1 = sha1;
export default sha1;
export = sha1;
@@ -1,6 +1,6 @@
import yaml from 'js-yaml';
export default function convert(ini: string) {
function convert(ini: string) {
const f = ini.split('\n');
const count = parseInt(f[0], 10);
const res = { cases: [] };
@@ -30,3 +30,4 @@ export default function convert(ini: string) {
}
global.Hydro.lib['testdata.convert.ini'] = convert;
export = convert;
+1 -1
View File
@@ -2,7 +2,7 @@ import fs from 'fs';
import os from 'os';
import path from 'path';
export default function load() {
export = function load() {
let f = path.resolve(process.cwd(), 'config.json');
if (!fs.existsSync(f)) f = path.resolve(__dirname, 'config.json');
if (!fs.existsSync(f)) f = path.resolve(os.homedir(), '.config', 'hydro', 'config.json');
-1
View File
@@ -478,7 +478,6 @@ export class Handler {
async putResponse() {
if (this.response.disposition) this.ctx.set('Content-Disposition', this.response.disposition);
console.log(this.response);
if (!this.response.body) return;
if (this.response.redirect && !this.request.json) {
this.ctx.response.type = 'application/octet-stream';