From 5ea28dc078c45ce3cf1e1ddaf616bec035854c56 Mon Sep 17 00:00:00 2001 From: ari melody Date: Fri, 5 Jul 2024 15:31:35 +0100 Subject: [PATCH] add edit post api handler (#6) --- src/lib/api.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/lib/api.js b/src/lib/api.js index 930b784..733e172 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -221,6 +221,29 @@ export async function createPost(host, token, post_data) { return await data.json() } +/** + * PUT /api/v1/statuses/{post_id} + * @param {string} host - The domain of the target server. + * @param {string} token - The application token + * @param {any} post_id - The ID of the post to edit. + * @param {any} post_data - The post content + */ +export async function editPost(host, token, post_id, post_data) { + let formdata = new FormData(); + for (const key in post_data) { + formdata.append(key, post_data[key]); + } + + let url = `https://${host}/api/v1/statuses/${post_id}`; + const data = await fetch(url, { + method: 'POST', + headers: { "Authorization": `Bearer ${token}` }, + body: formdata + }) + + return await data.json() +} + /** * GET /api/v1/statuses/{post_id}/context. * @param {string} host - The domain of the target server.