refactor: use node crypto uuid

This commit is contained in:
Huskydog9988
2025-04-06 14:08:36 -04:00
parent b4ab6c38fe
commit a01a94fff2
8 changed files with 12 additions and 28 deletions
-2
View File
@@ -40,7 +40,6 @@
"stream": "^0.0.3", "stream": "^0.0.3",
"stream-mime-type": "^2.0.0", "stream-mime-type": "^2.0.0",
"turndown": "^7.2.0", "turndown": "^7.2.0",
"uuid": "^10.0.0",
"vue": "latest", "vue": "latest",
"vue-router": "latest", "vue-router": "latest",
"vue3-carousel": "^0.15.0", "vue3-carousel": "^0.15.0",
@@ -53,7 +52,6 @@
"@types/bcryptjs": "^2.4.6", "@types/bcryptjs": "^2.4.6",
"@types/node": "^22.13.16", "@types/node": "^22.13.16",
"@types/turndown": "^5.0.5", "@types/turndown": "^5.0.5",
"@types/uuid": "^10.0.0",
"autoprefixer": "^10.4.20", "autoprefixer": "^10.4.20",
"h3": "^1.13.0", "h3": "^1.13.0",
"postcss": "^8.4.47", "postcss": "^8.4.47",
@@ -1,12 +1,10 @@
import { AuthMec, Invitation } from "@prisma/client"; import { AuthMec, Invitation } from "@prisma/client";
import prisma from "~/server/internal/db/database"; import prisma from "~/server/internal/db/database";
import { import { createHashArgon2 } from "~/server/internal/security/simple";
createHashArgon2,
} from "~/server/internal/security/simple";
import { v4 as uuidv4 } from "uuid";
import * as jdenticon from "jdenticon"; import * as jdenticon from "jdenticon";
import objectHandler from "~/server/internal/objects"; import objectHandler from "~/server/internal/objects";
import { type } from "arktype"; import { type } from "arktype";
import { randomUUID } from "node:crypto";
import { writeNonLiteralDefaultMessage } from "arktype/internal/parser/shift/operator/default.ts"; import { writeNonLiteralDefaultMessage } from "arktype/internal/parser/shift/operator/default.ts";
const userValidator = type({ const userValidator = type({
@@ -59,9 +57,9 @@ export default defineEventHandler(async (h3) => {
statusMessage: "Username already taken.", statusMessage: "Username already taken.",
}); });
const userId = uuidv4(); const userId = randomUUID();
const profilePictureId = uuidv4(); const profilePictureId = randomUUID();
await objectHandler.createFromSource( await objectHandler.createFromSource(
profilePictureId, profilePictureId,
async () => jdenticon.toPng(user.username, 256), async () => jdenticon.toPng(user.username, 256),
+3 -3
View File
@@ -1,4 +1,4 @@
import { v4 as uuidv4 } from "uuid"; import { randomUUID } from "node:crypto";
import { CertificateBundle } from "./ca"; import { CertificateBundle } from "./ca";
import prisma from "../db/database"; import prisma from "../db/database";
import { Platform } from "@prisma/client"; import { Platform } from "@prisma/client";
@@ -20,7 +20,7 @@ export class ClientHandler {
} = {}; } = {};
async initiate(metadata: ClientMetadata) { async initiate(metadata: ClientMetadata) {
const clientId = uuidv4(); const clientId = randomUUID();
this.temporaryClientTable[clientId] = { this.temporaryClientTable[clientId] = {
data: metadata, data: metadata,
@@ -53,7 +53,7 @@ export class ClientHandler {
const entry = this.temporaryClientTable[clientId]; const entry = this.temporaryClientTable[clientId];
if (!entry) throw new Error("Invalid clientId to generate token"); if (!entry) throw new Error("Invalid clientId to generate token");
const token = uuidv4(); const token = randomUUID();
this.temporaryClientTable[clientId].authToken = token; this.temporaryClientTable[clientId].authToken = token;
return token; return token;
@@ -11,7 +11,6 @@ import sanitize from "sanitize-filename";
import fs from "fs"; import fs from "fs";
import path from "path"; import path from "path";
import { Readable, Stream } from "stream"; import { Readable, Stream } from "stream";
import { v4 as uuidv4 } from "uuid";
export class FsObjectBackend extends ObjectBackend { export class FsObjectBackend extends ObjectBackend {
private baseObjectPath: string; private baseObjectPath: string;
@@ -17,7 +17,6 @@
import { parse as getMimeTypeBuffer } from "file-type-mime"; import { parse as getMimeTypeBuffer } from "file-type-mime";
import Stream, { Readable, Writable } from "stream"; import Stream, { Readable, Writable } from "stream";
import { getMimeType as getMimeTypeStream } from "stream-mime-type"; import { getMimeType as getMimeTypeStream } from "stream-mime-type";
import { v4 as uuidv4 } from "uuid";
export type ObjectReference = string; export type ObjectReference = string;
export type ObjectMetadata = { export type ObjectMetadata = {
@@ -3,7 +3,7 @@ The purpose of this class is to hold references to remote objects (like images)
This is used as a utility in metadata handling, so we only fetch the objects if we're actually creating a database record. This is used as a utility in metadata handling, so we only fetch the objects if we're actually creating a database record.
*/ */
import { Readable } from "stream"; import { Readable } from "stream";
import { v4 as uuidv4 } from "uuid"; import { randomUUID } from "node:crypto";
import objectHandler from "."; import objectHandler from ".";
export type TransactionDataType = string | Readable | Buffer; export type TransactionDataType = string | Readable | Buffer;
@@ -21,12 +21,12 @@ export class ObjectTransactionalHandler {
metadata: { [key: string]: string }, metadata: { [key: string]: string },
permissions: Array<string> permissions: Array<string>
): [Register, Pull, Dump] { ): [Register, Pull, Dump] {
const transactionId = uuidv4(); const transactionId = randomUUID();
this.record[transactionId] ??= {}; this.record[transactionId] ??= {};
const register = (data: TransactionDataType) => { const register = (data: TransactionDataType) => {
const objectId = uuidv4(); const objectId = randomUUID();
this.record[transactionId][objectId] = data; this.record[transactionId][objectId] = data;
return objectId; return objectId;
+2 -2
View File
@@ -2,7 +2,7 @@ import Stream, { Readable } from "stream";
import prisma from "../db/database"; import prisma from "../db/database";
import { applicationSettings } from "../config/application-configuration"; import { applicationSettings } from "../config/application-configuration";
import objectHandler from "../objects"; import objectHandler from "../objects";
import { v4 as uuidv4 } from "uuid"; import { randomUUID } from "node:crypto";
import crypto from "crypto"; import crypto from "crypto";
import { IncomingMessage } from "http"; import { IncomingMessage } from "http";
@@ -35,7 +35,7 @@ class SaveManager {
if (!save) if (!save)
throw createError({ statusCode: 404, statusMessage: "Save not found" }); throw createError({ statusCode: 404, statusMessage: "Save not found" });
const newSaveObjectId = uuidv4(); const newSaveObjectId = randomUUID();
const newSaveStream = await objectHandler.createWithStream( const newSaveStream = await objectHandler.createWithStream(
newSaveObjectId, newSaveObjectId,
{ saveSlot: JSON.stringify({ userId, gameId, index }) }, { saveSlot: JSON.stringify({ userId, gameId, index }) },
-10
View File
@@ -1777,11 +1777,6 @@
resolved "https://registry.yarnpkg.com/@types/turndown/-/turndown-5.0.5.tgz#614de24fc9ace4d8c0d9483ba81dc8c1976dd26f" resolved "https://registry.yarnpkg.com/@types/turndown/-/turndown-5.0.5.tgz#614de24fc9ace4d8c0d9483ba81dc8c1976dd26f"
integrity sha512-TL2IgGgc7B5j78rIccBtlYAnkuv8nUQqhQc+DSYV5j9Be9XOcm/SKOVRuA47xAVI3680Tk9B1d8flK2GWT2+4w== integrity sha512-TL2IgGgc7B5j78rIccBtlYAnkuv8nUQqhQc+DSYV5j9Be9XOcm/SKOVRuA47xAVI3680Tk9B1d8flK2GWT2+4w==
"@types/uuid@^10.0.0":
version "10.0.0"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-10.0.0.tgz#e9c07fe50da0f53dc24970cca94d619ff03f6f6d"
integrity sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ==
"@unhead/dom@1.11.20", "@unhead/dom@^1.11.18": "@unhead/dom@1.11.20", "@unhead/dom@^1.11.18":
version "1.11.20" version "1.11.20"
resolved "https://registry.yarnpkg.com/@unhead/dom/-/dom-1.11.20.tgz#b777f439e1c5f80ebcceb89aa45c45e877013c62" resolved "https://registry.yarnpkg.com/@unhead/dom/-/dom-1.11.20.tgz#b777f439e1c5f80ebcceb89aa45c45e877013c62"
@@ -7142,11 +7137,6 @@ util-deprecate@^1.0.1, util-deprecate@^1.0.2, util-deprecate@~1.0.1:
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw== integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==
uuid@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-10.0.0.tgz#5a95aa454e6e002725c79055fd42aaba30ca6294"
integrity sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==
vary@^1.1.2: vary@^1.1.2:
version "1.1.2" version "1.1.2"
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"