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 { getFiles, renameDirectoryOrFile } from '/lib/data/files.ts';
|
||||
import { getDirectoryAccess, getFileAccess, getFiles, renameDirectoryOrFile } from '/lib/data/files.ts';
|
||||
|
||||
interface Data {}
|
||||
|
||||
@@ -33,12 +33,35 @@ export const handler: Handlers<Data, FreshContextState> = {
|
||||
return new Response('Bad Request', { status: 400 });
|
||||
}
|
||||
|
||||
// TODO: Verify user has write access to old and new paths/files and get the appropriate ownerUserIds
|
||||
|
||||
const movedFile = await renameDirectoryOrFile(
|
||||
let { hasWriteAccess: hasOldWriteAccess, ownerUserId, ownerParentPath: oldOwnerParentPath } = await getFileAccess(
|
||||
context.state.user.id,
|
||||
requestBody.oldParentPath,
|
||||
requestBody.name.trim(),
|
||||
);
|
||||
|
||||
if (!hasOldWriteAccess) {
|
||||
const directoryAccessResult = await getDirectoryAccess(context.state.user.id, requestBody.oldParentPath);
|
||||
|
||||
hasOldWriteAccess = directoryAccessResult.hasWriteAccess;
|
||||
ownerUserId = directoryAccessResult.ownerUserId;
|
||||
oldOwnerParentPath = directoryAccessResult.ownerParentPath;
|
||||
|
||||
return new Response('Forbidden', { status: 403 });
|
||||
}
|
||||
|
||||
const { hasWriteAccess: hasNewWriteAccess, ownerParentPath: newOwnerParentPath } = await getDirectoryAccess(
|
||||
context.state.user.id,
|
||||
requestBody.newParentPath,
|
||||
);
|
||||
|
||||
if (!hasNewWriteAccess) {
|
||||
return new Response('Forbidden', { status: 403 });
|
||||
}
|
||||
|
||||
const movedFile = await renameDirectoryOrFile(
|
||||
ownerUserId,
|
||||
oldOwnerParentPath,
|
||||
newOwnerParentPath,
|
||||
requestBody.name.trim(),
|
||||
requestBody.name.trim(),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user