aboutsummaryrefslogtreecommitdiff
path: root/static/api
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2026-05-20 10:16:50 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2026-05-20 10:16:50 +0200
commit44445734ba4a0f05564f808c2fd34a7f23c6fafb (patch)
tree3bd22add718620cbf931286f55137bcc666100be /static/api
parent95ae9f15e1db335a7f8358d811ea37e2c89dd10f (diff)
Let's do a rewrite!
Created project structure and changed `build.zig` and added licence.
Diffstat (limited to 'static/api')
-rw-r--r--static/api/auth.js12
-rw-r--r--static/api/images.js83
-rw-r--r--static/api/index.js4
-rw-r--r--static/api/profile.js15
-rw-r--r--static/api/rest.js22
-rw-r--r--static/api/session.js23
6 files changed, 0 insertions, 159 deletions
diff --git a/static/api/auth.js b/static/api/auth.js
deleted file mode 100644
index e663d88..0000000
--- a/static/api/auth.js
+++ /dev/null
@@ -1,12 +0,0 @@
-import * as rest from './rest.js';
-
-
-export async function login(user, password) {
- const response = await rest.post('/api/auth/login', { user, password });
- return response?.success ?? false;
-}
-
-export async function is_first_login(user) {
- const response = await rest.post('/api/auth/first-login', { user });
- return response?.is_first ?? false;
-}
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 });
-}
diff --git a/static/api/index.js b/static/api/index.js
deleted file mode 100644
index cddd7bd..0000000
--- a/static/api/index.js
+++ /dev/null
@@ -1,4 +0,0 @@
-export * as images from './images.js';
-export * as auth from './auth.js';
-export * as session from './session.js';
-export * as profile from './profile.js';
diff --git a/static/api/profile.js b/static/api/profile.js
deleted file mode 100644
index d6acd16..0000000
--- a/static/api/profile.js
+++ /dev/null
@@ -1,15 +0,0 @@
-import * as rest from './rest.js';
-
-export async function set(name, birthday) {
- await rest.post('/api/profile/set', {
- full_name: name,
- birthday: birthday,
- });
-}
-
-export function update_password(old, next) {
- return rest.post('/api/profile/update-password', {
- current_password: old,
- new_password: next,
- }).then(r => r.success);
-}
diff --git a/static/api/rest.js b/static/api/rest.js
deleted file mode 100644
index 6b14034..0000000
--- a/static/api/rest.js
+++ /dev/null
@@ -1,22 +0,0 @@
-
-async function handle_fetch(promise) {
- const result = await promise;
- const json = await result.json();
-
- if (!result.ok) {
- throw json;
- }
-
- return json;
-}
-
-export function get(url) {
- return handle_fetch(fetch(url));
-}
-
-export function post(url, body) {
- return handle_fetch(fetch(url, {
- method: 'POST',
- body: JSON.stringify(body),
- }));
-}
diff --git a/static/api/session.js b/static/api/session.js
deleted file mode 100644
index 6e14d55..0000000
--- a/static/api/session.js
+++ /dev/null
@@ -1,23 +0,0 @@
-import * as rest from './rest.js';
-
-export function current() {
- return rest.get('/api/session/current');
-}
-
-export async function is_valid() {
- const result = await rest.get('/api/session/is-valid');
- return result.is_valid;
-}
-
-export async function drop() {
- const result = await rest.get('/api/session/drop');
-}
-
-export async function is_online() {
- try {
- const result = await rest.get('/api/session/is-online');
- return result.is_online;
- } catch {
- return false;
- }
-}