aboutsummaryrefslogtreecommitdiff
path: root/static/api/images.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/api/images.js')
-rw-r--r--static/api/images.js83
1 files changed, 0 insertions, 83 deletions
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 });
-}