feature: file uploading

This commit is contained in:
Andy Burke 2025-08-11 18:02:29 -07:00
parent a144c88c17
commit ffe0678e5b
8 changed files with 388 additions and 13 deletions

26
public/_pre.ts Normal file
View file

@ -0,0 +1,26 @@
import { PRECHECKS } from '@andyburke/serverus/handlers/static';
import { get_session, get_user, require_user } from '../utils/prechecks.ts';
import * as CANNED_RESPONSES from '../utils/canned_responses.ts';
export function load() {
PRECHECKS.PUT = [
get_session,
get_user,
require_user,
(request: Request, meta: Record<string, any>): Response | undefined => {
const can_write_own_files = meta.user?.permissions.includes('files.write.own');
const can_write_all_files = meta.user?.permissions.includes('files.write.all');
const path = new URL(request.url).pathname;
const is_to_files = path.toLowerCase().startsWith('/files/');
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();
}
}
];
}

View file

@ -10,6 +10,7 @@ import * as bcrypt from '@da/bcrypt';
// TODO: figure out a better solution for doling out permissions
const DEFAULT_USER_PERMISSIONS: string[] = [
'files.write.own',
'self.read',
'self.write',
'rooms.read',