Skip to content

Commit

Permalink
test[ENV]: Added test for .env uploadthing app api
Browse files Browse the repository at this point in the history
Need to fix that storgae internal error 500
  • Loading branch information
Parazeeknova authored and Parazeeknova committed Oct 15, 2024
1 parent ab41be6 commit 648ebd8
Show file tree
Hide file tree
Showing 9 changed files with 7,088 additions and 7,060 deletions.
148 changes: 74 additions & 74 deletions apps/web/package.json
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"
}
}
48 changes: 24 additions & 24 deletions apps/web/src/app/(main)/users/[username]/actions.ts
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;
}
92 changes: 46 additions & 46 deletions apps/web/src/app/api/uploadthing/core.ts
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;
11 changes: 11 additions & 0 deletions apps/web/src/app/api/verify-env.ts
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" });
}
Loading

0 comments on commit 648ebd8

Please sign in to comment.