-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update API routes and fix user settings
- Loading branch information
Showing
7 changed files
with
162 additions
and
106 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
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
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
This file was deleted.
Oops, something went wrong.
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,45 @@ | ||
import { NextResponse } from "next/server"; | ||
import { headers } from "next/headers"; | ||
|
||
export const runtime = "edge"; | ||
|
||
export async function POST(request) { | ||
try { | ||
const headersList = headers(); | ||
const cookieHeader = headersList.get("cookie"); | ||
|
||
// Assume the last segment of the URL is the user ID | ||
const userId = request.url.split("/").pop(); | ||
|
||
const requestData = await request.arrayBuffer(); | ||
|
||
if (!userId) { | ||
throw new Error("User ID is required"); | ||
} | ||
|
||
// Construct the URL for the external fetch | ||
const fetchURL = `${process.env.NEXT_PUBLIC_DOMAIN_API}/api/user-data/${userId}`; | ||
const uploadUrl = `${process.env.NEXT_PUBLIC_DOMAIN_API}/v1/storage/buckets/655842922bac16a94a25/files`; | ||
|
||
const response = await fetch(fetchURL, { | ||
method: "POST", | ||
headers: { | ||
"X-Appwrite-Project": `${process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID}`, | ||
"X-Appwrite-Response-Format": "1.4.0", | ||
"Content-Type": | ||
request.headers.get("Content-Type") || "multipart/form-data", | ||
Cookie: cookieHeader, | ||
}, | ||
body: requestData, | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error("Failed to update data"); | ||
} | ||
|
||
const data = await response.json(); | ||
return NextResponse.json(data, { status: 200 }); | ||
} catch (error) { | ||
return NextResponse.json(error.message, { status: 500 }); | ||
} | ||
} |
Oops, something went wrong.