mirror of
https://github.com/immich-app/immich.git
synced 2025-01-02 12:48:35 +02:00
chore: move apps and test utils (#8129)
This commit is contained in:
parent
c1402eee8e
commit
907eb869bc
@ -13,7 +13,7 @@ import {
|
||||
restoreTempFolder,
|
||||
testApp,
|
||||
waitForEvent,
|
||||
} from 'src/test-utils/utils';
|
||||
} from 'test/utils';
|
||||
|
||||
describe(`Library watcher (e2e)`, () => {
|
||||
let server: any;
|
||||
|
@ -3,10 +3,10 @@ import fs from 'node:fs';
|
||||
import { LibraryController } from 'src/controllers/library.controller';
|
||||
import { LoginResponseDto } from 'src/domain/auth/auth.dto';
|
||||
import { LibraryType } from 'src/entities/library.entity';
|
||||
import { IMMICH_TEST_ASSET_PATH, IMMICH_TEST_ASSET_TEMP_PATH, restoreTempFolder, testApp } from 'src/test-utils/utils';
|
||||
import request from 'supertest';
|
||||
import { errorStub } from 'test/fixtures/error.stub';
|
||||
import { uuidStub } from 'test/fixtures/uuid.stub';
|
||||
import { IMMICH_TEST_ASSET_PATH, IMMICH_TEST_ASSET_TEMP_PATH, restoreTempFolder, testApp } from 'test/utils';
|
||||
import { utimes } from 'utimes';
|
||||
|
||||
describe(`${LibraryController.name} (e2e)`, () => {
|
||||
|
@ -4,10 +4,10 @@ import { json } from 'body-parser';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import { existsSync } from 'node:fs';
|
||||
import sirv from 'sirv';
|
||||
import { ApiModule } from 'src/apps/api.module';
|
||||
import { ApiService } from 'src/apps/api.service';
|
||||
import { excludePaths } from 'src/config';
|
||||
import { WEB_ROOT, envName, isDev, serverVersion } from 'src/domain/domain.constant';
|
||||
import { AppModule } from 'src/immich/app.module';
|
||||
import { AppService } from 'src/immich/app.service';
|
||||
import { useSwagger } from 'src/immich/app.utils';
|
||||
import { otelSDK } from 'src/infra/instrumentation';
|
||||
import { ImmichLogger } from 'src/infra/logger';
|
||||
@ -16,9 +16,9 @@ import { WebSocketAdapter } from 'src/infra/websocket.adapter';
|
||||
const logger = new ImmichLogger('ImmichServer');
|
||||
const port = Number(process.env.SERVER_PORT) || 3001;
|
||||
|
||||
export async function bootstrap() {
|
||||
export async function bootstrapApi() {
|
||||
otelSDK.start();
|
||||
const app = await NestFactory.create<NestExpressApplication>(AppModule, { bufferLogs: true });
|
||||
const app = await NestFactory.create<NestExpressApplication>(ApiModule, { bufferLogs: true });
|
||||
|
||||
app.useLogger(app.get(ImmichLogger));
|
||||
app.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal']);
|
||||
@ -48,7 +48,7 @@ export async function bootstrap() {
|
||||
}),
|
||||
);
|
||||
}
|
||||
app.use(app.get(AppService).ssr(excludePaths));
|
||||
app.use(app.get(ApiService).ssr(excludePaths));
|
||||
|
||||
const server = await app.listen(port);
|
||||
server.requestTimeout = 30 * 60 * 1000;
|
@ -2,6 +2,7 @@ import { Module, OnModuleInit, ValidationPipe } from '@nestjs/common';
|
||||
import { APP_GUARD, APP_INTERCEPTOR, APP_PIPE } from '@nestjs/core';
|
||||
import { ScheduleModule } from '@nestjs/schedule';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { ApiService } from 'src/apps/api.service';
|
||||
import { ActivityController } from 'src/controllers/activity.controller';
|
||||
import { AlbumController } from 'src/controllers/album.controller';
|
||||
import { APIKeyController } from 'src/controllers/api-key.controller';
|
||||
@ -29,7 +30,6 @@ import { ExifEntity } from 'src/entities/exif.entity';
|
||||
import { AssetRepositoryV1, IAssetRepositoryV1 } from 'src/immich/api-v1/asset/asset-repository';
|
||||
import { AssetController as AssetControllerV1 } from 'src/immich/api-v1/asset/asset.controller';
|
||||
import { AssetService as AssetServiceV1 } from 'src/immich/api-v1/asset/asset.service';
|
||||
import { AppService } from 'src/immich/app.service';
|
||||
import { InfraModule } from 'src/infra/infra.module';
|
||||
import { AuthGuard } from 'src/middleware/auth.guard';
|
||||
import { ErrorInterceptor } from 'src/middleware/error.interceptor';
|
||||
@ -73,13 +73,13 @@ import { FileUploadInterceptor } from 'src/middleware/file-upload.interceptor';
|
||||
{ provide: APP_INTERCEPTOR, useClass: ErrorInterceptor },
|
||||
{ provide: APP_GUARD, useClass: AuthGuard },
|
||||
{ provide: IAssetRepositoryV1, useClass: AssetRepositoryV1 },
|
||||
AppService,
|
||||
ApiService,
|
||||
AssetServiceV1,
|
||||
FileUploadInterceptor,
|
||||
],
|
||||
})
|
||||
export class AppModule implements OnModuleInit {
|
||||
constructor(private appService: AppService) {}
|
||||
export class ApiModule implements OnModuleInit {
|
||||
constructor(private appService: ApiService) {}
|
||||
|
||||
async onModuleInit() {
|
||||
await this.appService.init();
|
@ -35,8 +35,8 @@ const render = (index: string, meta: OpenGraphTags) => {
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
private logger = new ImmichLogger(AppService.name);
|
||||
export class ApiService {
|
||||
private logger = new ImmichLogger(ApiService.name);
|
||||
|
||||
constructor(
|
||||
private authService: AuthService,
|
8
server/src/apps/immich-admin.main.ts
Executable file
8
server/src/apps/immich-admin.main.ts
Executable file
@ -0,0 +1,8 @@
|
||||
import { CommandFactory } from 'nest-commander';
|
||||
import { ImmichAdminModule } from 'src/apps/immich-admin.module';
|
||||
import { LogLevel } from 'src/entities/system-config.entity';
|
||||
|
||||
export async function bootstrapImmichAdmin() {
|
||||
process.env.LOG_LEVEL = LogLevel.WARN;
|
||||
await CommandFactory.run(ImmichAdminModule);
|
||||
}
|
@ -18,4 +18,4 @@ import { InfraModule } from 'src/infra/infra.module';
|
||||
ListUsersCommand,
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
export class ImmichAdminModule {}
|
@ -1,14 +1,14 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { MicroservicesModule } from 'src/apps/microservices.module';
|
||||
import { envName, serverVersion } from 'src/domain/domain.constant';
|
||||
import { otelSDK } from 'src/infra/instrumentation';
|
||||
import { ImmichLogger } from 'src/infra/logger';
|
||||
import { WebSocketAdapter } from 'src/infra/websocket.adapter';
|
||||
import { MicroservicesModule } from 'src/microservices/microservices.module';
|
||||
|
||||
const logger = new ImmichLogger('ImmichMicroservice');
|
||||
const port = Number(process.env.MICROSERVICES_PORT) || 3002;
|
||||
|
||||
export async function bootstrap() {
|
||||
export async function bootstrapMicroservices() {
|
||||
otelSDK.start();
|
||||
const app = await NestFactory.create(MicroservicesModule, { bufferLogs: true });
|
||||
app.useLogger(app.get(ImmichLogger));
|
@ -1,14 +1,14 @@
|
||||
import { Module, OnModuleInit } from '@nestjs/common';
|
||||
import { MicroservicesService } from 'src/apps/microservices.service';
|
||||
import { DomainModule } from 'src/domain/domain.module';
|
||||
import { InfraModule } from 'src/infra/infra.module';
|
||||
import { AppService } from 'src/microservices/app.service';
|
||||
|
||||
@Module({
|
||||
imports: [InfraModule, DomainModule],
|
||||
providers: [AppService],
|
||||
providers: [MicroservicesService],
|
||||
})
|
||||
export class MicroservicesModule implements OnModuleInit {
|
||||
constructor(private appService: AppService) {}
|
||||
constructor(private appService: MicroservicesService) {}
|
||||
|
||||
async onModuleInit() {
|
||||
await this.appService.init();
|
@ -17,7 +17,7 @@ import { UserService } from 'src/domain/user/user.service';
|
||||
import { otelSDK } from 'src/infra/instrumentation';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
export class MicroservicesService {
|
||||
constructor(
|
||||
private auditService: AuditService,
|
||||
private assetService: AssetService,
|
@ -1,8 +0,0 @@
|
||||
import { CommandFactory } from 'nest-commander';
|
||||
import { LogLevel } from 'src/entities/system-config.entity';
|
||||
import { AppModule } from 'src/immich-admin/app.module';
|
||||
|
||||
export async function bootstrap() {
|
||||
process.env.LOG_LEVEL = LogLevel.WARN;
|
||||
await CommandFactory.run(AppModule);
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import { bootstrap as admin } from 'src/immich-admin/main';
|
||||
import { bootstrap as server } from 'src/immich/main';
|
||||
import { bootstrap as microservices } from 'src/microservices/main';
|
||||
import { bootstrapApi } from 'src/apps/api.main';
|
||||
import { bootstrapImmichAdmin } from 'src/apps/immich-admin.main';
|
||||
import { bootstrapMicroservices } from 'src/apps/microservices.main';
|
||||
|
||||
const immichApp = process.argv[2] || process.env.IMMICH_APP;
|
||||
|
||||
@ -12,15 +12,15 @@ function bootstrap() {
|
||||
switch (immichApp) {
|
||||
case 'immich': {
|
||||
process.title = 'immich_server';
|
||||
return server();
|
||||
return bootstrapApi();
|
||||
}
|
||||
case 'microservices': {
|
||||
process.title = 'immich_microservices';
|
||||
return microservices();
|
||||
return bootstrapMicroservices();
|
||||
}
|
||||
case 'immich-admin': {
|
||||
process.title = 'immich_admin_cli';
|
||||
return admin();
|
||||
return bootstrapImmichAdmin();
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Invalid app name: ${immichApp}. Expected one of immich|microservices|cli`);
|
||||
|
@ -6,15 +6,15 @@ import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { EventEmitter } from 'node:stream';
|
||||
import { Server } from 'node:tls';
|
||||
import { ApiModule } from 'src/apps/api.module';
|
||||
import { ApiService } from 'src/apps/api.service';
|
||||
import { MicroservicesService } from 'src/apps/microservices.service';
|
||||
import { QueueName } from 'src/domain/job/job.constants';
|
||||
import { AppModule } from 'src/immich/app.module';
|
||||
import { AppService } from 'src/immich/app.service';
|
||||
import { dataSource } from 'src/infra/database.config';
|
||||
import { InfraModule, InfraTestModule } from 'src/infra/infra.module';
|
||||
import { IJobRepository, JobItem, JobItemHandler } from 'src/interfaces/job.repository';
|
||||
import { IMediaRepository } from 'src/interfaces/media.repository';
|
||||
import { StorageEventType } from 'src/interfaces/storage.repository';
|
||||
import { AppService as MicroAppService } from 'src/microservices/app.service';
|
||||
import { MediaRepository } from 'src/repositories/media.repository';
|
||||
import { EntityTarget, ObjectLiteral } from 'typeorm';
|
||||
|
||||
@ -106,8 +106,8 @@ let app: INestApplication;
|
||||
export const testApp = {
|
||||
create: async (): Promise<INestApplication> => {
|
||||
const moduleFixture = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
providers: [AppService, MicroAppService],
|
||||
imports: [ApiModule],
|
||||
providers: [ApiService, MicroservicesService],
|
||||
})
|
||||
.overrideModule(InfraModule)
|
||||
.useModule(InfraTestModule)
|
||||
@ -120,8 +120,8 @@ export const testApp = {
|
||||
app = await moduleFixture.createNestApplication().init();
|
||||
await app.listen(0);
|
||||
await db.reset();
|
||||
await app.get(AppService).init();
|
||||
await app.get(MicroAppService).init();
|
||||
await app.get(ApiService).init();
|
||||
await app.get(MicroservicesService).init();
|
||||
|
||||
const port = app.getHttpServer().address().port;
|
||||
const protocol = app instanceof Server ? 'https' : 'http';
|
||||
@ -135,7 +135,7 @@ export const testApp = {
|
||||
get: (member: any) => app.get(member),
|
||||
teardown: async () => {
|
||||
if (app) {
|
||||
await app.get(MicroAppService).teardown();
|
||||
await app.get(MicroservicesService).teardown();
|
||||
await app.close();
|
||||
}
|
||||
await db.disconnect();
|
Loading…
Reference in New Issue
Block a user