Compare commits

..

No commits in common. "main" and "v4.1.0" have entirely different histories.
main ... v4.1.0

10 changed files with 145 additions and 32 deletions

View file

@ -20,11 +20,9 @@ const config: PartialDeep<Config> = {
// rootPath: 'data-files', // rootPath: 'data-files',
// allowPublicSharing: false, // If true, public file sharing will be allowed (still requires a user to enable sharing for a given file or directory) // allowPublicSharing: false, // If true, public file sharing will be allowed (still requires a user to enable sharing for a given file or directory)
// allowDirectoryDownloads: false, // If true, directories can be downloaded as zip files // allowDirectoryDownloads: false, // If true, directories can be downloaded as zip files
// maxUploadSizeInMegabytes: 100, // The maximum upload size in megabytes. Overrides the core.maxRequestSizeInMegabytes setting on /dav and /api/files/upload endpoints.
// }, // },
// core: { // core: {
// enabledApps: ['dashboard', 'files', 'news', 'notes', 'photos', 'expenses', 'contacts', 'calendar'], // The apps to show, in order of appearance in the header. The first app will be the default one shown after logging in. At least one is required. // enabledApps: ['dashboard', 'files', 'news', 'notes', 'photos', 'expenses', 'contacts', 'calendar'], // The apps to show, in order of appearance in the header. The first app will be the default one shown after logging in. At least one is required.
// maxRequestSizeInMegabytes: 12, // The maximum request size in megabytes.
// }, // },
// visuals: { // visuals: {
// title: 'My own cloud', // title: 'My own cloud',

View file

@ -1,6 +1,6 @@
services: services:
website: website:
image: ghcr.io/bewcloud/bewcloud:v4.1.2 image: ghcr.io/bewcloud/bewcloud:v4.1.0
# NOTE: uncomment below (and comment above) only if you pulled the repo and want to build the image locally # NOTE: uncomment below (and comment above) only if you pulled the repo and want to build the image locally
# build: # build:
# context: . # context: .

View file

@ -25,11 +25,9 @@ export class AppConfig {
rootPath: 'data-files', rootPath: 'data-files',
allowPublicSharing: false, allowPublicSharing: false,
allowDirectoryDownloads: false, allowDirectoryDownloads: false,
maxUploadSizeInMegabytes: 100,
}, },
core: { core: {
enabledApps: ['dashboard', 'files', 'news', 'notes', 'photos', 'expenses', 'contacts', 'calendar'], enabledApps: ['dashboard', 'files', 'news', 'notes', 'photos', 'expenses', 'contacts', 'calendar'],
maxRequestSizeInMegabytes: 12,
}, },
visuals: { visuals: {
title: '', title: '',

View file

@ -17,7 +17,15 @@ export interface Page {
patch?: RequestHandler; patch?: RequestHandler;
delete?: RequestHandler; delete?: RequestHandler;
options?: RequestHandler; options?: RequestHandler;
catchAll?: RequestHandler; copy?: RequestHandler;
move?: RequestHandler;
mkcol?: RequestHandler;
mkcalendar?: RequestHandler;
lock?: RequestHandler;
unlock?: RequestHandler;
propfind?: RequestHandler;
proppatch?: RequestHandler;
report?: RequestHandler;
} }
type AccessMode = 'public' | 'user'; type AccessMode = 'public' | 'user';
@ -53,7 +61,15 @@ export default function page(
patch, patch,
delete: deleteAction, delete: deleteAction,
options, options,
catchAll, copy,
move,
mkcol,
mkcalendar,
lock,
unlock,
propfind,
proppatch,
report,
accessMode, accessMode,
}: Params, }: Params,
): Page { ): Page {
@ -64,6 +80,14 @@ export default function page(
patch: patch ? permissioned(patch, accessMode) : undefined, patch: patch ? permissioned(patch, accessMode) : undefined,
delete: deleteAction ? permissioned(deleteAction, accessMode) : undefined, delete: deleteAction ? permissioned(deleteAction, accessMode) : undefined,
options: options ? permissioned(options, accessMode) : undefined, options: options ? permissioned(options, accessMode) : undefined,
catchAll: catchAll ? permissioned(catchAll, accessMode) : undefined, copy: copy ? permissioned(copy, accessMode) : undefined,
move: move ? permissioned(move, accessMode) : undefined,
mkcol: mkcol ? permissioned(mkcol, accessMode) : undefined,
mkcalendar: mkcalendar ? permissioned(mkcalendar, accessMode) : undefined,
lock: lock ? permissioned(lock, accessMode) : undefined,
unlock: unlock ? permissioned(unlock, accessMode) : undefined,
propfind: propfind ? permissioned(propfind, accessMode) : undefined,
proppatch: proppatch ? permissioned(proppatch, accessMode) : undefined,
report: report ? permissioned(report, accessMode) : undefined,
}; };
} }

