Could not find requested resource
8 |,
57 | pre: (props: any) => (
58 |
62 | ),
63 | };
64 |
--------------------------------------------------------------------------------
/lib/s3.ts:
--------------------------------------------------------------------------------
1 | import {
2 | S3Client,
3 | PutObjectCommand,
4 | GetObjectCommand,
5 | } from "@aws-sdk/client-s3";
6 | // @ts-ignore
7 | import { lookup } from "mime-types";
8 |
9 | export interface UploadParams {
10 | FileName: string; // local file path -> eg. "path/to/local/file.txt"
11 | fileBuffer: Buffer;
12 | objectKey: string; // object key -> eg. "image/image.jpg"
13 | }
14 |
15 | export interface UploadImageParams {
16 | fileObject: File;
17 | objectKey: string; // object key -> eg. "image/image.jpg"
18 | }
19 |
20 | export interface DownloadParams {
21 | objectKey: string; // object key -> eg. "image/image.jpg"
22 | localFilePath: string; // local file path -> eg. "path/to/local/file.txt"
23 | }
24 |
25 | export const S3 = new S3Client({
26 | region: "auto",
27 | endpoint: `https://${process.env.R2_ACCOUNT_ID}.r2.cloudflarestorage.com`,
28 | credentials: {
29 | accessKeyId: process.env.R2_ACCESS_KEY_ID || "",
30 | secretAccessKey: process.env.R2_SECRET_ACCESS_KEY || "",
31 | },
32 | });
33 |
34 | export async function uploadFile(params: UploadParams) {
35 | const { FileName, fileBuffer, objectKey } = params;
36 |
37 | // Create PutObjectCommand to upload the local file to Cloudflare R2
38 | const command = new PutObjectCommand({
39 | Bucket: process.env.R2_BUCKET,
40 | Key: objectKey,
41 | Body: fileBuffer,
42 | ContentType: lookup(FileName),
43 | });
44 |
45 | let data;
46 |
47 | // Upload the file to the specified bucket and key
48 | try {
49 | data = await S3.send(command);
50 |
51 | console.log("File uploaded successfully:", objectKey);
52 | } catch (error) {
53 | console.error("Error uploading file:", error);
54 | }
55 |
56 | return data
57 | ? {
58 | url: `https://${process.env.R2_DOMAIN_URL}/${objectKey}`,
59 | contentType: lookup(FileName),
60 | }
61 | : null;
62 | }
63 |
--------------------------------------------------------------------------------
/components/ui/toggle-group.tsx:
--------------------------------------------------------------------------------
1 | "use client"
2 |
3 | import * as React from "react"
4 | import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group"
5 | import { type VariantProps } from "class-variance-authority"
6 |
7 | import { cn } from "@/lib/utils"
8 | import { toggleVariants } from "@/components/ui/toggle"
9 |
10 | const ToggleGroupContext = React.createContext<
11 | VariantProps29 | {model.description} 30 |
31 |39 | {name} 40 |
41 |42 | {size} 43 |
44 |163 | {body} 164 |
165 | ) 166 | }) 167 | FormMessage.displayName = "FormMessage" 168 | 169 | export { 170 | useFormField, 171 | Form, 172 | FormItem, 173 | FormLabel, 174 | FormControl, 175 | FormDescription, 176 | FormMessage, 177 | FormField, 178 | } 179 | -------------------------------------------------------------------------------- /components/ui/alert-dialog.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog" 5 | 6 | import { cn } from "@/lib/utils" 7 | import { buttonVariants } from "@/components/ui/button" 8 | 9 | const AlertDialog = AlertDialogPrimitive.Root 10 | 11 | const AlertDialogTrigger = AlertDialogPrimitive.Trigger 12 | 13 | const AlertDialogPortal = AlertDialogPrimitive.Portal 14 | 15 | const AlertDialogOverlay = React.forwardRef< 16 | React.ElementRef
45 | {childArray}
46 |
47 | );
48 | }
49 |
50 | return (
51 |