Enable image pasting in markdown textarea

This commit is contained in:
thiloho
2024-08-19 19:31:41 +02:00
parent ec23a6188a
commit 5cc329c2f1
5 changed files with 99 additions and 3 deletions

View File

@@ -180,5 +180,30 @@ export const actions: Actions = {
success: true,
message: "Successfully updated footer"
};
},
pasteImage: async ({ request, fetch, cookies, params }) => {
const data = await request.formData();
const file = data.get("file") as File;
const fileData = await fetch(`${API_BASE_PREFIX}/rpc/upload_file`, {
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
Authorization: `Bearer ${cookies.get("session_token")}`,
Accept: "application/vnd.pgrst.object+json",
"X-Website-Id": params.websiteId,
"X-Mimetype": file.type,
"X-Original-Filename": file.name
},
body: await file.arrayBuffer()
});
const fileJSON = await fileData.json();
if (!fileData.ok) {
return { success: false, message: fileJSON.message };
}
return { fileId: fileJSON.file_id };
}
};