fix: use uuid npm package instead of crypto

This commit is contained in:
Kirill Siukhin 2025-07-10 19:23:00 +05:00
parent 8aaf8bb42d
commit 8540258576
6 changed files with 73 additions and 7 deletions

16
package-lock.json generated
View File

@ -15,7 +15,8 @@
"next": "15.3.4",
"pg": "^8.16.3",
"react": "^19.0.0",
"react-dom": "^19.0.0"
"react-dom": "^19.0.0",
"uuid": "^11.1.0"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
@ -7489,6 +7490,19 @@
"punycode": "^2.1.0"
}
},
"node_modules/uuid": {
"version": "11.1.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.0.tgz",
"integrity": "sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A==",
"funding": [
"https://github.com/sponsors/broofa",
"https://github.com/sponsors/ctavan"
],
"license": "MIT",
"bin": {
"uuid": "dist/esm/bin/uuid"
}
},
"node_modules/which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",

View File

@ -16,7 +16,8 @@
"next": "15.3.4",
"pg": "^8.16.3",
"react": "^19.0.0",
"react-dom": "^19.0.0"
"react-dom": "^19.0.0",
"uuid": "^11.1.0"
},
"devDependencies": {
"@eslint/eslintrc": "^3",

View File

@ -0,0 +1,27 @@
import { notFound } from "next/navigation";
import { getNote } from "@/lib/notes";
import { Metadata } from "next";
export async function generateMetadata({ params }: { params: Promise<{ id: string }> }): Promise<Metadata> {
const { id } = await params;
const note = await getNote(id);
if (!note) {
notFound();
}
return { title: note.name };
}
export default async function Note({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const note = await getNote(id);
if (!note) {
notFound();
}
return (
<div>
{note.name}
</div>
);
}

View File

@ -2,6 +2,7 @@
import { useReducer } from "react";
import { Copy, Plus } from "lucide-react";
import { v4 as uuidv4 } from "uuid";
import { editorReducer } from "@/lib/editorReducer";
import IconOnlyButton from "../ui/IconOnlyButton";
import Block from "./Block";
@ -9,11 +10,11 @@ import Block from "./Block";
export default function Editor() {
const [state, dispatch] = useReducer(editorReducer, [
{
id: crypto.randomUUID(),
id: uuidv4(),
tag: "",
locked: false,
lines: Array.from({ length: 4 }, () => ({
id: crypto.randomUUID(),
id: uuidv4(),
text: "",
})),
}

View File

@ -1,3 +1,5 @@
import { v4 as uuidv4 } from "uuid";
export type ILine = {
id: string;
text: string;
@ -28,11 +30,11 @@ export function editorReducer(state: EditorState, action: Action): EditorState {
return [
...state,
{
id: crypto.randomUUID(),
id: uuidv4(),
tag: "",
locked: false,
lines: Array.from({ length: 4 }, () => ({
id: crypto.randomUUID(),
id: uuidv4(),
text: "",
})),
}
@ -61,7 +63,7 @@ export function editorReducer(state: EditorState, action: Action): EditorState {
if (block.id === action.blockId) {
return {
...block,
lines: [...block.lines, { id: crypto.randomUUID(), text: "" }],
lines: [...block.lines, { id: uuidv4(), text: "" }],
};
} else {
return block;

View File

@ -1,4 +1,5 @@
import { desc, eq } from "drizzle-orm";
import { validate as uuidValidate } from "uuid";
import { notesTable } from "./db/schema";
import { getAuth } from "./auth";
import { db } from "./db";
@ -10,6 +11,22 @@ export async function getNotes(authorId: string) {
.orderBy(desc(notesTable.lastEdited));
}
export async function getNote(noteId: string) {
if (!uuidValidate(noteId)) {
return null;
}
const notes = await db.select()
.from(notesTable)
.where(eq(notesTable.id, noteId));
if (notes.length === 0) {
return null;
} else {
return notes[0];
}
}
export async function createNote() {
const auth = await getAuth();
if (!auth) {
@ -25,6 +42,10 @@ export async function createNote() {
}
export async function deleteNote(noteId: string) {
if (!uuidValidate(noteId)) {
return null;
}
const auth = await getAuth();
if (!auth) {
return null;