Skip to content

Commit 5d7f5fe

Browse files
committed
replace String.random with randomstring
1 parent b18cce3 commit 5d7f5fe

22 files changed

Lines changed: 64 additions & 48 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ Hydro 用户群:1085853538
142142
- ui: 支持使用自定义字体
143143
- framework: 添加 Subscription API
144144
- core: 添加 fixStorage 脚本
145+
- core: websocket: 重构 Subscription API
146+
- ui: 允许跨页选择题目
147+
- judge: 重构 config.detail 设置
148+
- core: 自动清理多余的静态文件
149+
- ui: 优化比赛题目列表显示
150+
145151

146152
### Bug Fixes
147153

@@ -155,6 +161,8 @@ Hydro 用户群:1085853538
155161
- ui: 修复高亮行号显示
156162
- core: 修复 `User.serialize()` 参数
157163
- ui: 修复更换邮箱功能
164+
- ui: 修复比赛侧栏
165+
- ui: 修复文档链接
158166

159167
### Breaking API Changes
160168

@@ -174,6 +182,7 @@ Hydro 用户群:1085853538
174182
- framework: 移除 ready 与 dispose 事件 (使用 ctx.effect 代替)
175183
- core: 最低要求 node 22
176184
- core: 弃用 AdmZip
185+
- utils: 移除 String.random 与 Array.isDiff
177186

178187
## Hydro 4.19.0 / UI 4.57.0
179188

packages/common/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@hydrooj/common",
33
"main": "./index.ts",
44
"version": "0.0.2",
5+
"sideEffects": false,
56
"dependencies": {
67
"@hydrooj/utils": "workspace:^"
78
}

