-
-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80acd3b
commit 3eea07f
Showing
11 changed files
with
219 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
OPENAI_API_KEY= | ||
UPLOADTHING_TOKEN= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
templates/plate-playground-template/src/app/api/uploadthing/core.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { FileRouter } from 'uploadthing/next'; | ||
|
||
import { createUploadthing } from 'uploadthing/next'; | ||
|
||
const f = createUploadthing(); | ||
|
||
// FileRouter for your app, can contain multiple FileRoutes | ||
export const ourFileRouter = { | ||
// Define as many FileRoutes as you like, each with a unique routeSlug | ||
imageUploader: f(['image', 'text', 'blob', 'pdf', 'video', 'audio']) | ||
// Set permissions and file types for this FileRoute | ||
.middleware(async ({ req }) => { | ||
// This code runs on your server before upload | ||
|
||
// Whatever is returned here is accessible in onUploadComplete as `metadata` | ||
return {}; | ||
}) | ||
.onUploadComplete(({ file, metadata }) => { | ||
// This code RUNS ON YOUR SERVER after upload | ||
|
||
// !!! Whatever is returned here is sent to the clientside `onClientUploadComplete` callback | ||
return { file }; | ||
}), | ||
} satisfies FileRouter; | ||
|
||
export type OurFileRouter = typeof ourFileRouter; |
11 changes: 11 additions & 0 deletions
11
templates/plate-playground-template/src/app/api/uploadthing/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { createRouteHandler } from 'uploadthing/next'; | ||
|
||
import { ourFileRouter } from './core'; | ||
|
||
// Export routes for Next App Router | ||
export const { GET, POST } = createRouteHandler({ | ||
router: ourFileRouter, | ||
|
||
// Apply an (optional) custom config: | ||
// config: { ... }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
templates/plate-playground-template/src/lib/uploadthing/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from './handle-error'; | ||
|
||
export * from './uploadthing'; | ||
|
||
export * from './use-upload-file'; |
6 changes: 6 additions & 0 deletions
6
templates/plate-playground-template/src/lib/uploadthing/uploadthing.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { OurFileRouter } from '@/app/api/uploadthing/core'; | ||
|
||
import { generateReactHelpers } from '@uploadthing/react'; | ||
|
||
export const { uploadFiles, useUploadThing } = | ||
generateReactHelpers<OurFileRouter>(); |
Oops, something went wrong.