From 2faaeaedb365e3eb1b3fdfd463a22a5cf39244a4 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Thu, 27 Jun 2024 18:24:57 -0400 Subject: [PATCH] chore: add write request to kdmod --- mods/mods_available/kdmod/gui/main.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mods/mods_available/kdmod/gui/main.js b/mods/mods_available/kdmod/gui/main.js index ce69189d..cc3f55b9 100644 --- a/mods/mods_available/kdmod/gui/main.js +++ b/mods/mods_available/kdmod/gui/main.js @@ -74,6 +74,28 @@ const request_examples = [ const resp = await this.fetch(...a); return await this.out(resp); }, + }, + { + name: 'write file', + fetch: async (path, str) => { + const endpoint = `${window.api_origin}/write`; + const token = puter.authToken; + + const blob = new Blob([str], { type: 'text/plain' }); + const formData = new FormData(); + formData.append('create_missing_ancestors', true); + formData.append('path', path); + formData.append('size', 8); + formData.append('overwrite', true); + formData.append('file', blob, 'something.txt'); + + const response = await fetch(endpoint, { + method: 'POST', + headers: { 'Authorization': `Bearer ${token}` }, + body: formData + }); + return await response.json(); + }, } ];