mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor(api): 🎨 Don't use node:crypto for random strings
This commit is contained in:
parent
d8cb1d475b
commit
d301d4da09
12 changed files with 37 additions and 35 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { randomBytes } from "node:crypto";
|
||||
import { consoleLogger } from "@/loggers";
|
||||
import { randomString } from "@/math";
|
||||
import { asc, inArray, like } from "drizzle-orm";
|
||||
import type { Status } from "~/database/entities/status";
|
||||
import { db } from "~/drizzle/db";
|
||||
|
|
@ -35,11 +35,11 @@ export const getTestUsers = async (count: number) => {
|
|||
const passwords: string[] = [];
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const password = randomBytes(32).toString("hex");
|
||||
const password = randomString(32, "hex");
|
||||
|
||||
const user = await User.fromDataLocal({
|
||||
username: `test-${randomBytes(32).toString("hex")}`,
|
||||
email: `${randomBytes(32).toString("hex")}@test.com`,
|
||||
username: `test-${randomString(32, "hex")}`,
|
||||
email: `${randomString(32, "hex")}@test.com`,
|
||||
password,
|
||||
});
|
||||
|
||||
|
|
@ -55,11 +55,11 @@ export const getTestUsers = async (count: number) => {
|
|||
.insert(Tokens)
|
||||
.values(
|
||||
users.map((u) => ({
|
||||
accessToken: randomBytes(32).toString("hex"),
|
||||
accessToken: randomString(32, "hex"),
|
||||
tokenType: "bearer",
|
||||
userId: u.id,
|
||||
applicationId: null,
|
||||
code: randomBytes(32).toString("hex"),
|
||||
code: randomString(32, "hex"),
|
||||
scope: "read write follow push",
|
||||
})),
|
||||
)
|
||||
|
|
@ -89,7 +89,7 @@ export const getTestStatuses = async (
|
|||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const newStatus = await Note.insert({
|
||||
content: `${i} ${randomBytes(32).toString("hex")}`,
|
||||
content: `${i} ${randomString(32, "hex")}`,
|
||||
authorId: user.id,
|
||||
sensitive: false,
|
||||
updatedAt: new Date().toISOString(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue