feat: enhance share service and API routes for better parameter handling

- Updated ShareService to hash passwords conditionally before storing them in the database.
- Modified API route handlers to await parameters, improving the handling of dynamic route parameters in the fetch requests.
- Added .gitignore entry for Prisma database files to prevent them from being tracked.
This commit is contained in:
Daniel Luiz Alves 2025-06-01 00:52:46 -03:00
parent d3b7fe04ed
commit 9dff734f9f
5 changed files with 18 additions and 17 deletions

View File

@ -3,3 +3,4 @@ node_modules
dist/*
uploads/*
temp-chunks/*
prisma/*.db

View File

@ -45,7 +45,7 @@ export class ShareService {
async createShare(data: CreateShareInput, userId: string) {
const security = await prisma.shareSecurity.create({
data: {
password: data.password,
password: data.password ? await bcrypt.hash(data.password, 10) : null,
maxViews: data.maxViews,
},
});

View File

@ -1,10 +1,11 @@
import { NextRequest, NextResponse } from "next/server";
export async function POST(req: NextRequest, { params }: { params: { shareId: string } }) {
export async function POST(req: NextRequest, { params }: { params: Promise<{ shareId: string }> }) {
const body = await req.text();
const cookieHeader = req.headers.get("cookie");
const { shareId } = await params;
const apiRes = await fetch(`${process.env.API_BASE_URL}/shares/${params.shareId}/alias`, {
const apiRes = await fetch(`${process.env.API_BASE_URL}/shares/${shareId}/alias`, {
method: "POST",
headers: {
"Content-Type": "application/json",

View File

@ -1,10 +1,11 @@
import { NextRequest, NextResponse } from "next/server";
export async function GET(req: NextRequest, { params }: { params: { alias: string } }) {
export async function GET(req: NextRequest, { params }: { params: Promise<{ alias: string }> }) {
const cookieHeader = req.headers.get("cookie");
const url = new URL(req.url);
const queryParams = url.search;
const apiRes = await fetch(`${process.env.API_BASE_URL}/shares/alias/${params.alias}${queryParams}`, {
const { alias } = await params;
const apiRes = await fetch(`${process.env.API_BASE_URL}/shares/alias/${alias}${queryParams}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
@ -28,4 +29,4 @@ export async function GET(req: NextRequest, { params }: { params: { alias: strin
}
return res;
}
}

View File

@ -1,20 +1,18 @@
import { NextRequest, NextResponse } from "next/server";
export async function GET(req: NextRequest, { params }: { params: { shareId: string } }) {
export async function GET(req: NextRequest, { params }: { params: Promise<{ shareId: string }> }) {
const cookieHeader = req.headers.get("cookie");
const url = new URL(req.url);
const searchParams = url.searchParams.toString();
const { shareId } = await params;
const apiRes = await fetch(
`${process.env.API_BASE_URL}/shares/${params.shareId}${searchParams ? `?${searchParams}` : ""}`,
{
method: "GET",
headers: {
cookie: cookieHeader || "",
},
redirect: "manual",
}
);
const apiRes = await fetch(`${process.env.API_BASE_URL}/shares/${shareId}${searchParams ? `?${searchParams}` : ""}`, {
method: "GET",
headers: {
cookie: cookieHeader || "",
},
redirect: "manual",
});
const resBody = await apiRes.text();