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