mirror of
https://github.com/immich-app/immich.git
synced 2024-11-27 09:21:05 +02:00
refactor(server): move constant into common package (#522)
* refactor(server): move constant into common package * refactor(server): re-arrange import statement in microservice module * refactor(server): move app.config into common package * fix(server): e2e testing
This commit is contained in:
parent
0efcc99f3e
commit
3b55cdc0be
@ -1,7 +1,7 @@
|
|||||||
|
import { APP_UPLOAD_LOCATION } from '@app/common/constants';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { ServerInfoResponseDto } from './response-dto/server-info-response.dto';
|
import { ServerInfoResponseDto } from './response-dto/server-info-response.dto';
|
||||||
import diskusage from 'diskusage';
|
import diskusage from 'diskusage';
|
||||||
import { APP_UPLOAD_LOCATION } from '../../constants/upload_location.constant';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ServerInfoService {
|
export class ServerInfoService {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { immichAppConfig } from '@app/common/config';
|
||||||
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
|
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
|
||||||
import { UserModule } from './api-v1/user/user.module';
|
import { UserModule } from './api-v1/user/user.module';
|
||||||
import { AssetModule } from './api-v1/asset/asset.module';
|
import { AssetModule } from './api-v1/asset/asset.module';
|
||||||
@ -5,7 +6,6 @@ import { AuthModule } from './api-v1/auth/auth.module';
|
|||||||
import { ImmichJwtModule } from './modules/immich-jwt/immich-jwt.module';
|
import { ImmichJwtModule } from './modules/immich-jwt/immich-jwt.module';
|
||||||
import { DeviceInfoModule } from './api-v1/device-info/device-info.module';
|
import { DeviceInfoModule } from './api-v1/device-info/device-info.module';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { immichAppConfig } from './config/app.config';
|
|
||||||
import { BullModule } from '@nestjs/bull';
|
import { BullModule } from '@nestjs/bull';
|
||||||
import { ServerInfoModule } from './api-v1/server-info/server-info.module';
|
import { ServerInfoModule } from './api-v1/server-info/server-info.module';
|
||||||
import { BackgroundTaskModule } from './modules/background-task/background-task.module';
|
import { BackgroundTaskModule } from './modules/background-task/background-task.module';
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
|
import { APP_UPLOAD_LOCATION } from '@app/common/constants';
|
||||||
import { HttpException, HttpStatus } from '@nestjs/common';
|
import { HttpException, HttpStatus } from '@nestjs/common';
|
||||||
import { MulterOptions } from '@nestjs/platform-express/multer/interfaces/multer-options.interface';
|
import { MulterOptions } from '@nestjs/platform-express/multer/interfaces/multer-options.interface';
|
||||||
import { existsSync, mkdirSync } from 'fs';
|
import { existsSync, mkdirSync } from 'fs';
|
||||||
import { diskStorage } from 'multer';
|
import { diskStorage } from 'multer';
|
||||||
import { extname } from 'path';
|
import { extname } from 'path';
|
||||||
import { Request } from 'express';
|
import { Request } from 'express';
|
||||||
import { APP_UPLOAD_LOCATION } from '../constants/upload_location.constant';
|
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
|
|
||||||
export const assetUploadOption: MulterOptions = {
|
export const assetUploadOption: MulterOptions = {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
|
import { APP_UPLOAD_LOCATION } from '@app/common/constants';
|
||||||
import { HttpException, HttpStatus } from '@nestjs/common';
|
import { HttpException, HttpStatus } from '@nestjs/common';
|
||||||
import { MulterOptions } from '@nestjs/platform-express/multer/interfaces/multer-options.interface';
|
import { MulterOptions } from '@nestjs/platform-express/multer/interfaces/multer-options.interface';
|
||||||
import { existsSync, mkdirSync } from 'fs';
|
import { existsSync, mkdirSync } from 'fs';
|
||||||
import { diskStorage } from 'multer';
|
import { diskStorage } from 'multer';
|
||||||
import { extname } from 'path';
|
import { extname } from 'path';
|
||||||
import { Request } from 'express';
|
import { Request } from 'express';
|
||||||
import { APP_UPLOAD_LOCATION } from '../constants/upload_location.constant';
|
|
||||||
|
|
||||||
export const profileImageUploadOption: MulterOptions = {
|
export const profileImageUploadOption: MulterOptions = {
|
||||||
fileFilter: (req: Request, file: any, cb: any) => {
|
fileFilter: (req: Request, file: any, cb: any) => {
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
"^.+\\.(t|j)s$": "ts-jest"
|
"^.+\\.(t|j)s$": "ts-jest"
|
||||||
},
|
},
|
||||||
"moduleNameMapper": {
|
"moduleNameMapper": {
|
||||||
|
"@app/common/(.*)": "<rootDir>../../../libs/common/src/$1",
|
||||||
"@app/database/config/(.*)": "<rootDir>../../../libs/database/src/config/$1",
|
"@app/database/config/(.*)": "<rootDir>../../../libs/database/src/config/$1",
|
||||||
"@app/database/entities/(.*)": "<rootDir>../../../libs/database/src/entities/$1"
|
"@app/database/entities/(.*)": "<rootDir>../../../libs/database/src/entities/$1"
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,29 @@
|
|||||||
import { BullModule } from '@nestjs/bull';
|
import { immichAppConfig } from '@app/common/config';
|
||||||
import { Module } from '@nestjs/common';
|
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
||||||
import { DatabaseModule } from '@app/database';
|
import { DatabaseModule } from '@app/database';
|
||||||
import { AssetEntity } from '@app/database/entities/asset.entity';
|
import { AssetEntity } from '@app/database/entities/asset.entity';
|
||||||
import { ExifEntity } from '@app/database/entities/exif.entity';
|
import { ExifEntity } from '@app/database/entities/exif.entity';
|
||||||
import { SmartInfoEntity } from '@app/database/entities/smart-info.entity';
|
import { SmartInfoEntity } from '@app/database/entities/smart-info.entity';
|
||||||
import { UserEntity } from '@app/database/entities/user.entity';
|
import { UserEntity } from '@app/database/entities/user.entity';
|
||||||
import { MicroservicesService } from './microservices.service';
|
|
||||||
import { AssetUploadedProcessor } from './processors/asset-uploaded.processor';
|
|
||||||
import { ThumbnailGeneratorProcessor } from './processors/thumbnail.processor';
|
|
||||||
import { MetadataExtractionProcessor } from './processors/metadata-extraction.processor';
|
|
||||||
import { VideoTranscodeProcessor } from './processors/video-transcode.processor';
|
|
||||||
import { CommunicationModule } from '../../immich/src/api-v1/communication/communication.module';
|
|
||||||
import {
|
import {
|
||||||
assetUploadedQueueName,
|
assetUploadedQueueName,
|
||||||
metadataExtractionQueueName,
|
metadataExtractionQueueName,
|
||||||
thumbnailGeneratorQueueName,
|
thumbnailGeneratorQueueName,
|
||||||
videoConversionQueueName,
|
videoConversionQueueName,
|
||||||
} from '@app/job/constants/queue-name.constant';
|
} from '@app/job/constants/queue-name.constant';
|
||||||
|
import { BullModule } from '@nestjs/bull';
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { CommunicationModule } from '../../immich/src/api-v1/communication/communication.module';
|
||||||
|
import { MicroservicesService } from './microservices.service';
|
||||||
|
import { AssetUploadedProcessor } from './processors/asset-uploaded.processor';
|
||||||
|
import { MetadataExtractionProcessor } from './processors/metadata-extraction.processor';
|
||||||
|
import { ThumbnailGeneratorProcessor } from './processors/thumbnail.processor';
|
||||||
|
import { VideoTranscodeProcessor } from './processors/video-transcode.processor';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
ConfigModule.forRoot(immichAppConfig),
|
||||||
DatabaseModule,
|
DatabaseModule,
|
||||||
TypeOrmModule.forFeature([UserEntity, ExifEntity, AssetEntity, SmartInfoEntity]),
|
TypeOrmModule.forFeature([UserEntity, ExifEntity, AssetEntity, SmartInfoEntity]),
|
||||||
BullModule.forRootAsync({
|
BullModule.forRootAsync({
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
import { InjectQueue, Process, Processor } from '@nestjs/bull';
|
|
||||||
import { Job, Queue } from 'bull';
|
|
||||||
import { AssetType } from '@app/database/entities/asset.entity';
|
import { AssetType } from '@app/database/entities/asset.entity';
|
||||||
import { randomUUID } from 'crypto';
|
|
||||||
import {
|
import {
|
||||||
IAssetUploadedJob,
|
IAssetUploadedJob,
|
||||||
IMetadataExtractionJob,
|
IMetadataExtractionJob,
|
||||||
@ -17,6 +14,9 @@ import {
|
|||||||
mp4ConversionProcessorName,
|
mp4ConversionProcessorName,
|
||||||
videoMetadataExtractionProcessorName,
|
videoMetadataExtractionProcessorName,
|
||||||
} from '@app/job';
|
} from '@app/job';
|
||||||
|
import { InjectQueue, Process, Processor } from '@nestjs/bull';
|
||||||
|
import { Job, Queue } from 'bull';
|
||||||
|
import { randomUUID } from 'crypto';
|
||||||
|
|
||||||
@Processor(assetUploadedQueueName)
|
@Processor(assetUploadedQueueName)
|
||||||
export class AssetUploadedProcessor {
|
export class AssetUploadedProcessor {
|
||||||
|
@ -1,18 +1,6 @@
|
|||||||
import { Process, Processor } from '@nestjs/bull';
|
|
||||||
import { Job } from 'bull';
|
|
||||||
import { AssetEntity } from '@app/database/entities/asset.entity';
|
import { AssetEntity } from '@app/database/entities/asset.entity';
|
||||||
import { Repository } from 'typeorm/repository/Repository';
|
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
|
||||||
import { ExifEntity } from '@app/database/entities/exif.entity';
|
import { ExifEntity } from '@app/database/entities/exif.entity';
|
||||||
import exifr from 'exifr';
|
|
||||||
import mapboxGeocoding, { GeocodeService } from '@mapbox/mapbox-sdk/services/geocoding';
|
|
||||||
import { MapiResponse } from '@mapbox/mapbox-sdk/lib/classes/mapi-response';
|
|
||||||
import { readFile } from 'fs/promises';
|
|
||||||
import { Logger } from '@nestjs/common';
|
|
||||||
import axios from 'axios';
|
|
||||||
import { SmartInfoEntity } from '@app/database/entities/smart-info.entity';
|
import { SmartInfoEntity } from '@app/database/entities/smart-info.entity';
|
||||||
import ffmpeg from 'fluent-ffmpeg';
|
|
||||||
import path from 'path';
|
|
||||||
import {
|
import {
|
||||||
IExifExtractionProcessor,
|
IExifExtractionProcessor,
|
||||||
IVideoLengthExtractionProcessor,
|
IVideoLengthExtractionProcessor,
|
||||||
@ -24,6 +12,18 @@ import {
|
|||||||
reverseGeocodingProcessorName,
|
reverseGeocodingProcessorName,
|
||||||
IReverseGeocodingProcessor,
|
IReverseGeocodingProcessor,
|
||||||
} from '@app/job';
|
} from '@app/job';
|
||||||
|
import { MapiResponse } from '@mapbox/mapbox-sdk/lib/classes/mapi-response';
|
||||||
|
import mapboxGeocoding, { GeocodeService } from '@mapbox/mapbox-sdk/services/geocoding';
|
||||||
|
import { Process, Processor } from '@nestjs/bull';
|
||||||
|
import { Logger } from '@nestjs/common';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import axios from 'axios';
|
||||||
|
import { Job } from 'bull';
|
||||||
|
import exifr from 'exifr';
|
||||||
|
import ffmpeg from 'fluent-ffmpeg';
|
||||||
|
import { readFile } from 'fs/promises';
|
||||||
|
import path from 'path';
|
||||||
|
import { Repository } from 'typeorm/repository/Repository';
|
||||||
|
|
||||||
@Processor(metadataExtractionQueueName)
|
@Processor(metadataExtractionQueueName)
|
||||||
export class MetadataExtractionProcessor {
|
export class MetadataExtractionProcessor {
|
||||||
|
@ -1,14 +1,4 @@
|
|||||||
import { InjectQueue, Process, Processor } from '@nestjs/bull';
|
|
||||||
import { Job, Queue } from 'bull';
|
|
||||||
import { AssetEntity, AssetType } from '@app/database/entities/asset.entity';
|
import { AssetEntity, AssetType } from '@app/database/entities/asset.entity';
|
||||||
import { Repository } from 'typeorm/repository/Repository';
|
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
|
||||||
import sharp from 'sharp';
|
|
||||||
import { existsSync, mkdirSync } from 'node:fs';
|
|
||||||
import { randomUUID } from 'node:crypto';
|
|
||||||
import { CommunicationGateway } from '../../../immich/src/api-v1/communication/communication.gateway';
|
|
||||||
import ffmpeg from 'fluent-ffmpeg';
|
|
||||||
import { Logger } from '@nestjs/common';
|
|
||||||
import {
|
import {
|
||||||
WebpGeneratorProcessor,
|
WebpGeneratorProcessor,
|
||||||
generateJPEGThumbnailProcessorName,
|
generateJPEGThumbnailProcessorName,
|
||||||
@ -19,7 +9,17 @@ import {
|
|||||||
thumbnailGeneratorQueueName,
|
thumbnailGeneratorQueueName,
|
||||||
JpegGeneratorProcessor,
|
JpegGeneratorProcessor,
|
||||||
} from '@app/job';
|
} from '@app/job';
|
||||||
|
import { InjectQueue, Process, Processor } from '@nestjs/bull';
|
||||||
|
import { Logger } from '@nestjs/common';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { mapAsset } from 'apps/immich/src/api-v1/asset/response-dto/asset-response.dto';
|
import { mapAsset } from 'apps/immich/src/api-v1/asset/response-dto/asset-response.dto';
|
||||||
|
import { Job, Queue } from 'bull';
|
||||||
|
import ffmpeg from 'fluent-ffmpeg';
|
||||||
|
import { randomUUID } from 'node:crypto';
|
||||||
|
import { existsSync, mkdirSync } from 'node:fs';
|
||||||
|
import sharp from 'sharp';
|
||||||
|
import { Repository } from 'typeorm/repository/Repository';
|
||||||
|
import { CommunicationGateway } from '../../../immich/src/api-v1/communication/communication.gateway';
|
||||||
|
|
||||||
@Processor(thumbnailGeneratorQueueName)
|
@Processor(thumbnailGeneratorQueueName)
|
||||||
export class ThumbnailGeneratorProcessor {
|
export class ThumbnailGeneratorProcessor {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { APP_UPLOAD_LOCATION } from '@app/common/constants';
|
||||||
|
import { AssetEntity } from '@app/database/entities/asset.entity';
|
||||||
import { mp4ConversionProcessorName } from '@app/job/constants/job-name.constant';
|
import { mp4ConversionProcessorName } from '@app/job/constants/job-name.constant';
|
||||||
import { videoConversionQueueName } from '@app/job/constants/queue-name.constant';
|
import { videoConversionQueueName } from '@app/job/constants/queue-name.constant';
|
||||||
import { IMp4ConversionProcessor } from '@app/job/interfaces/video-transcode.interface';
|
import { IMp4ConversionProcessor } from '@app/job/interfaces/video-transcode.interface';
|
||||||
@ -8,8 +10,6 @@ import { Job } from 'bull';
|
|||||||
import ffmpeg from 'fluent-ffmpeg';
|
import ffmpeg from 'fluent-ffmpeg';
|
||||||
import { existsSync, mkdirSync } from 'fs';
|
import { existsSync, mkdirSync } from 'fs';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { AssetEntity } from '../../../../libs/database/src/entities/asset.entity';
|
|
||||||
import { APP_UPLOAD_LOCATION } from '../../../immich/src/constants/upload_location.constant';
|
|
||||||
|
|
||||||
@Processor(videoConversionQueueName)
|
@Processor(videoConversionQueueName)
|
||||||
export class VideoTranscodeProcessor {
|
export class VideoTranscodeProcessor {
|
||||||
|
1
server/libs/common/src/config/index.ts
Normal file
1
server/libs/common/src/config/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './app.config';
|
1
server/libs/common/src/constants/index.ts
Normal file
1
server/libs/common/src/constants/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './upload_location.constant';
|
2
server/libs/common/src/index.ts
Normal file
2
server/libs/common/src/index.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export * from './config';
|
||||||
|
export * from './constants';
|
9
server/libs/common/tsconfig.lib.json
Normal file
9
server/libs/common/tsconfig.lib.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"declaration": true,
|
||||||
|
"outDir": "../../dist/libs/common"
|
||||||
|
},
|
||||||
|
"include": ["src/**/*"],
|
||||||
|
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
|
||||||
|
}
|
@ -33,6 +33,15 @@
|
|||||||
"tsConfigPath": "apps/microservices/tsconfig.app.json"
|
"tsConfigPath": "apps/microservices/tsconfig.app.json"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"common": {
|
||||||
|
"type": "library",
|
||||||
|
"root": "libs/common",
|
||||||
|
"entryFile": "index",
|
||||||
|
"sourceRoot": "libs/common/src",
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsConfigPath": "libs/common/tsconfig.lib.json"
|
||||||
|
}
|
||||||
|
},
|
||||||
"database": {
|
"database": {
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"root": "libs/database",
|
"root": "libs/database",
|
||||||
|
@ -16,6 +16,12 @@
|
|||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"baseUrl": "./",
|
"baseUrl": "./",
|
||||||
"paths": {
|
"paths": {
|
||||||
|
"@app/common": [
|
||||||
|
"libs/common/src"
|
||||||
|
],
|
||||||
|
"@app/common/*": [
|
||||||
|
"libs/common/src/*"
|
||||||
|
],
|
||||||
"@app/database": [
|
"@app/database": [
|
||||||
"libs/database/src"
|
"libs/database/src"
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user