View file

@ -175,14 +175,10 @@ export interface Config {
allowPublicSharing: boolean; allowPublicSharing: boolean;
/** If true, directories can be downloaded as zip files */ /** If true, directories can be downloaded as zip files */
allowDirectoryDownloads: boolean; allowDirectoryDownloads: boolean;
/** The maximum upload size in megabytes. Overrides the core.maxRequestSizeInMegabytes setting on /dav and /api/files/upload endpoints. */
maxUploadSizeInMegabytes: number;
}; };
core: { core: {
/** The apps to show, in order of appearance in the header. The first app will be the default one shown after logging in. At least one is required. */ /** The apps to show, in order of appearance in the header. The first app will be the default one shown after logging in. At least one is required. */
enabledApps: OptionalApp[]; enabledApps: OptionalApp[];
/** The maximum request size in megabytes. */
maxRequestSizeInMegabytes: number;
}; };
visuals: { visuals: {
/** An override title of the application. Empty shows the default title. */ /** An override title of the application. Empty shows the default title. */

13
main.ts
View file

@ -1,13 +1,9 @@
import routes, { Route } from './routes.ts'; import routes, { Route } from './routes.ts';
import { startCrons } from './crons/index.ts'; import { startCrons } from './crons/index.ts';
import { Page } from './lib/page.ts'; import { Page } from './lib/page.ts';
import { AppConfig } from './lib/config.ts';
const config = await AppConfig.getConfig(); const MAX_REQUEST_SIZE_IN_MEGABYTES = 12;
const MAX_REQUEST_SIZE_IN_MEGABYTES = config.core.maxRequestSizeInMegabytes;
const MAX_UPLOAD_SIZE_IN_MEGABYTES = config.files.maxUploadSizeInMegabytes;
const MAX_REQUEST_SIZE_IN_BYTES = MAX_REQUEST_SIZE_IN_MEGABYTES * 1024 * 1024; const MAX_REQUEST_SIZE_IN_BYTES = MAX_REQUEST_SIZE_IN_MEGABYTES * 1024 * 1024;
const MAX_UPLOAD_SIZE_IN_BYTES = MAX_UPLOAD_SIZE_IN_MEGABYTES * 1024 * 1024;
function applyCorsHeadersToResponse(origin: string, response: Response) { function applyCorsHeadersToResponse(origin: string, response: Response) {
const headers = response.headers; const headers = response.headers;
@ -57,15 +53,12 @@ function handleLogging(request: Request, response: Response) {
async function handler(request: Request) { async function handler(request: Request) {
const contentLength = request.headers.get('content-length'); const contentLength = request.headers.get('content-length');
const path = new URL(request.url).pathname;
const isUploadRequest = path.startsWith('/api/files/upload') || path.startsWith('/dav'); if (contentLength && parseInt(contentLength, 10) > MAX_REQUEST_SIZE_IN_BYTES) {
const maxSizeInBytes = isUploadRequest ? MAX_UPLOAD_SIZE_IN_BYTES : MAX_REQUEST_SIZE_IN_BYTES;
if (contentLength && parseInt(contentLength, 10) > maxSizeInBytes) {
return new Response('Payload too large', { status: 413 }); return new Response('Payload too large', { status: 413 });
} }
const path = new URL(request.url).pathname;
const origin = request.headers.get('Origin') || '*'; const origin = request.headers.get('Origin') || '*';
// CORS headers for non-DAV routes // CORS headers for non-DAV routes

View file

@ -75,6 +75,14 @@ export default page({
put: get, put: get,
delete: get, delete: get,
options: get, options: get,
catchAll: get, copy: get,
move: get,
mkcol: get,
mkcalendar: get,
lock: get,
unlock: get,
propfind: get,
proppatch: get,
report: get,
accessMode: 'public', accessMode: 'public',
}); });

View file

@ -75,6 +75,13 @@ export default page({
put: get, put: get,
delete: get, delete: get,
options: get, options: get,
catchAll: get, copy: get,
move: get,
mkcol: get,
lock: get,
unlock: get,
propfind: get,
proppatch: get,
report: get,
accessMode: 'public', accessMode: 'public',
}); });

View file

@ -142,8 +142,6 @@ async function handler({ request, user, match }: RequestHandlerParams): Promise<
console.error(error); console.error(error);
} }
} }
return new Response('Not Found', { status: 404 });
} }
if (request.method === 'MKCOL') { if (request.method === 'MKCOL') {
@ -259,6 +257,12 @@ export default page({
delete: handler, delete: handler,
put: handler, put: handler,
options: handler, options: handler,
catchAll: handler, copy: handler,
move: handler,
mkcol: handler,
lock: handler,
unlock: handler,
propfind: handler,
report: handler,
accessMode: 'public', accessMode: 'public',
}); });

