integratedhub/routes/api/photo-upload.ts
2026-02-14 02:20:19 +00:00

35 lines
1.1 KiB
TypeScript

import { define } from "../../utils.ts";
export const handler = define.handlers({
async POST(ctx) {
const auth = ctx.req.headers.get("Authorization");
if (!auth || !auth.startsWith("Bearer ")) {
return new Response("Unauthorized", { status: 401 });
}
// Parse form data and save the file as needed
const form = await ctx.req.formData();
const file = form.get("photo");
if (!(file instanceof File)) {
return new Response("No file uploaded", { status: 400 });
}
// For demo, just print details (replace with Microsoft Graph logic)
const arr = new Uint8Array(await file.arrayBuffer());
// -- Here you'd use fetch to Microsoft Graph API with the access token --
// Example:
// await fetch("https://graph.microsoft.com/v1.0/me/photo/$value", {
// method: "PUT",
// headers: {
// "Authorization": auth,
// "Content-Type": "image/jpeg"
// },
// body: arr,
// });
return new Response(JSON.stringify({ success: true, size: arr.length }), {
headers: { "Content-Type": "application/json" },
});
},
});