Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/commands/webdav-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export default class WebDAVConfig extends Command {
required: false,
exclusive: ['https'],
}),
timeout: Flags.integer({
char: 't',
description: 'Configures the WebDAV server to use this timeout in minutes.',
required: false,
min: 0,
}),
};
static readonly enableJsonFlag = true;

Expand All @@ -54,6 +60,11 @@ export default class WebDAVConfig extends Command {
webdavConfig['protocol'] = 'https';
}

const timeout = flags['timeout'];
if (timeout) {
webdavConfig['timeoutMinutes'] = timeout;
}

await ConfigService.instance.saveWebdavConfig(webdavConfig);
const message = `On the next start, the WebDAV server will use the next config: ${JSON.stringify(webdavConfig)}`;
CLIUtils.success(this.log.bind(this), message);
Expand Down
3 changes: 3 additions & 0 deletions src/services/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class ConfigService {
static readonly WEBDAV_LOCAL_URL = 'webdav.local.internxt.com';
static readonly WEBDAV_DEFAULT_PORT = '3005';
static readonly WEBDAV_DEFAULT_PROTOCOL = 'https';
static readonly WEBDAV_DEFAULT_TIMEOUT = 0;
public static readonly instance: ConfigService = new ConfigService();

/**
Expand Down Expand Up @@ -87,11 +88,13 @@ export class ConfigService {
return {
port: configs?.port ?? ConfigService.WEBDAV_DEFAULT_PORT,
protocol: configs?.protocol ?? ConfigService.WEBDAV_DEFAULT_PROTOCOL,
timeoutMinutes: configs?.timeoutMinutes ?? ConfigService.WEBDAV_DEFAULT_TIMEOUT,
};
} catch {
return {
port: ConfigService.WEBDAV_DEFAULT_PORT,
protocol: ConfigService.WEBDAV_DEFAULT_PROTOCOL,
timeoutMinutes: ConfigService.WEBDAV_DEFAULT_TIMEOUT,
};
}
};
Expand Down
1 change: 1 addition & 0 deletions src/types/command.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface LoginCredentials {
export interface WebdavConfig {
port: string;
protocol: 'http' | 'https';
timeoutMinutes: number;
}

export class NotValidEmailError extends Error {
Expand Down
4 changes: 2 additions & 2 deletions src/webdav/webdav-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ export class WebDavServer {
server = https.createServer(httpsCerts, this.app);
}

// Allow long uploads/downloads from WebDAV clients (up to 15 minutes before closing connection):
server.requestTimeout = 15 * 60 * 1000;
// Allow long uploads/downloads from WebDAV clients:
server.requestTimeout = configs.timeoutMinutes * 60 * 1000;

server.listen(configs.port, () => {
webdavLogger.info(
Expand Down
4 changes: 4 additions & 0 deletions test/services/config.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ describe('Config service', () => {
const webdavConfig: WebdavConfig = {
port: String(crypto.randomInt(65000)),
protocol: 'https',
timeoutMinutes: crypto.randomInt(100),
};
const stringConfig = JSON.stringify(webdavConfig);

Expand All @@ -134,6 +135,7 @@ describe('Config service', () => {
const webdavConfig: WebdavConfig = {
port: String(crypto.randomInt(65000)),
protocol: 'http',
timeoutMinutes: crypto.randomInt(100),
};
const stringConfig = JSON.stringify(webdavConfig);

Expand All @@ -148,6 +150,7 @@ describe('Config service', () => {
const defaultWebdavConfig: WebdavConfig = {
port: ConfigService.WEBDAV_DEFAULT_PORT,
protocol: ConfigService.WEBDAV_DEFAULT_PROTOCOL,
timeoutMinutes: ConfigService.WEBDAV_DEFAULT_TIMEOUT,
};

const fsStub = vi.spyOn(fs, 'readFile').mockResolvedValue('');
Expand All @@ -161,6 +164,7 @@ describe('Config service', () => {
const defaultWebdavConfig: WebdavConfig = {
port: ConfigService.WEBDAV_DEFAULT_PORT,
protocol: ConfigService.WEBDAV_DEFAULT_PROTOCOL,
timeoutMinutes: ConfigService.WEBDAV_DEFAULT_TIMEOUT,
};

const fsStub = vi.spyOn(fs, 'readFile').mockRejectedValue(new Error());
Expand Down
Loading