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:
@@ -1,7 +1,7 @@
|
||||
import { Handlers } from 'fresh/server.ts';
|
||||
|
||||
import { FreshContextState } from '/lib/types.ts';
|
||||
import { getFile } from '/lib/data/files.ts';
|
||||
import { getFile, getDirectoryAccess, getFileAccess } from '/lib/data/files.ts';
|
||||
|
||||
interface Data {}
|
||||
|
||||
@@ -31,9 +31,25 @@ export const handler: Handlers<Data, FreshContextState> = {
|
||||
currentPath = `${currentPath}/`;
|
||||
}
|
||||
|
||||
// TODO: Verify user has read or write access to path/file and get the appropriate ownerUserId
|
||||
let { hasWriteAccess, ownerUserId, ownerParentPath } = await getFileAccess(
|
||||
context.state.user.id,
|
||||
currentPath,
|
||||
decodeURIComponent(fileName),
|
||||
);
|
||||
|
||||
const fileResult = await getFile(context.state.user.id, currentPath, decodeURIComponent(fileName));
|
||||
if (!hasWriteAccess) {
|
||||
const directoryAccessResult = await getDirectoryAccess(context.state.user.id, currentPath);
|
||||
|
||||
hasWriteAccess = directoryAccessResult.hasWriteAccess;
|
||||
ownerUserId = directoryAccessResult.ownerUserId;
|
||||
ownerParentPath = directoryAccessResult.ownerParentPath;
|
||||
|
||||
if (!hasWriteAccess) {
|
||||
return new Response('Forbidden', { status: 403 });
|
||||
}
|
||||
}
|
||||
|
||||
const fileResult = await getFile(ownerUserId, ownerParentPath, decodeURIComponent(fileName));
|
||||
|
||||
if (!fileResult.success) {
|
||||
return new Response('Not Found', { status: 404 });
|
||||
|
||||
Reference in New Issue
Block a user