packages/components/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"name": "@hydrooj/components",
33
"version": "1.0.0-beta.3",
44
"main": "./frontend/index.ts",
5+
"sideEffects": [
6+
"*.scss",
7+
"*.css"
8+
],
59
"dependencies": {
610
"allotment": "^1.20.4",
711
"diff": "^8.0.2",

packages/fps-importer/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import decodeHTML from 'decode-html';
44
import xml2js from 'xml2js';
55
import {
66
_, BadRequestError, buildContent, Context, FileTooLargeError, fs, Handler, PERM, ProblemConfigFile,
7-
ProblemModel, ProblemType, Schema, SolutionModel, SystemModel, ValidationError, yaml, Zip,
7+
ProblemModel, ProblemType, randomstring, Schema, SolutionModel, SystemModel, ValidationError, yaml, Zip,
88
} from 'hydrooj';
99

1010
const knownRemoteMapping = {
@@ -65,7 +65,7 @@ class FpsProblemImportHandler extends Handler {
6565
}
6666
if (p.img?.length) {
6767
for (const img of p.img) {
68-
const filename = String.random(8) + img.src[0].split('/').pop().split('.').pop();
68+
const filename = randomstring(8) + img.src[0].split('/').pop().split('.').pop();
6969
tasks.push(ProblemModel.addAdditionalFile(domainId, pid, filename, Buffer.from(img.base64[0], 'base64')));
7070
content = content.replace(img.src[0], `file://${filename}`);
7171
}

packages/hydrojudge/src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import os from 'os';
22
import path from 'path';
33
import cac from 'cac';
44
import Schema from 'schemastery';
5-
import { fs, yaml } from '@hydrooj/utils';
5+
import { fs, randomstring, yaml } from '@hydrooj/utils';
66

77
const argv = cac().parse();
88

@@ -30,7 +30,7 @@ export const JudgeSettings = Schema.object({
3030
rate: Schema.number().default(1),
3131
env: Schema.string().default(defaultEnv),
3232
host: Schema.any(),
33-
secret: Schema.string().description('Judge Token Secret').default(String.random(32)),
33+
secret: Schema.string().description('Judge Token Secret').default(randomstring(32)),
3434
disable: Schema.boolean().description('Disable builtin judge').default(false),
3535
detail: Schema.union([
3636
Schema.const('full'),

packages/hydrooj/src/handler/contest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { escapeRegExp, pick } from 'lodash';
55
import moment from 'moment-timezone';
66
import { ObjectId } from 'mongodb';
77
import {
8-
Counter, sortFiles, Time, yaml,
8+
Counter, diffArray, randomstring, sortFiles, Time, yaml,
99
} from '@hydrooj/utils/lib/utils';
1010
import { Context, Service } from '../context';
1111
import {
@@ -317,7 +317,7 @@ export class ContestEditHandler extends Handler {
317317
title, content, rule, beginAt, endAt, pids, rated, duration: contestDuration,
318318
});
319319
if (this.tdoc.beginAt !== beginAt || this.tdoc.endAt !== endAt
320-
|| Array.isDiff(this.tdoc.pids, pids) || this.tdoc.rule !== rule
320+
|| diffArray(this.tdoc.pids, pids) || this.tdoc.rule !== rule
321321
|| lockAt !== this.tdoc.lockAt) {
322322
await contest.recalcStatus(domainId, this.tdoc.docId);
323323
}
@@ -484,7 +484,7 @@ export class ContestManagementHandler extends ContestManagementBaseHandler {
484484
if (size >= system.get('limit.contest_files_size')) {
485485
throw new FileLimitExceededError('size');
486486
}
487-
filename ||= file.originalFilename || String.random(16);
487+
filename ||= file.originalFilename || randomstring(16);
488488
await storage.put(`contest/${domainId}/${tid}/${filename}`, file.filepath, this.user._id);
489489
const meta = await storage.getMeta(`contest/${domainId}/${tid}/${filename}`);
490490
const payload = { _id: filename, name: filename, ...pick(meta, ['size', 'lastModified', 'etag']) };

packages/hydrooj/src/handler/problem.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { nanoid } from 'nanoid';
1010
import sanitize from 'sanitize-filename';
1111
import Schema from 'schemastery';
1212
import parser from '@hydrooj/utils/lib/search';
13-
import { sortFiles, streamToBuffer } from '@hydrooj/utils/lib/utils';
13+
import { randomstring, sortFiles, streamToBuffer } from '@hydrooj/utils/lib/utils';
1414
import type { Context } from '../context';
1515
import {
1616
BadRequestError, ContestNotAttendedError, ContestNotEndedError, ContestNotFoundError, ContestNotLiveError,
@@ -709,7 +709,7 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
709709
async postUploadFile(domainId: string, filename: string, type = 'testdata') {
710710
const file = this.request.files.file;
711711
if (!file) throw new ValidationError('file');
712-
filename ||= file.originalFilename || String.random(16);
712+
filename ||= file.originalFilename || randomstring(16);
713713
const files = [];
714714
if (filename.endsWith('.zip') && type === 'testdata') {
715715
const zip = new ZipReader(Readable.toWeb(createReadStream(file.filepath)));

packages/hydrooj/src/handler/user.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { isoBase64URL } from '@simplewebauthn/server/helpers';
33
import moment from 'moment-timezone';
44
import { Binary } from 'mongodb';
55
import Schema from 'schemastery';
6+
import { randomstring } from '@hydrooj/utils';
67
import type { Context } from '../context';
78
import {
89
AuthOperationError, BadRequestError, BlacklistedError, BuiltinLoginError,
@@ -306,7 +307,7 @@ class UserRegisterWithCodeHandler extends Handler {
306307
if (provider.lockUsername) uname = this.tdoc.identity.username;
307308
if (!Types.Username[1](uname)) throw new ValidationError('uname');
308309
if (password !== verify) throw new VerifyPasswordError();
309-
const randomEmail = `${String.random(12)}@invalid.local`; // some random email to remove in the future
310+
const randomEmail = `${randomstring(12)}@invalid.local`; // some random email to remove in the future
310311
const uid = await user.create(this.tdoc.mail || randomEmail, uname, password, undefined, this.request.ip);
311312
await token.del(code, token.TYPE_REGISTRATION);
312313
const [id, mailDomain] = this.tdoc.mail.split('@');

packages/hydrooj/src/model/setting.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Dictionary } from 'lodash';
66
import moment from 'moment-timezone';
77
import Schema from 'schemastery';
88
import { LangConfig, parseLang } from '@hydrooj/common';
9-
import { findFileSync, retry } from '@hydrooj/utils';
9+
import { findFileSync, randomstring, retry } from '@hydrooj/utils';
1010
import { Context } from '../context';
1111
import { Setting as _Setting } from '../interface';
1212
import { Logger } from '../logger';
@@ -345,14 +345,14 @@ SystemSetting(
345345
Setting('setting_basic', 'pagination.reply', 50, 'number', 'pagination.reply', 'Replies per page'),
346346
Setting('setting_basic', 'hydrooj.homepage', settingFile.homepage.default, 'yaml', 'hydrooj.homepage', 'Homepage config'),
347347
Setting('setting_basic', 'hydrooj.langs', settingFile.langs.default, 'yaml', 'hydrooj.langs', 'Language config'),
348-
Setting('setting_session', 'session.keys', [String.random(32)], 'text', 'session.keys', 'session.keys', FLAG_HIDDEN),
348+
Setting('setting_session', 'session.keys', [randomstring(32)], 'text', 'session.keys', 'session.keys', FLAG_HIDDEN),
349349
Setting('setting_session', 'session.domain', '', 'text', 'session.domain', 'session.domain', FLAG_HIDDEN),
350350
Setting('setting_session', 'session.saved_expire_seconds', 3600 * 24 * 30,
351351
'number', 'session.saved_expire_seconds', 'Saved session expire seconds'),
352352
Setting('setting_session', 'session.unsaved_expire_seconds', 3600 * 3,
353353
'number', 'session.unsaved_expire_seconds', 'Unsaved session expire seconds'),
354354
Setting('setting_storage', 'db.ver', 0, 'number', 'db.ver', 'Database version', FLAG_DISABLED | FLAG_HIDDEN),
355-
Setting('setting_storage', 'installid', String.random(64), 'text', 'installid', 'Installation ID', FLAG_HIDDEN | FLAG_DISABLED),
355+
Setting('setting_storage', 'installid', randomstring(64), 'text', 'installid', 'Installation ID', FLAG_HIDDEN | FLAG_DISABLED),
356356
);
357357

358358
export const langs: Record<string, LangConfig> = {};

packages/hydrooj/src/model/token.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Filter } from 'mongodb';
22
import { Context } from '../context';
33
import { TokenDoc } from '../interface';
44
import db from '../service/db';
5-
import { ArgMethod } from '../utils';
5+
import { ArgMethod, randomstring } from '../utils';
66

77
class TokenModel {
88
static coll = db.collection('token');
@@ -26,7 +26,7 @@ class TokenModel {
2626
};
2727

2828
static async add(
29-
tokenType: number, expireSeconds: number, data: any, id = String.random(32),
29+
tokenType: number, expireSeconds: number, data: any, id = randomstring(32),
3030
): Promise<[string, TokenDoc]> {
3131
const now = new Date();
3232
const payload = {

0 commit comments

Comments
 (0)