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 { DirectoryFile, FreshContextState } from '/lib/types.ts';
|
||||
import { deleteDirectoryOrFile, getFiles } from '/lib/data/files.ts';
|
||||
import { deleteDirectoryOrFile, getDirectoryAccess, getFileAccess, getFiles } from '/lib/data/files.ts';
|
||||
|
||||
interface Data {}
|
||||
|
||||
@@ -30,14 +30,30 @@ export const handler: Handlers<Data, FreshContextState> = {
|
||||
return new Response('Bad Request', { status: 400 });
|
||||
}
|
||||
|
||||
// TODO: Verify user has write access to path/file and get the appropriate ownerUserId
|
||||
|
||||
const deletedFile = await deleteDirectoryOrFile(
|
||||
let { hasWriteAccess, ownerUserId, ownerParentPath } = await getFileAccess(
|
||||
context.state.user.id,
|
||||
requestBody.parentPath,
|
||||
requestBody.name.trim(),
|
||||
);
|
||||
|
||||
if (!hasWriteAccess) {
|
||||
const directoryAccessResult = await getDirectoryAccess(context.state.user.id, requestBody.parentPath);
|
||||
|
||||
hasWriteAccess = directoryAccessResult.hasWriteAccess;
|
||||
ownerUserId = directoryAccessResult.ownerUserId;
|
||||
ownerParentPath = directoryAccessResult.ownerParentPath;
|
||||
|
||||
if (!hasWriteAccess) {
|
||||
return new Response('Forbidden', { status: 403 });
|
||||
}
|
||||
}
|
||||
|
||||
const deletedFile = await deleteDirectoryOrFile(
|
||||
ownerUserId,
|
||||
ownerParentPath,
|
||||
requestBody.name.trim(),
|
||||
);
|
||||
|
||||
const newFiles = await getFiles(context.state.user.id, requestBody.parentPath);
|
||||
|
||||
const responseBody: ResponseBody = { success: deletedFile, newFiles };
|
||||
|
||||
Reference in New Issue
Block a user