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('@');
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Dictionary } from 'lodash';
|
||||
import moment from 'moment-timezone';
|
||||
import Schema from 'schemastery';
|
||||
import { LangConfig, parseLang } from '@hydrooj/common';
|
||||
import { findFileSync, retry } from '@hydrooj/utils';
|
||||
import { findFileSync, randomstring, retry } from '@hydrooj/utils';
|
||||
import { Context } from '../context';
|
||||
import { Setting as _Setting } from '../interface';
|
||||
import { Logger } from '../logger';
|
||||
@@ -345,14 +345,14 @@ SystemSetting(
|
||||
Setting('setting_basic', 'pagination.reply', 50, 'number', 'pagination.reply', 'Replies per page'),
|
||||
Setting('setting_basic', 'hydrooj.homepage', settingFile.homepage.default, 'yaml', 'hydrooj.homepage', 'Homepage config'),
|
||||
Setting('setting_basic', 'hydrooj.langs', settingFile.langs.default, 'yaml', 'hydrooj.langs', 'Language config'),
|
||||
Setting('setting_session', 'session.keys', [String.random(32)], 'text', 'session.keys', 'session.keys', FLAG_HIDDEN),
|
||||
Setting('setting_session', 'session.keys', [randomstring(32)], 'text', 'session.keys', 'session.keys', FLAG_HIDDEN),
|
||||
Setting('setting_session', 'session.domain', '', 'text', 'session.domain', 'session.domain', FLAG_HIDDEN),
|
||||
Setting('setting_session', 'session.saved_expire_seconds', 3600 * 24 * 30,
|
||||
'number', 'session.saved_expire_seconds', 'Saved session expire seconds'),
|
||||
Setting('setting_session', 'session.unsaved_expire_seconds', 3600 * 3,
|
||||
'number', 'session.unsaved_expire_seconds', 'Unsaved session expire seconds'),
|
||||
Setting('setting_storage', 'db.ver', 0, 'number', 'db.ver', 'Database version', FLAG_DISABLED | FLAG_HIDDEN),
|
||||
Setting('setting_storage', 'installid', String.random(64), 'text', 'installid', 'Installation ID', FLAG_HIDDEN | FLAG_DISABLED),
|
||||
Setting('setting_storage', 'installid', randomstring(64), 'text', 'installid', 'Installation ID', FLAG_HIDDEN | FLAG_DISABLED),
|
||||
);
|
||||
|
||||
export const langs: Record<string, LangConfig> = {};
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Filter } from 'mongodb';
|
||||
import { Context } from '../context';
|
||||
import { TokenDoc } from '../interface';
|
||||
import db from '../service/db';
|
||||
import { ArgMethod } from '../utils';
|
||||
import { ArgMethod, randomstring } from '../utils';
|
||||
|
||||
class TokenModel {
|
||||
static coll = db.collection('token');
|
||||
@@ -26,7 +26,7 @@ class TokenModel {
|
||||
};
|
||||
|
||||
static async add(
|
||||
tokenType: number, expireSeconds: number, data: any, id = String.random(32),
|
||||
tokenType: number, expireSeconds: number, data: any, id = randomstring(32),
|
||||
): Promise<[string, TokenDoc]> {
|
||||
const now = new Date();
|
||||
const payload = {
|
||||
|
||||
@@ -12,7 +12,7 @@ import pwhash from '../lib/hash.hydro';
|
||||
import bus from '../service/bus';
|
||||
import db from '../service/db';
|
||||
import { Value } from '../typeutils';
|
||||
import { ArgMethod, buildProjection } from '../utils';
|
||||
import { ArgMethod, buildProjection, randomstring } from '../utils';
|
||||
import { PERM, PRIV } from './builtin';
|
||||
import domain from './domain';
|
||||
import * as setting from './setting';
|
||||
@@ -285,7 +285,7 @@ class UserModel {
|
||||
|
||||
@ArgMethod
|
||||
static async setPassword(uid: number, password: string): Promise<Udoc> {
|
||||
const salt = String.random();
|
||||
const salt = randomstring();
|
||||
const res = await coll.findOneAndUpdate(
|
||||
{ _id: uid },
|
||||
{ $set: { salt, hash: await pwhash(password, salt), hashType: 'hydro' } },
|
||||
@@ -317,7 +317,7 @@ class UserModel {
|
||||
uid = Math.max((udoc?._id || 0) + 1, 2);
|
||||
autoAlloc = true;
|
||||
}
|
||||
const salt = String.random();
|
||||
const salt = randomstring();
|
||||
while (true) {
|
||||
try {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import os from 'os';
|
||||
import { DisposableList } from 'cordis';
|
||||
import { randomstring } from '@hydrooj/utils';
|
||||
import { Context, Service } from '../context';
|
||||
import * as system from '../model/system';
|
||||
import db from './db';
|
||||
@@ -55,7 +56,7 @@ export default class CheckService extends Service {
|
||||
}
|
||||
|
||||
async run(ctx, log, warn, error, cb: (id: string) => void) {
|
||||
const id = String.random(6);
|
||||
const id = randomstring(6);
|
||||
cb(id);
|
||||
for (const check of this.checkers) {
|
||||
if (this.c[id]) {
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import yaml from 'js-yaml';
|
||||
import { pick } from 'lodash';
|
||||
import moment from 'moment-timezone';
|
||||
import { ObjectId } from 'mongodb';
|
||||
import { sleep } from '@hydrooj/utils';
|
||||
import { randomstring, sleep } from '@hydrooj/utils';
|
||||
import { buildContent } from './lib/content';
|
||||
import { Logger } from './logger';
|
||||
import { PERM, PRIV, STATUS } from './model/builtin';
|
||||
@@ -42,10 +40,10 @@ export const coreScripts: MigrationScript[] = [
|
||||
// Mark as used
|
||||
async function init() {
|
||||
if (!await user.getById('system', 0)) {
|
||||
await user.create('Guest@hydro.local', 'Guest', String.random(32), 0, '127.0.0.1', PRIV.PRIV_REGISTER_USER);
|
||||
await user.create('Guest@hydro.local', 'Guest', randomstring(32), 0, '127.0.0.1', PRIV.PRIV_REGISTER_USER);
|
||||
}
|
||||
if (!await user.getById('system', 1)) {
|
||||
await user.create('Hydro@hydro.local', 'Hydro', String.random(32), 1, '127.0.0.1', PRIV.PRIV_USER_PROFILE);
|
||||
await user.create('Hydro@hydro.local', 'Hydro', randomstring(32), 1, '127.0.0.1', PRIV.PRIV_USER_PROFILE);
|
||||
}
|
||||
const ddoc = await domain.get('system');
|
||||
if (!ddoc) await domain.add('system', 1, 'Hydro', 'Welcome to Hydro!');
|
||||
|
||||
Reference in new issue
Block a user