View file

@ -33,7 +33,14 @@ function createPageRouteHandler(id: string, pathname: string) {
patch, patch,
delete: deleteAction, delete: deleteAction,
options, options,
catchAll, copy,
move,
mkcol,
lock,
unlock,
propfind,
proppatch,
report,
} = page; } = page;
const { user, session, tokenData } = (await getDataFromRequest(request)) || {}; const { user, session, tokenData } = (await getDataFromRequest(request)) || {};
@ -141,9 +148,9 @@ function createPageRouteHandler(id: string, pathname: string) {
}); });
} }
break; break;
default: case 'COPY':
if (catchAll) { if (copy) {
return await catchAll({ return await copy({
request, request,
match, match,
user, user,
@ -151,7 +158,85 @@ function createPageRouteHandler(id: string, pathname: string) {
isRunningLocally, isRunningLocally,
}); });
} }
break;
case 'MOVE':
if (move) {
return await move({
request,
match,
user,
session: { userSession: session, tokenData },
isRunningLocally,
});
}
break;
case 'MKCOL':
if (mkcol) {
return await mkcol({
request,
match,
user,
session: { userSession: session, tokenData },
isRunningLocally,
});
}
break;
case 'LOCK':
if (lock) {
return await lock({
request,
match,
user,
session: { userSession: session, tokenData },
isRunningLocally,
});
}
break;
case 'UNLOCK':
if (unlock) {
return await unlock({
request,
match,
user,
session: { userSession: session, tokenData },
isRunningLocally,
});
}
break;
case 'PROPFIND':
if (propfind) {
return await propfind({
request,
match,
user,
session: { userSession: session, tokenData },
isRunningLocally,
});
}
break;
case 'PROPPATCH':
if (proppatch) {
return await proppatch({
request,
match,
user,
session: { userSession: session, tokenData },
isRunningLocally,
});
}
break;
case 'REPORT':
if (report) {
return await report({
request,
match,
user,
session: { userSession: session, tokenData },
isRunningLocally,
});
}
break;
default:
return new Response('Not Implemented', { status: 501 }); return new Response('Not Implemented', { status: 501 });
} }