diff --git a/.changeset/config.json b/.changeset/config.json index 2867245fa..965a76a6a 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -5,7 +5,7 @@ { "repo": "pingdotgg/uploadthing" } ], "commit": false, - "fixed": [["uploadthing", "@uploadthing/react", "@uploadthing/solid"]], + "fixed": [["uploadthing", "@uploadthing/react"]], "access": "public", "baseBranch": "main", "updateInternalDependencies": "patch", diff --git a/.changeset/ninety-monkeys-notice.md b/.changeset/ninety-monkeys-notice.md deleted file mode 100644 index 004d092ac..000000000 --- a/.changeset/ninety-monkeys-notice.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"uploadthing": minor ---- - -[feat] API Helpers -- deleteFiles() and getFileUrls() diff --git a/.changeset/olive-donkeys-move.md b/.changeset/olive-donkeys-move.md deleted file mode 100644 index 0cb561254..000000000 --- a/.changeset/olive-donkeys-move.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -"uploadthing": major -"@uploadthing/react": major ---- - -Overhauled file router syntax diff --git a/.changeset/swift-bottles-dream.md b/.changeset/swift-bottles-dream.md deleted file mode 100644 index e53a61c8b..000000000 --- a/.changeset/swift-bottles-dream.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"uploadthing": patch ---- - -[Fix] Update to buildRequestHandler secret diff --git a/examples/appdir/package.json b/examples/appdir/package.json index a07f2a780..28fc81e22 100644 --- a/examples/appdir/package.json +++ b/examples/appdir/package.json @@ -12,14 +12,14 @@ }, "dependencies": { "@tanstack/react-query": "^4.28.0", - "@uploadthing/react": "3.0.5", + "@uploadthing/react": "4.0.0", "autoprefixer": "10.4.14", "next": "13.4.4", "postcss": "8.4.22", "react": "18.2.0", "react-dom": "18.2.0", "tailwindcss": "^3.3.2", - "uploadthing": "3.0.5", + "uploadthing": "4.0.0", "zod": "^3.21.4", "zod-validation-error": "^1.1.0" }, diff --git a/examples/pagedir/package.json b/examples/pagedir/package.json index f25669d4a..1363438b5 100644 --- a/examples/pagedir/package.json +++ b/examples/pagedir/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@tanstack/react-query": "^4.28.0", - "@uploadthing/react": "3.0.5", + "@uploadthing/react": "4.0.0", "autoprefixer": "10.4.14", "next": "13.4.4", "next-auth": "^4.22.1", @@ -20,7 +20,7 @@ "react": "18.2.0", "react-dom": "18.2.0", "tailwindcss": "^3.3.2", - "uploadthing": "3.0.5", + "uploadthing": "4.0.0", "zod": "^3.21.4", "zod-validation-error": "^1.1.0" }, diff --git a/examples/solid/src/routes/api/uploadthing/core.ts b/examples/solid/src/routes/api/uploadthing/core.ts index 143114b41..c7dcc995d 100644 --- a/examples/solid/src/routes/api/uploadthing/core.ts +++ b/examples/solid/src/routes/api/uploadthing/core.ts @@ -8,31 +8,25 @@ const auth = (req: Request) => Promise.resolve({ id: "fakeId" }); // Fake auth f // FileRouter for your app, can contain multiple FileRoutes export const ourFileRouter = { // Define as many FileRoutes as you like, each with a unique routeSlug - withMdwr: f({ - image: { - maxFileCount: 2, - maxFileSize: "1MB", - }, - }) + imageUploader: f + // Set permissions and file types for this FileRoute + .fileTypes(["image", "video"]) + .maxSize("1GB") .middleware(async (req) => { - const h = req.headers.get("someProperty"); - const authed = await auth(req); + // This code runs on your server before upload + const user = await auth(req); - return { - someProperty: h, - userId: authed.id, - }; + // If you throw, the user will not be able to upload + if (!user) throw new Error("Unauthorized"); + + // Whatever is returned here is accessible in onUploadComplete as `metadata` + return { userId: user.id }; }) .onUploadComplete(({ metadata, file }) => { - console.log("uploaded with the following metadata:", metadata); - metadata.someProperty; - // ^? - metadata.userId; - // ^? + // This code RUNS ON YOUR SERVER after upload + console.log("Upload complete for userId:", metadata.userId); - console.log("files successfully uploaded:", file); - file; - // ^? + console.log("file url", file.url); }), } satisfies FileRouter; diff --git a/examples/solid/src/routes/index.tsx b/examples/solid/src/routes/index.tsx index eafc64224..7e14ad6ae 100644 --- a/examples/solid/src/routes/index.tsx +++ b/examples/solid/src/routes/index.tsx @@ -10,7 +10,7 @@ const Home: VoidComponent = () => { return (
- endpoint="withMdwr" + endpoint="imageUploader" // needed when server side rendering url="http://localhost:9898" onClientUploadComplete={(res) => { diff --git a/package.json b/package.json index 325520137..11255751c 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "build": "turbo run build", "clean": "turbo run clean && git clean -xdf node_modules", "dev": "turbo run dev", - "lint": "turbo run lint && manypkg check", + "lint": "turbo run lint", + "lint fixme after solid package is updated": "turbo run lint && manypkg check", "format": "prettier --write . --ignore-path .gitignore", "test": "turbo run test", "test:watch": "turbo run test:watch", diff --git a/packages/react/CHANGELOG.md b/packages/react/CHANGELOG.md index 5ef2f06d0..463aaeb15 100644 --- a/packages/react/CHANGELOG.md +++ b/packages/react/CHANGELOG.md @@ -1,5 +1,16 @@ # @uploadthing/react +## 4.0.0 + +### Major Changes + +- [#94](https://github.com/pingdotgg/uploadthing/pull/94) [`91fb166`](https://github.com/pingdotgg/uploadthing/commit/91fb1660ba9a3dd2eb92df16b5bb1d3373b77662) Thanks [@t3dotgg](https://github.com/t3dotgg)! - Overhauled file router syntax + +### Patch Changes + +- Updated dependencies [[`16157de`](https://github.com/pingdotgg/uploadthing/commit/16157de54198d0838007efb4f6a37a4cd8720bab), [`91fb166`](https://github.com/pingdotgg/uploadthing/commit/91fb1660ba9a3dd2eb92df16b5bb1d3373b77662), [`b073c96`](https://github.com/pingdotgg/uploadthing/commit/b073c96120edccf9c9dd8f6db78611f43b841d20)]: + - uploadthing@4.0.0 + ## 3.0.5 ### Patch Changes diff --git a/packages/react/package.json b/packages/react/package.json index 066e0b0d2..489e9d888 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "@uploadthing/react", - "version": "3.0.5", + "version": "4.0.0", "license": "MIT", "exports": { "./package.json": "./package.json", @@ -36,7 +36,7 @@ "peerDependencies": { "react": "^17.0.2 || ^18.0.0", "react-dropzone": "^14.2.3", - "uploadthing": "3.0.5" + "uploadthing": "4.0.0" }, "devDependencies": { "@tailwindcss/forms": "^0.5.3", @@ -54,7 +54,7 @@ "tailwindcss": "^3.3.2", "tsup": "6.7.0", "typescript": "5.1.0-beta", - "uploadthing": "3.0.5", + "uploadthing": "4.0.0", "vitest": "^0.30.1", "wait-on": "^7.0.1" }, diff --git a/packages/uploadthing/CHANGELOG.md b/packages/uploadthing/CHANGELOG.md index 6223f1ec5..37fe7a73c 100644 --- a/packages/uploadthing/CHANGELOG.md +++ b/packages/uploadthing/CHANGELOG.md @@ -1,5 +1,19 @@ # uploadthing +## 4.0.0 + +### Major Changes + +- [#94](https://github.com/pingdotgg/uploadthing/pull/94) [`91fb166`](https://github.com/pingdotgg/uploadthing/commit/91fb1660ba9a3dd2eb92df16b5bb1d3373b77662) Thanks [@t3dotgg](https://github.com/t3dotgg)! - Overhauled file router syntax + +### Minor Changes + +- [#93](https://github.com/pingdotgg/uploadthing/pull/93) [`16157de`](https://github.com/pingdotgg/uploadthing/commit/16157de54198d0838007efb4f6a37a4cd8720bab) Thanks [@markflorkowski](https://github.com/markflorkowski)! - [feat] API Helpers -- deleteFiles() and getFileUrls() + +### Patch Changes + +- [#97](https://github.com/pingdotgg/uploadthing/pull/97) [`b073c96`](https://github.com/pingdotgg/uploadthing/commit/b073c96120edccf9c9dd8f6db78611f43b841d20) Thanks [@ayatofrench](https://github.com/ayatofrench)! - [Fix] Update to buildRequestHandler secret + ## 3.0.5 ### Patch Changes diff --git a/packages/uploadthing/package.json b/packages/uploadthing/package.json index 26e3813cd..f0f81d965 100644 --- a/packages/uploadthing/package.json +++ b/packages/uploadthing/package.json @@ -1,6 +1,6 @@ { "name": "uploadthing", - "version": "3.0.5", + "version": "4.0.0", "license": "MIT", "exports": { "./package.json": "./package.json", diff --git a/packages/uploadthing/src/next/core/page.ts b/packages/uploadthing/src/next/core/page.ts index 4a76f23b1..f9808d5e1 100644 --- a/packages/uploadthing/src/next/core/page.ts +++ b/packages/uploadthing/src/next/core/page.ts @@ -36,10 +36,13 @@ export const createNextPageApiHandler = ( return res.status(400).send("`actionType` must not be an array"); if (uploadthingHook && typeof uploadthingHook !== "string") return res.status(400).send("`uploadthingHook` must not be an array"); + if (typeof req.body !== "string") + return res.status(400).send("Request body must be a JSON string"); const standardRequest = { ...req, - json: () => Promise.resolve(req.body), + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + json: () => Promise.resolve(JSON.parse(req.body)), headers: { get: (key: string) => req.headers[key], } as Headers, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c0f1a309d..b3e7dd15d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -62,7 +62,7 @@ importers: specifier: ^4.28.0 version: 4.28.0(react-dom@18.2.0)(react@18.2.0) '@uploadthing/react': - specifier: 3.0.5 + specifier: 4.0.0 version: link:../../packages/react autoprefixer: specifier: 10.4.14 @@ -83,7 +83,7 @@ importers: specifier: ^3.3.2 version: 3.3.2 uploadthing: - specifier: 3.0.5 + specifier: 4.0.0 version: link:../../packages/uploadthing zod: specifier: ^3.21.4 @@ -123,7 +123,7 @@ importers: specifier: ^4.28.0 version: 4.28.0(react-dom@18.2.0)(react@18.2.0) '@uploadthing/react': - specifier: 3.0.5 + specifier: 4.0.0 version: link:../../packages/react autoprefixer: specifier: 10.4.14 @@ -147,7 +147,7 @@ importers: specifier: ^3.3.2 version: 3.3.2 uploadthing: - specifier: 3.0.5 + specifier: 4.0.0 version: link:../../packages/uploadthing zod: specifier: ^3.21.4 @@ -215,7 +215,7 @@ importers: version: 5.20.0 uploadthing: specifier: 3.0.5 - version: link:../../packages/uploadthing + version: 3.0.5 zod: specifier: ^3.21.4 version: 3.21.4 @@ -347,7 +347,7 @@ importers: specifier: 5.1.0-beta version: 5.1.0-beta uploadthing: - specifier: 3.0.5 + specifier: 4.0.0 version: link:../uploadthing vitest: specifier: ^0.30.1 @@ -387,7 +387,7 @@ importers: version: 5.1.0-beta uploadthing: specifier: 3.0.5 - version: link:../uploadthing + version: 3.0.5 packages/uploadthing: dependencies: @@ -9031,6 +9031,9 @@ packages: escalade: 3.1.1 picocolors: 1.0.0 + /uploadthing@3.0.5: + resolution: {integrity: sha512-/AHyRKp6nnI0DLbjBeKf/JYqQNW6qIYVVBiVyDQewlJk+NtP5R7ux8aPGNrgdZOonXWrM3pDYaY7+FtplQ7sPA==} + /uri-js@4.4.1: resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} dependencies: