-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test[ENV]: Added test for .env uploadthing app api
Need to fix that storgae internal error 500
- Loading branch information
Parazeeknova
authored and
Parazeeknova
committed
Oct 15, 2024
1 parent
ab41be6
commit 648ebd8
Showing
9 changed files
with
7,088 additions
and
7,060 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 |
---|---|---|
@@ -1,74 +1,74 @@ | ||
{ | ||
"name": "@zephyr/web", | ||
"version": "0.0.1", | ||
"license": "AGPL-3.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "next dev --turbo", | ||
"build": "next build", | ||
"start": "next start", | ||
"lint": "next lint" | ||
}, | ||
"dependencies": { | ||
"@emotion/styled": "^11.13.0", | ||
"@hookform/resolvers": "^3.9.0", | ||
"@mui/icons-material": "^6.1.3", | ||
"@node-rs/argon2": "^2.0.0", | ||
"@prisma/client": "^5.20.0", | ||
"@radix-ui/react-avatar": "^1.1.1", | ||
"@radix-ui/react-dialog": "^1.1.2", | ||
"@radix-ui/react-dropdown-menu": "^2.1.2", | ||
"@radix-ui/react-icons": "^1.3.0", | ||
"@radix-ui/react-label": "^2.1.0", | ||
"@radix-ui/react-scroll-area": "^1.2.0", | ||
"@radix-ui/react-separator": "^1.1.0", | ||
"@radix-ui/react-slot": "^1.1.0", | ||
"@radix-ui/react-tabs": "^1.1.1", | ||
"@radix-ui/react-toast": "^1.2.2", | ||
"@radix-ui/react-tooltip": "^1.1.3", | ||
"@tanstack/react-query": "^5.59.13", | ||
"@tanstack/react-query-devtools": "^5.59.13", | ||
"@tiptap/extension-placeholder": "^2.8.0", | ||
"@tiptap/react": "^2.8.0", | ||
"@tiptap/starter-kit": "^2.8.0", | ||
"@tsparticles/engine": "^3.5.0", | ||
"@tsparticles/react": "^3.0.0", | ||
"@tsparticles/slim": "^3.5.0", | ||
"@uploadthing/react": "^7.0.3", | ||
"@zephyr/auth": "workspace:*", | ||
"@zephyr/db": "workspace:*", | ||
"@zephyr/ui": "workspace:*", | ||
"class-variance-authority": "^0.7.0", | ||
"clsx": "^2.1.1", | ||
"cn": "^0.1.1", | ||
"cropperjs": "^1.6.2", | ||
"date-fns": "^4.1.0", | ||
"framer-motion": "^11.11.8", | ||
"ky": "^1.7.2", | ||
"lucia": "^3.2.1", | ||
"lucide-react": "^0.452.0", | ||
"next": "15.0.0-rc.0", | ||
"next-themes": "^0.3.0", | ||
"react": "19.0.0-rc-459fd418-20241001", | ||
"react-cropper": "^2.3.3", | ||
"react-dom": "19.0.0-rc.0", | ||
"react-hook-form": "^7.53.0", | ||
"react-image-file-resizer": "^0.4.8", | ||
"react-intersection-observer": "^9.13.1", | ||
"react-linkify-it": "^1.0.8", | ||
"tailwind-merge": "^2.5.4", | ||
"tailwindcss-animate": "^1.0.7", | ||
"uploadthing": "^7.1.0" | ||
}, | ||
"devDependencies": { | ||
"@tailwindcss/aspect-ratio": "0.4.2", | ||
"@types/node": "^22.7.5", | ||
"@types/react": "^18.3.11", | ||
"@types/react-dom": "^18.3.1", | ||
"@zephyr/config": "workspace:*", | ||
"autoprefixer": "^10.4.20", | ||
"postcss": "^8.4.47", | ||
"tailwindcss": "^3.4.13", | ||
"typescript": "^5.6.3" | ||
} | ||
} | ||
{ | ||
"name": "@zephyr/web", | ||
"version": "0.0.1", | ||
"license": "AGPL-3.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "next dev --turbo", | ||
"build": "next build", | ||
"start": "next start", | ||
"lint": "next lint" | ||
}, | ||
"dependencies": { | ||
"@emotion/styled": "^11.13.0", | ||
"@hookform/resolvers": "^3.9.0", | ||
"@mui/icons-material": "^6.1.3", | ||
"@node-rs/argon2": "^2.0.0", | ||
"@prisma/client": "^5.20.0", | ||
"@radix-ui/react-avatar": "^1.1.1", | ||
"@radix-ui/react-dialog": "^1.1.2", | ||
"@radix-ui/react-dropdown-menu": "^2.1.2", | ||
"@radix-ui/react-icons": "^1.3.0", | ||
"@radix-ui/react-label": "^2.1.0", | ||
"@radix-ui/react-scroll-area": "^1.2.0", | ||
"@radix-ui/react-separator": "^1.1.0", | ||
"@radix-ui/react-slot": "^1.1.0", | ||
"@radix-ui/react-tabs": "^1.1.1", | ||
"@radix-ui/react-toast": "^1.2.2", | ||
"@radix-ui/react-tooltip": "^1.1.3", | ||
"@tanstack/react-query": "^5.59.13", | ||
"@tanstack/react-query-devtools": "^5.59.13", | ||
"@tiptap/extension-placeholder": "^2.8.0", | ||
"@tiptap/react": "^2.8.0", | ||
"@tiptap/starter-kit": "^2.8.0", | ||
"@tsparticles/engine": "^3.5.0", | ||
"@tsparticles/react": "^3.0.0", | ||
"@tsparticles/slim": "^3.5.0", | ||
"@uploadthing/react": "^7.0.3", | ||
"@zephyr/auth": "workspace:*", | ||
"@zephyr/db": "workspace:*", | ||
"@zephyr/ui": "workspace:*", | ||
"class-variance-authority": "^0.7.0", | ||
"clsx": "^2.1.1", | ||
"cn": "^0.1.1", | ||
"cropperjs": "^1.6.2", | ||
"date-fns": "^4.1.0", | ||
"framer-motion": "^11.11.8", | ||
"ky": "^1.7.2", | ||
"lucia": "^3.2.1", | ||
"lucide-react": "^0.452.0", | ||
"next": "15.0.0-rc.0", | ||
"next-themes": "^0.3.0", | ||
"react": "19.0.0-rc-459fd418-20241001", | ||
"react-cropper": "^2.3.3", | ||
"react-dom": "19.0.0-rc.0", | ||
"react-hook-form": "^7.53.0", | ||
"react-image-file-resizer": "^0.4.8", | ||
"react-intersection-observer": "^9.13.1", | ||
"react-linkify-it": "^1.0.8", | ||
"tailwind-merge": "^2.5.4", | ||
"tailwindcss-animate": "^1.0.7", | ||
"uploadthing": "^7.1.0" | ||
}, | ||
"devDependencies": { | ||
"@tailwindcss/aspect-ratio": "0.4.2", | ||
"@types/node": "^22.7.5", | ||
"@types/react": "^18.3.11", | ||
"@types/react-dom": "^18.3.1", | ||
"@zephyr/config": "workspace:*", | ||
"autoprefixer": "^10.4.20", | ||
"postcss": "^8.4.47", | ||
"tailwindcss": "^3.4.13", | ||
"typescript": "^5.6.3" | ||
} | ||
} |
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,24 +1,24 @@ | ||
"use server"; | ||
|
||
import { validateRequest } from "@zephyr/auth/auth"; | ||
import { | ||
type UpdateUserProfileValues, | ||
updateUserProfileSchema | ||
} from "@zephyr/auth/validation"; | ||
import { getUserDataSelect, prisma } from "@zephyr/db"; | ||
|
||
export async function updateUserProfile(values: UpdateUserProfileValues) { | ||
const validatedValues = updateUserProfileSchema.parse(values); | ||
|
||
const { user } = await validateRequest(); | ||
|
||
if (!user) throw new Error("Unauthorized"); | ||
|
||
const updatedUser = await prisma.user.update({ | ||
where: { id: user.id }, | ||
data: validatedValues, | ||
select: getUserDataSelect(user.id) | ||
}); | ||
|
||
return updatedUser; | ||
} | ||
"use server"; | ||
|
||
import { validateRequest } from "@zephyr/auth/auth"; | ||
import { | ||
type UpdateUserProfileValues, | ||
updateUserProfileSchema | ||
} from "@zephyr/auth/validation"; | ||
import { getUserDataSelect, prisma } from "@zephyr/db"; | ||
|
||
export async function updateUserProfile(values: UpdateUserProfileValues) { | ||
const validatedValues = updateUserProfileSchema.parse(values); | ||
|
||
const { user } = await validateRequest(); | ||
|
||
if (!user) throw new Error("Unauthorized"); | ||
|
||
const updatedUser = await prisma.user.update({ | ||
where: { id: user.id }, | ||
data: validatedValues, | ||
select: getUserDataSelect(user.id) | ||
}); | ||
|
||
return updatedUser; | ||
} |
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,46 +1,46 @@ | ||
import { validateRequest } from "@zephyr/auth/auth"; | ||
import { prisma } from "@zephyr/db"; | ||
import { type FileRouter, createUploadthing } from "uploadthing/next"; | ||
import { UTApi, UploadThingError } from "uploadthing/server"; | ||
|
||
const f = createUploadthing(); | ||
|
||
export const fileRouter = { | ||
avatar: f({ | ||
image: { maxFileSize: "512KB" } | ||
}) | ||
.middleware(async () => { | ||
const { user } = await validateRequest(); | ||
|
||
if (!user) throw new UploadThingError("Unauthorized"); | ||
|
||
return { user }; | ||
}) | ||
.onUploadComplete(async ({ metadata, file }) => { | ||
const oldAvatarUrl = metadata.user.avatarUrl; | ||
|
||
if (oldAvatarUrl) { | ||
const key = oldAvatarUrl.split( | ||
`/a/${process.env.NEXT_PUBLIC_UPLOADTHING_APP_ID}/` | ||
)[1]; | ||
|
||
await new UTApi().deleteFiles(key); | ||
} | ||
|
||
const newAvatarUrl = file.url.replace( | ||
"/f/", | ||
`/a/${process.env.NEXT_PUBLIC_UPLOADTHING_APP_ID}/` | ||
); | ||
|
||
await prisma.user.update({ | ||
where: { id: metadata.user.id }, | ||
data: { | ||
avatarUrl: newAvatarUrl | ||
} | ||
}); | ||
|
||
return { avatarUrl: newAvatarUrl }; | ||
}) | ||
} satisfies FileRouter; | ||
|
||
export type AppFileRouter = typeof fileRouter; | ||
import { validateRequest } from "@zephyr/auth/auth"; | ||
import { prisma } from "@zephyr/db"; | ||
import { type FileRouter, createUploadthing } from "uploadthing/next"; | ||
import { UTApi, UploadThingError } from "uploadthing/server"; | ||
|
||
const f = createUploadthing(); | ||
|
||
export const fileRouter = { | ||
avatar: f({ | ||
image: { maxFileSize: "512KB" } | ||
}) | ||
.middleware(async () => { | ||
const { user } = await validateRequest(); | ||
|
||
if (!user) throw new UploadThingError("Unauthorized"); | ||
|
||
return { user }; | ||
}) | ||
.onUploadComplete(async ({ metadata, file }) => { | ||
const oldAvatarUrl = metadata.user.avatarUrl; | ||
|
||
if (oldAvatarUrl) { | ||
const key = oldAvatarUrl.split( | ||
`/a/${process.env.NEXT_PUBLIC_UPLOADTHING_APP_ID}/` | ||
)[1]; | ||
|
||
await new UTApi().deleteFiles(key); | ||
} | ||
|
||
const newAvatarUrl = file.url.replace( | ||
"/f/", | ||
`/a/${process.env.NEXT_PUBLIC_UPLOADTHING_APP_ID}/` | ||
); | ||
|
||
await prisma.user.update({ | ||
where: { id: metadata.user.id }, | ||
data: { | ||
avatarUrl: newAvatarUrl | ||
} | ||
}); | ||
|
||
return { avatarUrl: newAvatarUrl }; | ||
}) | ||
} satisfies FileRouter; | ||
|
||
export type AppFileRouter = typeof fileRouter; |
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 type { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
export default function handler(_req: NextApiRequest, res: NextApiResponse) { | ||
console.log( | ||
"NEXT_PUBLIC_UPLOADTHING_APP_ID:", | ||
process.env.NEXT_PUBLIC_UPLOADTHING_APP_ID | ||
); | ||
res | ||
.status(200) | ||
.json({ message: "Check server logs for environment variable values" }); | ||
} |
Oops, something went wrong.