Skip to content

Commit

Permalink
Merge branch 'develop' into server-4710-spaceAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
techsmyth authored Dec 7, 2024
2 parents 6f0516d + 2d424e5 commit d8674c0
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 3 deletions.
3 changes: 3 additions & 0 deletions alkemio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ communications:
## storage ##
# Alkemio uses multiple types of persistent storage, including SQL database, postgres database, file storage, redis.
storage:
#
enabled: ${STORAGE_ENABLED}:true
#
file:
# 20MB
max_file_size: ${STORAGE_MAX_FILE_SIZE}:20971520
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alkemio-server",
"version": "0.96.2",
"version": "0.97.0",
"description": "Alkemio server, responsible for managing the shared Alkemio platform",
"author": "Alkemio Foundation",
"private": false,
Expand Down
1 change: 1 addition & 0 deletions src/common/enums/alkemio.error.status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export enum AlkemioErrorStatus {
EXCALIDRAW_REDIS_ADAPTER_INIT = 'EXCALIDRAW_REDIS_INIT',
EXCALIDRAW_SERVER_INIT = 'EXCALIDRAW_SERVER_INIT',
UNSPECIFIED = 'UNSPECIFIED',
STORAGE_DISABLED = 'STORAGE_DISABLED',
LOCAL_STORAGE_SAVE_FAILED = 'LOCAL_STORAGE_SAVE_FAILED',
LOCAL_STORAGE_READ_FAILED = 'LOCAL_STORAGE_READ_FAILED',
LOCAL_STORAGE_DELETE_FAILED = 'LOCAL_STORAGE_DELETE_FAILED',
Expand Down
2 changes: 2 additions & 0 deletions src/common/exceptions/storage/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './local-storage/local.storage.delete.failed.exception';
export * from './local-storage/local.storage.save.failed.exception';
export * from './local-storage/local.storage.read.failed.exception';

export * from './storage.disabled.exception';
9 changes: 9 additions & 0 deletions src/common/exceptions/storage/storage.disabled.exception.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { AlkemioErrorStatus, LogContext } from '@common/enums';
import { BaseException } from '../../exceptions/base.exception';
import { ExceptionDetails } from '../../exceptions/exception.details';

export class StorageDisabledException extends BaseException {
constructor(error: string, context: LogContext, details?: ExceptionDetails) {
super(error, context, AlkemioErrorStatus.STORAGE_DISABLED, details);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ import {
import { StorageService } from '../storage.service.interface';
import { StorageServiceType } from '../storage.service.type';
import { AlkemioConfig } from '@src/types';
import { StorageDisabledException } from '@common/exceptions/storage/storage.disabled.exception';

const writeFileAsync = promisify(writeFile);
const readFileAsync = promisify(readFile);
const unlinkAsync = promisify(unlink);

@Injectable()
export class LocalStorageAdapter implements StorageService {
private readonly enabled: boolean;
private readonly storagePath: string;

constructor(private configService: ConfigService<AlkemioConfig, true>) {
this.enabled = this.configService.get('storage.enabled', { infer: true });
const pathFromConfig = this.configService.get(
'storage.local_storage.path',
{ infer: true }
Expand All @@ -36,10 +39,24 @@ export class LocalStorageAdapter implements StorageService {
}

public save(data: Buffer) {
if (!this.enabled) {
throw new StorageDisabledException(
'Storage is currently disabled',
LogContext.LOCAL_STORAGE
);
}

return this.saveFromBuffer(data);
}

public async read(fileName: string): Promise<Buffer> | never {
if (!this.enabled) {
throw new StorageDisabledException(
'Storage is currently disabled',
LogContext.LOCAL_STORAGE
);
}

const filePath = this.getFilePath(fileName);
try {
return await readFileAsync(filePath);
Expand All @@ -58,6 +75,13 @@ export class LocalStorageAdapter implements StorageService {
}

public async delete(fileName: string): Promise<void> | never {
if (!this.enabled) {
throw new StorageDisabledException(
'Storage is currently disabled',
LogContext.LOCAL_STORAGE
);
}

const filePath = this.getFilePath(fileName);

try {
Expand All @@ -77,6 +101,13 @@ export class LocalStorageAdapter implements StorageService {
}

public exists(fileName: string): boolean {
if (!this.enabled) {
throw new StorageDisabledException(
'Storage is currently disabled',
LogContext.LOCAL_STORAGE
);
}

const filePath = this.getFilePath(fileName);
return existsSync(filePath);
}
Expand Down
1 change: 1 addition & 0 deletions src/types/alkemio.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export type AlkemioConfig = {
};
};
storage: {
enabled: boolean;
file: {
max_file_size: number;
};
Expand Down

0 comments on commit d8674c0

Please sign in to comment.