mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
replace String.random with randomstring
This commit is contained in:
22 files changed
+64
-48
No files matched your search
@@ -5,7 +5,7 @@ import { escapeRegExp, pick } from 'lodash';
|
||||
import moment from 'moment-timezone';
|
||||
import { ObjectId } from 'mongodb';
|
||||
import {
|
||||
Counter, sortFiles, Time, yaml,
|
||||
Counter, diffArray, randomstring, sortFiles, Time, yaml,
|
||||
} from '@hydrooj/utils/lib/utils';
|
||||
import { Context, Service } from '../context';
|
||||
import {
|
||||
@@ -317,7 +317,7 @@ export class ContestEditHandler extends Handler {
|
||||
title, content, rule, beginAt, endAt, pids, rated, duration: contestDuration,
|
||||
});
|
||||
if (this.tdoc.beginAt !== beginAt || this.tdoc.endAt !== endAt
|
||||
|| Array.isDiff(this.tdoc.pids, pids) || this.tdoc.rule !== rule
|
||||
|| diffArray(this.tdoc.pids, pids) || this.tdoc.rule !== rule
|
||||
|| lockAt !== this.tdoc.lockAt) {
|
||||
await contest.recalcStatus(domainId, this.tdoc.docId);
|
||||
}
|
||||
@@ -484,7 +484,7 @@ export class ContestManagementHandler extends ContestManagementBaseHandler {
|
||||
if (size >= system.get('limit.contest_files_size')) {
|
||||
throw new FileLimitExceededError('size');
|
||||
}
|
||||
filename ||= file.originalFilename || String.random(16);
|
||||
filename ||= file.originalFilename || randomstring(16);
|
||||
await storage.put(`contest/${domainId}/${tid}/${filename}`, file.filepath, this.user._id);
|
||||
const meta = await storage.getMeta(`contest/${domainId}/${tid}/${filename}`);
|
||||
const payload = { _id: filename, name: filename, ...pick(meta, ['size', 'lastModified', 'etag']) };
|
||||
|
||||
@@ -10,7 +10,7 @@ import { nanoid } from 'nanoid';
|
||||
import sanitize from 'sanitize-filename';
|
||||
import Schema from 'schemastery';
|
||||
import parser from '@hydrooj/utils/lib/search';
|
||||
import { sortFiles, streamToBuffer } from '@hydrooj/utils/lib/utils';
|
||||
import { randomstring, sortFiles, streamToBuffer } from '@hydrooj/utils/lib/utils';
|
||||
import type { Context } from '../context';
|
||||
import {
|
||||
BadRequestError, ContestNotAttendedError, ContestNotEndedError, ContestNotFoundError, ContestNotLiveError,
|
||||
@@ -709,7 +709,7 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
|
||||
async postUploadFile(domainId: string, filename: string, type = 'testdata') {
|
||||
const file = this.request.files.file;
|
||||
if (!file) throw new ValidationError('file');
|
||||
filename ||= file.originalFilename || String.random(16);
|
||||
filename ||= file.originalFilename || randomstring(16);
|
||||
const files = [];
|
||||
if (filename.endsWith('.zip') && type === 'testdata') {
|
||||
const zip = new ZipReader(Readable.toWeb(createReadStream(file.filepath)));
|
||||
|
||||
@@ -3,6 +3,7 @@ import { isoBase64URL } from '@simplewebauthn/server/helpers';
|
||||
import moment from 'moment-timezone';
|
||||
import { Binary } from 'mongodb';
|
||||
import Schema from 'schemastery';
|
||||
import { randomstring } from '@hydrooj/utils';
|
||||
import type { Context } from '../context';
|
||||
import {
|
||||
AuthOperationError, BadRequestError, BlacklistedError, BuiltinLoginError,
|
||||
@@ -306,7 +307,7 @@ class UserRegisterWithCodeHandler extends Handler {
|
||||
if (provider.lockUsername) uname = this.tdoc.identity.username;
|
||||
if (!Types.Username[1](uname)) throw new ValidationError('uname');
|
||||
if (password !== verify) throw new VerifyPasswordError();
|
||||
const randomEmail = `${String.random(12)}@invalid.local`; // some random email to remove in the future
|
||||
const randomEmail = `${randomstring(12)}@invalid.local`; // some random email to remove in the future
|
||||
const uid = await user.create(this.tdoc.mail || randomEmail, uname, password, undefined, this.request.ip);
|
||||
await token.del(code, token.TYPE_REGISTRATION);
|
||||
const [id, mailDomain] = this.tdoc.mail.split('@');
|
||||
|
||||
Reference in new issue
Block a user