From caba46270347ac08b0fc513dea18f49d9bc57bfe Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Sun, 28 May 2023 21:48:07 -0400 Subject: [PATCH] fix(server): library folder missing on new install (#2597) --- server/apps/immich/src/main.ts | 3 +++ server/libs/domain/src/storage/storage.service.spec.ts | 7 +++++++ server/libs/domain/src/storage/storage.service.ts | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/server/apps/immich/src/main.ts b/server/apps/immich/src/main.ts index 678c9498fb..ccb97c4d9e 100644 --- a/server/apps/immich/src/main.ts +++ b/server/apps/immich/src/main.ts @@ -6,6 +6,7 @@ import { MACHINE_LEARNING_ENABLED, SearchService, SERVER_VERSION, + StorageService, } from '@app/domain'; import { RedisIoAdapter } from '@app/infra'; import { Logger } from '@nestjs/common'; @@ -72,6 +73,8 @@ async function bootstrap() { customSiteTitle: 'Immich API Documentation', }); + app.get(StorageService).init(); + await app.listen(serverPort, () => { if (process.env.NODE_ENV == 'development') { // Generate API Documentation only in development mode diff --git a/server/libs/domain/src/storage/storage.service.spec.ts b/server/libs/domain/src/storage/storage.service.spec.ts index 7a2c58c5dc..9b180cafc9 100644 --- a/server/libs/domain/src/storage/storage.service.spec.ts +++ b/server/libs/domain/src/storage/storage.service.spec.ts @@ -15,6 +15,13 @@ describe(StorageService.name, () => { expect(sut).toBeDefined(); }); + describe('init', () => { + it('should create the library folder on initialization', () => { + sut.init(); + expect(storageMock.mkdirSync).toHaveBeenCalledWith('upload/library'); + }); + }); + describe('handleDeleteFiles', () => { it('should handle null values', async () => { await sut.handleDeleteFiles({ files: [undefined, null] }); diff --git a/server/libs/domain/src/storage/storage.service.ts b/server/libs/domain/src/storage/storage.service.ts index fea0c12081..23e8aa11e5 100644 --- a/server/libs/domain/src/storage/storage.service.ts +++ b/server/libs/domain/src/storage/storage.service.ts @@ -1,13 +1,20 @@ import { Inject, Injectable, Logger } from '@nestjs/common'; import { IDeleteFilesJob } from '../job'; +import { StorageCore, StorageFolder } from './storage.core'; import { IStorageRepository } from './storage.repository'; @Injectable() export class StorageService { private logger = new Logger(StorageService.name); + private storageCore = new StorageCore(); constructor(@Inject(IStorageRepository) private storageRepository: IStorageRepository) {} + init() { + const libraryBase = this.storageCore.getBaseFolder(StorageFolder.LIBRARY); + this.storageRepository.mkdirSync(libraryBase); + } + async handleDeleteFiles(job: IDeleteFilesJob) { const { files } = job;