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

Function post

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 7

generateHashFunction · 0.90
isAppEnabledMethod · 0.80
cloneMethod · 0.80
getByIdMethod · 0.45
updateMethod · 0.45
listMethod · 0.45

Tested by

no test coverage detected