From 44445734ba4a0f05564f808c2fd34a7f23c6fafb Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 20 May 2026 10:16:50 +0200 Subject: Let's do a rewrite! Created project structure and changed `build.zig` and added licence. --- static/api/images.js | 83 ---------------------------------------------------- 1 file changed, 83 deletions(-) delete mode 100644 static/api/images.js (limited to 'static/api/images.js') diff --git a/static/api/images.js b/static/api/images.js deleted file mode 100644 index 8e9cff2..0000000 --- a/static/api/images.js +++ /dev/null @@ -1,83 +0,0 @@ -import * as sfw from 'sfw'; -const { Input } = sfw.element.native; -import * as rest from './rest.js'; - -class FileUploader { - constructor(url, files) { - this.onprogress = () => {} - this.ondone = () => {} - this.url = url; - this.sessions = []; - this.files = files; - } - - send() { - let count = 0; - this.sessions = this.sessions.concat(this.files.map( - (file) => new Promise((resolve) => { - const xhr = new XMLHttpRequest(); - xhr.addEventListener("loadend", (event) => { - count += 1; - - this.onprogress(count, this.files.length) - - resolve(xhr.readyState === 4 && xhr.status === 200); - - if (count == this.files.length) { - this.ondone(); - } - }); - - xhr.open("POST", this.url, true); - xhr.setRequestHeader("Content-Type", "application/octet-stream"); - xhr.send(file.slice()); - }) - )); - } -} - -export async function upload_to_timeline() { - const input = Input.new({ - type: 'file', - multiple: true, - accept: 'image/jpeg', - }) - input.click(); - - - return new Promise((resolve) => { - input.onchange = () => { - resolve(new FileUploader('/api/image/upload', [...input.files])); - } - }) -} - -export async function upload_to_profile(id) { - const input = Input.new({ - type: 'file', - multiple: false, - accept: 'image/jpeg', - }) - input.click(); - - return new Promise((resolve) => { - input.onchange = () => { - resolve(new FileUploader(`/api/profile/image/upload/${id}`, [...input.files])); - } - }) -} - -export function list() { - return rest.get('/api/image/list') - .then(r => { - r.images.forEach(i => { - i.date = new Date(i.timestamp * 1000) - }); - return r.images; - }); -} - - -export function remove(id) { - return rest.post('/api/image/remove', { id: id }); -} -- cgit v1.2.3-70-g09d2