Skip to content

Commit

Permalink
chore: crypto random UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
arshad-yaseen committed Dec 4, 2023
1 parent add012c commit cebc650
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
4 changes: 2 additions & 2 deletions components/dashboard/post-create-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useAtom } from "jotai"
import { Loader2, PlusIcon } from "lucide-react"

import { DefaultEditorContent, defaultEditorContent } from "@/config/editor"
import { cn, generateRandomString } from "@/lib/utils"
import { cn, generateUUID } from "@/lib/utils"
import { Button, ButtonProps } from "@/components/ui/button"

interface PostCreateButtonProps extends ButtonProps {}
Expand Down Expand Up @@ -48,7 +48,7 @@ export function PostCreateButton({
"/api/posts",
{
code: defaultEditorContent,
markdown_id: generateRandomString(15),
markdown_id: generateUUID(),
},
{
error: "Your post was not created. Please try again.",
Expand Down
10 changes: 2 additions & 8 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ export function absoluteUrl(path: string) {
return `${env.NEXT_PUBLIC_APP_URL}${path}`
}

export function generateRandomString(length: number) {
var result = ""
var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
var charactersLength = characters.length
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength))
}
return result
export function generateUUID() {
return crypto.randomUUID()
}

export async function handleSave(
Expand Down

1 comment on commit cebc650

@vercel
Copy link

@vercel vercel bot commented on cebc650 Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.