MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / post

Function post

pages/api/files/delete-share.ts:18–52  ·  view source on GitHub ↗
({ request, user }: RequestHandlerParams)

Source from the content-addressed store, hash-verified

16}
17
18async function post({ request, user }: RequestHandlerParams) {
19 const isPublicFileSharingAllowed = await AppConfig.isPublicFileSharingAllowed();
20
21 if (!isPublicFileSharingAllowed) {
22 return new Response('Forbidden', { status: 403 });
23 }
24
25 if (!(await AppConfig.isAppEnabled('files'))) {
26 return new Response('Forbidden', { status: 403 });
27 }
28
29 const requestBody = await request.clone().json() as RequestBody;
30
31 if (
32 !requestBody.fileShareId || !requestBody.pathInView || !requestBody.pathInView.trim() ||
33 !requestBody.pathInView.startsWith('/') || requestBody.pathInView.includes('../')
34 ) {
35 return new Response('Bad Request', { status: 400 });
36 }
37
38 const fileShare = await FileShareModel.getById(requestBody.fileShareId);
39
40 if (!fileShare || fileShare.user_id !== user!.id) {
41 return new Response('Not Found', { status: 404 });
42 }
43
44 await FileShareModel.delete(requestBody.fileShareId);
45
46 const newFiles = await FileModel.list(user!.id, requestBody.pathInView);
47 const newDirectories = await DirectoryModel.list(user!.id, requestBody.pathInView);
48
49 const responseBody: ResponseBody = { success: true, newFiles, newDirectories };
50
51 return new Response(JSON.stringify(responseBody));
52}
53
54export default page({
55 post,

Callers

nothing calls this directly

Calls 6

isAppEnabledMethod · 0.80
cloneMethod · 0.80
getByIdMethod · 0.45
deleteMethod · 0.45
listMethod · 0.45

Tested by

no test coverage detected