Advanced file sharing

This is a WIP for advanced file sharing, but I won't pursue this for now since using symlinks in the file system works for me, and this is adding a ton of complexity I don't want or need right now.
This commit is contained in:
Bruno Bernardino
2024-04-04 12:52:44 +01:00
parent 4e5fdd569a
commit a8a0e20428
14 changed files with 547 additions and 100 deletions

View File

@@ -1,7 +1,7 @@
import { Handlers } from 'fresh/server.ts';
import { DirectoryFile, FreshContextState } from '/lib/types.ts';
import { createFile, getFiles } from '/lib/data/files.ts';
import { createFile, getDirectoryAccess, getFileAccess, getFiles } from '/lib/data/files.ts';
interface Data {}
@@ -29,9 +29,25 @@ export const handler: Handlers<Data, FreshContextState> = {
return new Response('Bad Request', { status: 400 });
}
// TODO: Verify user has write access to path and get the appropriate ownerUserId
let { hasWriteAccess, ownerUserId, ownerParentPath } = await getFileAccess(
context.state.user.id,
parentPath,
name.trim(),
);
const createdFile = await createFile(context.state.user.id, parentPath, name.trim(), await contents.arrayBuffer());
if (!hasWriteAccess) {
const directoryAccessResult = await getDirectoryAccess(context.state.user.id, parentPath);
hasWriteAccess = directoryAccessResult.hasWriteAccess;
ownerUserId = directoryAccessResult.ownerUserId;
ownerParentPath = directoryAccessResult.ownerParentPath;
if (!hasWriteAccess) {
return new Response('Forbidden', { status: 403 });
}
}
const createdFile = await createFile(ownerUserId, ownerParentPath, name.trim(), await contents.arrayBuffer());
const newFiles = await getFiles(context.state.user.id, parentPath);