From 01768da6476fa7d7783ce49286132c60f43e4d46 Mon Sep 17 00:00:00 2001 From: Andy Burke Date: Tue, 12 Aug 2025 16:00:36 -0700 Subject: [PATCH] feature: avatar uploads --- README.md | 5 +- deno.json | 6 +- deno.lock | 8 +- public/_pre.ts | 1 + public/js/api.js | 2 + public/tabs/profile/profile.html | 131 ++++++++++++++++++++++++++++--- tests/01_file_uploads.test.ts | 4 + 7 files changed, 139 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 8636384..76bfb42 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,13 @@ feature discussions. - [X] log in - [X] refactor login/sessions/totp - [ ] media uploads - - [ ] local upload support (keep it simple for small instances) + - [X] local upload support (keep it simple for small instances) - [ ] S3 support (then self-host with your friends: https://garagehq.deuxfleurs.fr/) + - [ ] test mounting an s3 volume under /files and having no s3 support in the codebase - [X] user profile page - [X] logout button - [ ] profile editing - - [ ] avatar uploads + - [X] avatar uploads - [X] chat rooms - [X] chat messages - [ ] @-prefixing of users for notifications/highlighting diff --git a/deno.json b/deno.json index b9438c4..3d4c012 100644 --- a/deno.json +++ b/deno.json @@ -7,8 +7,8 @@ "tasks": { "lint": "deno lint", "fmt": "deno fmt", - "serve": "FSDB_ROOT=$PWD/.fsdb TRACE_ERROR_RESPONSES=true SERVERUS_TYPESCRIPT_IMPORT_LOGGING=true SERVERUS_PUT_PATHS_ALLOWED=./public/files SERVERUS_DELETE_PATHS_ALLOWED=./public/files deno --allow-env --allow-read --allow-write --allow-net @andyburke/serverus --root ./public --hostname 0.0.0.0", - "test": "DENO_ENV=test FSDB_ROOT=$PWD/tests/data/$(date --iso-8601=seconds) SERVERUS_ROOT=$PWD/public deno test --allow-env --allow-read --allow-write --allow-net --allow-import --trace-leaks --fail-fast tests/" + "serve": "FSDB_ROOT=$PWD/.fsdb TRACE_ERROR_RESPONSES=true SERVERUS_TYPESCRIPT_IMPORT_LOGGING=true SERVERUS_PUT_PATHS_ALLOWED=./files SERVERUS_DELETE_PATHS_ALLOWED=./files deno --allow-env --allow-read --allow-write --allow-net @andyburke/serverus --root ./public --hostname 0.0.0.0", + "test": "DENO_ENV=test FSDB_ROOT=$PWD/tests/data/$(date --iso-8601=seconds) SERVERUS_ROOT=$PWD/public SERVERUS_PUT_PATHS_ALLOWED=./files SERVERUS_DELETE_PATHS_ALLOWED=./files deno test --allow-env --allow-read --allow-write --allow-net --allow-import --trace-leaks --fail-fast tests/" }, "test": { "exclude": ["tests/data/"] @@ -34,7 +34,7 @@ "imports": { "@andyburke/fsdb": "jsr:@andyburke/fsdb@^1.0.2", "@andyburke/lurid": "jsr:@andyburke/lurid@^0.2.0", - "@andyburke/serverus": "jsr:@andyburke/serverus@^0.12.2", + "@andyburke/serverus": "jsr:@andyburke/serverus@^0.12.5", "@da/bcrypt": "jsr:@da/bcrypt@^1.0.1", "@std/assert": "jsr:@std/assert@^1.0.13", "@std/encoding": "jsr:@std/encoding@^1.0.10", diff --git a/deno.lock b/deno.lock index 243b97c..2c74cb8 100644 --- a/deno.lock +++ b/deno.lock @@ -3,7 +3,7 @@ "specifiers": { "jsr:@andyburke/fsdb@^1.0.2": "1.0.2", "jsr:@andyburke/lurid@0.2": "0.2.0", - "jsr:@andyburke/serverus@~0.12.2": "0.12.2", + "jsr:@andyburke/serverus@~0.12.5": "0.12.5", "jsr:@da/bcrypt@*": "1.0.1", "jsr:@da/bcrypt@^1.0.1": "1.0.1", "jsr:@std/assert@^1.0.13": "1.0.13", @@ -41,8 +41,8 @@ "jsr:@std/cli@^1.0.19" ] }, - "@andyburke/serverus@0.12.2": { - "integrity": "17cf6d7cb58857c4bc34ee96aa718c05edf0fd4fe159afc5890253e50bd99c3a", + "@andyburke/serverus@0.12.5": { + "integrity": "c6bf017e82f20625f9d29dacaa7e2b034e91c37b8171f6725fade4599db66864", "dependencies": [ "jsr:@std/cli@^1.0.21", "jsr:@std/fmt@^1.0.6", @@ -131,7 +131,7 @@ "dependencies": [ "jsr:@andyburke/fsdb@^1.0.2", "jsr:@andyburke/lurid@0.2", - "jsr:@andyburke/serverus@~0.12.2", + "jsr:@andyburke/serverus@~0.12.5", "jsr:@da/bcrypt@^1.0.1", "jsr:@std/assert@^1.0.13", "jsr:@std/encoding@^1.0.10", diff --git a/public/_pre.ts b/public/_pre.ts index e20765c..fe09978 100644 --- a/public/_pre.ts +++ b/public/_pre.ts @@ -18,6 +18,7 @@ export function load() { const is_to_home_dir = meta.user?.id && path.toLowerCase().startsWith(`/files/users/${meta.user.id}/`); const has_permission = is_to_files && (can_write_all_files || (can_write_own_files && is_to_home_dir)); + if (!has_permission) { return CANNED_RESPONSES.permission_denied(); } diff --git a/public/js/api.js b/public/js/api.js index c9b0683..6aaea4b 100644 --- a/public/js/api.js +++ b/public/js/api.js @@ -24,6 +24,8 @@ const api = { if (options.json) { headers["Content-Type"] = "application/json"; fetch_options.body = JSON.stringify(options.json); + } else if (options.body) { + fetch_options.body = options.body; } const response = await fetch(url, fetch_options); diff --git a/public/tabs/profile/profile.html b/public/tabs/profile/profile.html index 8f93057..3d90ef7 100644 --- a/public/tabs/profile/profile.html +++ b/public/tabs/profile/profile.html @@ -1,4 +1,6 @@
- +
diff --git a/tests/01_file_uploads.test.ts b/tests/01_file_uploads.test.ts index bd93ae9..39eb3c5 100644 --- a/tests/01_file_uploads.test.ts +++ b/tests/01_file_uploads.test.ts @@ -23,6 +23,10 @@ Deno.test({ fn: async () => { let test_server_info: EPHEMERAL_SERVER | null = null; try { + console.dir({ + SERVERUS_PUT_PATHS_ALLOWED: Deno.env.get('SERVERUS_PUT_PATHS_ALLOWED') + }); + test_server_info = await get_ephemeral_listen_server(); const client: API_CLIENT = api({ prefix: '/api',