mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
refactor(server): flatten infra folders (#2120)
* refactor: flatten infra folders * fix: database migrations * fix: test related import * fix: github actions workflow * chore: rename schemas to typesense-schemas
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
export * from './communication.gateway';
|
||||
export * from './communication.repository';
|
||||
@@ -1,5 +1,5 @@
|
||||
import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions';
|
||||
|
||||
const url = process.env.DB_URL;
|
||||
const urlOrParts = url
|
||||
@@ -14,12 +14,13 @@ const urlOrParts = url
|
||||
|
||||
export const databaseConfig: PostgresConnectionOptions = {
|
||||
type: 'postgres',
|
||||
entities: [__dirname + '/../**/*.entity.{js,ts}'],
|
||||
entities: [__dirname + '/entities/*.entity.{js,ts}'],
|
||||
synchronize: false,
|
||||
migrations: [__dirname + '/../migrations/*.{js,ts}'],
|
||||
migrations: [__dirname + '/migrations/*.{js,ts}'],
|
||||
migrationsRun: true,
|
||||
connectTimeoutMS: 10000, // 10 seconds
|
||||
...urlOrParts,
|
||||
};
|
||||
|
||||
// this export is used by TypeORM commands in package.json#scripts
|
||||
export const dataSource = new DataSource(databaseConfig);
|
||||
@@ -1 +0,0 @@
|
||||
export * from './database.config';
|
||||
@@ -1,11 +0,0 @@
|
||||
export * from './album.entity';
|
||||
export * from './api-key.entity';
|
||||
export * from './asset.entity';
|
||||
export * from './device-info.entity';
|
||||
export * from './exif.entity';
|
||||
export * from './smart-info.entity';
|
||||
export * from './system-config.entity';
|
||||
export * from './tag.entity';
|
||||
export * from './user.entity';
|
||||
export * from './user-token.entity';
|
||||
export * from './shared-link.entity';
|
||||
@@ -1,3 +0,0 @@
|
||||
export * from './config';
|
||||
export * from './entities';
|
||||
export * from './repository';
|
||||
33
server/libs/infra/src/entities/index.ts
Normal file
33
server/libs/infra/src/entities/index.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { AlbumEntity } from './album.entity';
|
||||
import { APIKeyEntity } from './api-key.entity';
|
||||
import { AssetEntity } from './asset.entity';
|
||||
import { DeviceInfoEntity } from './device-info.entity';
|
||||
import { SharedLinkEntity } from './shared-link.entity';
|
||||
import { SmartInfoEntity } from './smart-info.entity';
|
||||
import { SystemConfigEntity } from './system-config.entity';
|
||||
import { UserTokenEntity } from './user-token.entity';
|
||||
import { UserEntity } from './user.entity';
|
||||
|
||||
export * from './album.entity';
|
||||
export * from './api-key.entity';
|
||||
export * from './asset.entity';
|
||||
export * from './device-info.entity';
|
||||
export * from './exif.entity';
|
||||
export * from './shared-link.entity';
|
||||
export * from './smart-info.entity';
|
||||
export * from './system-config.entity';
|
||||
export * from './tag.entity';
|
||||
export * from './user-token.entity';
|
||||
export * from './user.entity';
|
||||
|
||||
export const databaseEntities = [
|
||||
AssetEntity,
|
||||
AlbumEntity,
|
||||
APIKeyEntity,
|
||||
DeviceInfoEntity,
|
||||
UserEntity,
|
||||
SharedLinkEntity,
|
||||
SmartInfoEntity,
|
||||
SystemConfigEntity,
|
||||
UserTokenEntity,
|
||||
];
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from './db';
|
||||
export * from './database.config';
|
||||
export * from './infra.config';
|
||||
export * from './infra.module';
|
||||
|
||||
35
server/libs/infra/src/infra.config.ts
Normal file
35
server/libs/infra/src/infra.config.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { BullModuleOptions } from '@nestjs/bull';
|
||||
import { ConfigurationOptions } from 'typesense/lib/Typesense/Configuration';
|
||||
import { QueueName } from '../../domain/src';
|
||||
|
||||
export const bullConfig: BullModuleOptions = {
|
||||
prefix: 'immich_bull',
|
||||
redis: {
|
||||
host: process.env.REDIS_HOSTNAME || 'immich_redis',
|
||||
port: parseInt(process.env.REDIS_PORT || '6379'),
|
||||
db: parseInt(process.env.REDIS_DBINDEX || '0'),
|
||||
password: process.env.REDIS_PASSWORD || undefined,
|
||||
path: process.env.REDIS_SOCKET || undefined,
|
||||
},
|
||||
defaultJobOptions: {
|
||||
attempts: 3,
|
||||
removeOnComplete: true,
|
||||
removeOnFail: false,
|
||||
},
|
||||
};
|
||||
|
||||
export const bullQueues: BullModuleOptions[] = Object.values(QueueName).map((name) => ({ name }));
|
||||
|
||||
export const typesenseConfig: ConfigurationOptions = {
|
||||
nodes: [
|
||||
{
|
||||
host: process.env.TYPESENSE_HOST || 'typesense',
|
||||
port: Number(process.env.TYPESENSE_PORT) || 8108,
|
||||
protocol: process.env.TYPESENSE_PROTOCOL || 'http',
|
||||
},
|
||||
],
|
||||
apiKey: process.env.TYPESENSE_API_KEY as string,
|
||||
numRetries: 15,
|
||||
retryIntervalSeconds: 4,
|
||||
connectionTimeoutSeconds: 10,
|
||||
};
|
||||
@@ -16,40 +16,33 @@ import {
|
||||
ISystemConfigRepository,
|
||||
IUserRepository,
|
||||
IUserTokenRepository,
|
||||
QueueName,
|
||||
} from '@app/domain';
|
||||
import { BullModule } from '@nestjs/bull';
|
||||
import { Global, Module, Provider } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { CryptoRepository } from './auth/crypto.repository';
|
||||
import { CommunicationGateway, CommunicationRepository } from './communication';
|
||||
import { CommunicationGateway } from './communication.gateway';
|
||||
import { databaseConfig } from './database.config';
|
||||
import { databaseEntities } from './entities';
|
||||
import { bullConfig, bullQueues } from './infra.config';
|
||||
import {
|
||||
AlbumEntity,
|
||||
AlbumRepository,
|
||||
APIKeyEntity,
|
||||
APIKeyRepository,
|
||||
AssetEntity,
|
||||
AssetRepository,
|
||||
databaseConfig,
|
||||
DeviceInfoEntity,
|
||||
CommunicationRepository,
|
||||
CryptoRepository,
|
||||
DeviceInfoRepository,
|
||||
SharedLinkEntity,
|
||||
FilesystemProvider,
|
||||
JobRepository,
|
||||
MachineLearningRepository,
|
||||
MediaRepository,
|
||||
SharedLinkRepository,
|
||||
SmartInfoEntity,
|
||||
SmartInfoRepository,
|
||||
SystemConfigEntity,
|
||||
SystemConfigRepository,
|
||||
UserEntity,
|
||||
TypesenseRepository,
|
||||
UserRepository,
|
||||
UserTokenEntity,
|
||||
UserTokenRepository,
|
||||
} from './db';
|
||||
import { JobRepository } from './job';
|
||||
import { MachineLearningRepository } from './machine-learning';
|
||||
import { MediaRepository } from './media';
|
||||
import { TypesenseRepository } from './search';
|
||||
import { FilesystemProvider } from './storage';
|
||||
} from './repositories';
|
||||
|
||||
const providers: Provider[] = [
|
||||
{ provide: IAlbumRepository, useClass: AlbumRepository },
|
||||
@@ -74,38 +67,10 @@ const providers: Provider[] = [
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(immichAppConfig),
|
||||
|
||||
TypeOrmModule.forRoot(databaseConfig),
|
||||
TypeOrmModule.forFeature([
|
||||
AssetEntity,
|
||||
AlbumEntity,
|
||||
APIKeyEntity,
|
||||
DeviceInfoEntity,
|
||||
UserEntity,
|
||||
SharedLinkEntity,
|
||||
SmartInfoEntity,
|
||||
SystemConfigEntity,
|
||||
UserTokenEntity,
|
||||
]),
|
||||
|
||||
BullModule.forRootAsync({
|
||||
useFactory: async () => ({
|
||||
prefix: 'immich_bull',
|
||||
redis: {
|
||||
host: process.env.REDIS_HOSTNAME || 'immich_redis',
|
||||
port: parseInt(process.env.REDIS_PORT || '6379'),
|
||||
db: parseInt(process.env.REDIS_DBINDEX || '0'),
|
||||
password: process.env.REDIS_PASSWORD || undefined,
|
||||
path: process.env.REDIS_SOCKET || undefined,
|
||||
},
|
||||
defaultJobOptions: {
|
||||
attempts: 3,
|
||||
removeOnComplete: true,
|
||||
removeOnFail: false,
|
||||
},
|
||||
}),
|
||||
}),
|
||||
BullModule.registerQueue(...Object.values(QueueName).map((name) => ({ name }))),
|
||||
TypeOrmModule.forFeature(databaseEntities),
|
||||
BullModule.forRoot(bullConfig),
|
||||
BullModule.registerQueue(...bullQueues),
|
||||
],
|
||||
providers: [...providers, CommunicationGateway],
|
||||
exports: [...providers, BullModule],
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export * from './job.repository';
|
||||
@@ -1 +0,0 @@
|
||||
export * from './machine-learning.repository';
|
||||
@@ -1 +0,0 @@
|
||||
export * from './media.repository';
|
||||
@@ -2,7 +2,7 @@ import { AlbumAssetCount, IAlbumRepository } from '@app/domain';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { In, IsNull, Not, Repository } from 'typeorm';
|
||||
import { dataSource } from '../config';
|
||||
import { dataSource } from '../database.config';
|
||||
import { AlbumEntity } from '../entities';
|
||||
|
||||
@Injectable()
|
||||
@@ -1,6 +1,6 @@
|
||||
import { CommunicationEvent } from '@app/domain';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CommunicationGateway } from './communication.gateway';
|
||||
import { CommunicationGateway } from '../communication.gateway';
|
||||
|
||||
@Injectable()
|
||||
export class CommunicationRepository {
|
||||
@@ -1,9 +1,16 @@
|
||||
export * from './album.repository';
|
||||
export * from './api-key.repository';
|
||||
export * from './asset.repository';
|
||||
export * from './communication.repository';
|
||||
export * from './crypto.repository';
|
||||
export * from './device-info.repository';
|
||||
export * from './filesystem.provider';
|
||||
export * from './job.repository';
|
||||
export * from './machine-learning.repository';
|
||||
export * from './media.repository';
|
||||
export * from './shared-link.repository';
|
||||
export * from './smart-info.repository';
|
||||
export * from './system-config.repository';
|
||||
export * from './typesense.repository';
|
||||
export * from './user-token.repository';
|
||||
export * from './user.repository';
|
||||
@@ -12,9 +12,9 @@ import { catchError, filter, firstValueFrom, from, map, mergeMap, of, toArray }
|
||||
import { Client } from 'typesense';
|
||||
import { CollectionCreateSchema } from 'typesense/lib/Typesense/Collections';
|
||||
import { DocumentSchema, SearchResponse } from 'typesense/lib/Typesense/Documents';
|
||||
import { AlbumEntity, AssetEntity } from '../db';
|
||||
import { albumSchema } from './schemas/album.schema';
|
||||
import { assetSchema } from './schemas/asset.schema';
|
||||
import { AlbumEntity, AssetEntity } from '../entities';
|
||||
import { typesenseConfig } from '../infra.config';
|
||||
import { albumSchema, assetSchema } from '../typesense-schemas';
|
||||
|
||||
function removeNil<T extends Dictionary<any>>(item: T): T {
|
||||
_.forOwn(item, (value, key) => {
|
||||
@@ -51,24 +51,11 @@ export class TypesenseRepository implements ISearchRepository {
|
||||
}
|
||||
|
||||
constructor() {
|
||||
const apiKey = process.env.TYPESENSE_API_KEY;
|
||||
if (!apiKey) {
|
||||
if (!typesenseConfig.apiKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._client = new Client({
|
||||
nodes: [
|
||||
{
|
||||
host: process.env.TYPESENSE_HOST || 'typesense',
|
||||
port: Number(process.env.TYPESENSE_PORT) || 8108,
|
||||
protocol: process.env.TYPESENSE_PROTOCOL || 'http',
|
||||
},
|
||||
],
|
||||
apiKey,
|
||||
numRetries: 15,
|
||||
retryIntervalSeconds: 4,
|
||||
connectionTimeoutSeconds: 10,
|
||||
});
|
||||
this._client = new Client(typesenseConfig);
|
||||
}
|
||||
|
||||
async setup(): Promise<void> {
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { UserTokenEntity } from '../entities/user-token.entity';
|
||||
import { UserTokenEntity } from '../entities';
|
||||
import { IUserTokenRepository } from '@app/domain/user-token';
|
||||
|
||||
@Injectable()
|
||||
@@ -1,8 +1,8 @@
|
||||
import { UserEntity } from '../entities';
|
||||
import { IUserRepository, UserListFilter, UserStatsQueryResponse } from '@app/domain';
|
||||
import { Injectable, InternalServerErrorException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { IsNull, Not, Repository } from 'typeorm';
|
||||
import { UserEntity } from '../entities';
|
||||
|
||||
@Injectable()
|
||||
export class UserRepository implements IUserRepository {
|
||||
@@ -1 +0,0 @@
|
||||
export * from './typesense.repository';
|
||||
@@ -1 +0,0 @@
|
||||
export * from './filesystem.provider';
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user