mirror of
https://github.com/kyantech/Palmr.git
synced 2026-01-09 06:02:28 +08:00
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:
parent
d3b7fe04ed
commit
9dff734f9f
1
apps/server/.gitignore
vendored
1
apps/server/.gitignore
vendored
@ -3,3 +3,4 @@ node_modules
|
||||
dist/*
|
||||
uploads/*
|
||||
temp-chunks/*
|
||||
prisma/*.db
|
||||
|
||||
@ -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,
|
||||
},
|
||||
});
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user