summaryrefslogtreecommitdiff
path: root/packages/backend/src
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2024-11-28 19:56:26 -0500
committerHazelnoot <acomputerdog@gmail.com>2024-11-29 13:00:51 -0500
commit3d3cf5bd7aa19aaf245aa1fe426fe39f2e7c3436 (patch)
treeb12754a19561ba83f1ae63221044adbb384cb4ee /packages/backend/src
parentremove unused import from InternalStorageService (diff)
downloadsharkey-3d3cf5bd7aa19aaf245aa1fe426fe39f2e7c3436.tar.gz
sharkey-3d3cf5bd7aa19aaf245aa1fe426fe39f2e7c3436.tar.bz2
sharkey-3d3cf5bd7aa19aaf245aa1fe426fe39f2e7c3436.zip
add option `filePermissionBits` to override permissions on locally-stored files
This is useful for custom deployments, such as using a reverse proxy to serve static files directly
Diffstat (limited to 'packages/backend/src')
-rw-r--r--packages/backend/src/config.ts10
-rw-r--r--packages/backend/src/core/InternalStorageService.ts12
2 files changed, 18 insertions, 4 deletions
diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts
index 3dc49c7eb6..9cac058d96 100644
--- a/packages/backend/src/config.ts
+++ b/packages/backend/src/config.ts
@@ -115,6 +115,7 @@ type Source = {
};
pidFile: string;
+ filePermissionBits?: string;
};
export type Config = {
@@ -212,6 +213,7 @@ export type Config = {
} | undefined;
pidFile: string;
+ filePermissionBits?: string;
};
const _filename = fileURLToPath(import.meta.url);
@@ -347,6 +349,7 @@ export function loadConfig(): Config {
deactivateAntennaThreshold: config.deactivateAntennaThreshold ?? (1000 * 60 * 60 * 24 * 7),
import: config.import,
pidFile: config.pidFile,
+ filePermissionBits: config.filePermissionBits,
};
}
@@ -452,7 +455,10 @@ function applyEnvOverrides(config: Source) {
}
}
- const alwaysStrings = { 'chmodSocket': true } as { [key: string]: boolean };
+ const alwaysStrings: { [key in string]?: boolean } = {
+ 'chmodSocket': true,
+ 'filePermissionBits': true,
+ };
function _assign(path: (string | number)[], lastStep: string | number, value: string) {
let thisConfig = config as any;
@@ -490,7 +496,7 @@ function applyEnvOverrides(config: Source) {
_apply_top(['sentryForBackend', 'enableNodeProfiling']);
_apply_top([['clusterLimit', 'deliverJobConcurrency', 'inboxJobConcurrency', 'relashionshipJobConcurrency', 'deliverJobPerSec', 'inboxJobPerSec', 'relashionshipJobPerSec', 'deliverJobMaxAttempts', 'inboxJobMaxAttempts']]);
_apply_top([['outgoingAddress', 'outgoingAddressFamily', 'proxy', 'proxySmtp', 'mediaProxy', 'proxyRemoteFiles', 'videoThumbnailGenerator']]);
- _apply_top([['maxFileSize', 'maxNoteLength', 'maxRemoteNoteLength', 'maxAltTextLength', 'maxRemoteAltTextLength', 'pidFile']]);
+ _apply_top([['maxFileSize', 'maxNoteLength', 'maxRemoteNoteLength', 'maxAltTextLength', 'maxRemoteAltTextLength', 'pidFile', 'filePermissionBits']]);
_apply_top(['import', ['downloadTimeout', 'maxFileSize']]);
_apply_top([['signToActivityPubGet', 'checkActivityPubGetSignature']]);
}
diff --git a/packages/backend/src/core/InternalStorageService.ts b/packages/backend/src/core/InternalStorageService.ts
index 5b179baf41..b00c5796d2 100644
--- a/packages/backend/src/core/InternalStorageService.ts
+++ b/packages/backend/src/core/InternalStorageService.ts
@@ -4,7 +4,7 @@
*/
import * as fs from 'node:fs';
-import { copyFile, unlink, writeFile } from 'node:fs/promises';
+import { copyFile, unlink, writeFile, chmod } from 'node:fs/promises';
import * as Path from 'node:path';
import { fileURLToPath } from 'node:url';
import { dirname } from 'node:path';
@@ -41,12 +41,20 @@ export class InternalStorageService {
@bindThis
public async saveFromPath(key: string, srcPath: string): Promise<string> {
await copyFile(srcPath, this.resolvePath(key));
- return `${this.config.url}/files/${key}`;
+ return await this.finalizeSavedFile(key);
}
@bindThis
public async saveFromBuffer(key: string, data: Buffer): Promise<string> {
await writeFile(this.resolvePath(key), data);
+ return await this.finalizeSavedFile(key);
+ }
+
+ private async finalizeSavedFile(key: string): Promise<string> {
+ if (this.config.filePermissionBits) {
+ const path = this.resolvePath(key);
+ await chmod(path, this.config.filePermissionBits);
+ }
return `${this.config.url}/files/${key}`;
}