Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move controllers and middleware #8119

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/e2e/jobs/specs/library.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { api } from 'e2e/client';
import fs from 'node:fs';
import { LibraryController } from 'src/controllers/library.controller';
import { LoginResponseDto } from 'src/domain/auth/auth.dto';
import { LibraryController } from 'src/immich/controllers/library.controller';
import { LibraryType } from 'src/infra/entities/library.entity';
import { IMMICH_TEST_ASSET_PATH, IMMICH_TEST_ASSET_TEMP_PATH, restoreTempFolder, testApp } from 'src/test-utils/utils';
import request from 'supertest';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from 'src/domain/activity/activity.dto';
import { ActivityService } from 'src/domain/activity/activity.service';
import { AuthDto } from 'src/domain/auth/auth.dto';
import { Auth, Authenticated } from 'src/immich/app.guard';
import { Auth, Authenticated } from 'src/middleware/auth.guard';
import { UUIDParamDto } from 'src/validation';

@ApiTags('Activity')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AlbumInfoDto } from 'src/domain/album/dto/album.dto';
import { GetAlbumsDto } from 'src/domain/album/dto/get-albums.dto';
import { BulkIdResponseDto, BulkIdsDto } from 'src/domain/asset/response-dto/asset-ids-response.dto';
import { AuthDto } from 'src/domain/auth/auth.dto';
import { Auth, Authenticated, SharedLinkRoute } from 'src/immich/app.guard';
import { Auth, Authenticated, SharedLinkRoute } from 'src/middleware/auth.guard';
import { ParseMeUUIDPipe, UUIDParamDto } from 'src/validation';

@ApiTags('Album')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from 'src/domain/api-key/api-key.dto';
import { APIKeyService } from 'src/domain/api-key/api-key.service';
import { AuthDto } from 'src/domain/auth/auth.dto';
import { Auth, Authenticated } from 'src/immich/app.guard';
import { Auth, Authenticated } from 'src/middleware/auth.guard';
import { UUIDParamDto } from 'src/validation';

@ApiTags('API Key')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller, Get, Header } from '@nestjs/common';
import { ApiExcludeEndpoint } from '@nestjs/swagger';
import { SystemConfigService } from 'src/domain/system-config/system-config.service';
import { PublicRoute } from 'src/immich/app.guard';
import { PublicRoute } from 'src/middleware/auth.guard';

@Controller()
export class AppController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { TimeBucketResponseDto } from 'src/domain/asset/response-dto/time-bucket
import { AuthDto } from 'src/domain/auth/auth.dto';
import { MetadataSearchDto } from 'src/domain/search/dto/search.dto';
import { SearchService } from 'src/domain/search/search.service';
import { Auth, Authenticated, SharedLinkRoute } from 'src/immich/app.guard';
import { Route } from 'src/immich/interceptors/file-upload.interceptor';
import { Auth, Authenticated, SharedLinkRoute } from 'src/middleware/auth.guard';
import { Route } from 'src/middleware/file-upload.interceptor';
import { UUIDParamDto } from 'src/validation';

@ApiTags('Asset')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from 'src/domain/audit/audit.dto';
import { AuditService } from 'src/domain/audit/audit.service';
import { AuthDto } from 'src/domain/auth/auth.dto';
import { AdminRoute, Auth, Authenticated } from 'src/immich/app.guard';
import { AdminRoute, Auth, Authenticated } from 'src/middleware/auth.guard';

@ApiTags('Audit')
@Controller('audit')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from 'src/domain/auth/auth.dto';
import { AuthService, LoginDetails } from 'src/domain/auth/auth.service';
import { UserResponseDto, mapUser } from 'src/domain/user/response-dto/user-response.dto';
import { Auth, Authenticated, GetLoginDetails, PublicRoute } from 'src/immich/app.guard';
import { Auth, Authenticated, GetLoginDetails, PublicRoute } from 'src/middleware/auth.guard';
import { UUIDParamDto } from 'src/validation';

@ApiTags('Authentication')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { AssetIdsDto } from 'src/domain/asset/dto/asset-ids.dto';
import { AuthDto } from 'src/domain/auth/auth.dto';
import { DownloadInfoDto, DownloadResponseDto } from 'src/domain/download/download.dto';
import { DownloadService } from 'src/domain/download/download.service';
import { Auth, Authenticated, FileResponse, SharedLinkRoute } from 'src/immich/app.guard';
import { asStreamableFile, sendFile } from 'src/immich/app.utils';
import { Auth, Authenticated, FileResponse, SharedLinkRoute } from 'src/middleware/auth.guard';
import { UUIDParamDto } from 'src/validation';

@ApiTags('Download')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ApiTags } from '@nestjs/swagger';
import { AuthDto } from 'src/domain/auth/auth.dto';
import { AssetFaceResponseDto, FaceDto, PersonResponseDto } from 'src/domain/person/person.dto';
import { PersonService } from 'src/domain/person/person.service';
import { Auth, Authenticated } from 'src/immich/app.guard';
import { Auth, Authenticated } from 'src/middleware/auth.guard';
import { UUIDParamDto } from 'src/validation';

@ApiTags('Face')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Body, Controller, Get, Param, Put } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { AllJobStatusResponseDto, JobCommandDto, JobIdParamDto, JobStatusDto } from 'src/domain/job/job.dto';
import { JobService } from 'src/domain/job/job.service';
import { Authenticated } from 'src/immich/app.guard';
import { Authenticated } from 'src/middleware/auth.guard';

@ApiTags('Job')
@Controller('jobs')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ValidateLibraryResponseDto,
} from 'src/domain/library/library.dto';
import { LibraryService } from 'src/domain/library/library.service';
import { AdminRoute, Authenticated } from 'src/immich/app.guard';
import { AdminRoute, Authenticated } from 'src/middleware/auth.guard';
import { UUIDParamDto } from 'src/validation';

@ApiTags('Library')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from 'src/domain/auth/auth.dto';
import { AuthService, LoginDetails } from 'src/domain/auth/auth.service';
import { UserResponseDto } from 'src/domain/user/response-dto/user-response.dto';
import { Auth, Authenticated, GetLoginDetails, PublicRoute } from 'src/immich/app.guard';
import { Auth, Authenticated, GetLoginDetails, PublicRoute } from 'src/middleware/auth.guard';

@ApiTags('OAuth')
@Controller('oauth')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AuthDto } from 'src/domain/auth/auth.dto';
import { PartnerResponseDto, UpdatePartnerDto } from 'src/domain/partner/partner.dto';
import { PartnerService } from 'src/domain/partner/partner.service';
import { PartnerDirection } from 'src/domain/repositories/partner.repository';
import { Auth, Authenticated } from 'src/immich/app.guard';
import { Auth, Authenticated } from 'src/middleware/auth.guard';
import { UUIDParamDto } from 'src/validation';

@ApiTags('Partner')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
PersonUpdateDto,
} from 'src/domain/person/person.dto';
import { PersonService } from 'src/domain/person/person.service';
import { Auth, Authenticated, FileResponse } from 'src/immich/app.guard';
import { sendFile } from 'src/immich/app.utils';
import { Auth, Authenticated, FileResponse } from 'src/middleware/auth.guard';
import { UUIDParamDto } from 'src/validation';

@ApiTags('Person')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { SearchExploreResponseDto } from 'src/domain/search/response-dto/search-explore.response.dto';
import { SearchResponseDto } from 'src/domain/search/response-dto/search-response.dto';
import { SearchService } from 'src/domain/search/search.service';
import { Auth, Authenticated } from 'src/immich/app.guard';
import { Auth, Authenticated } from 'src/middleware/auth.guard';

@ApiTags('Search')
@Controller('search')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ServerVersionResponseDto,
} from 'src/domain/server-info/server-info.dto';
import { ServerInfoService } from 'src/domain/server-info/server-info.service';
import { AdminRoute, Authenticated, PublicRoute } from 'src/immich/app.guard';
import { AdminRoute, Authenticated, PublicRoute } from 'src/middleware/auth.guard';

@ApiTags('Server Info')
@Controller('server-info')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AuthDto } from 'src/domain/auth/auth.dto';
import { SharedLinkResponseDto } from 'src/domain/shared-link/shared-link-response.dto';
import { SharedLinkCreateDto, SharedLinkEditDto, SharedLinkPasswordDto } from 'src/domain/shared-link/shared-link.dto';
import { SharedLinkService } from 'src/domain/shared-link/shared-link.service';
import { Auth, Authenticated, SharedLinkRoute } from 'src/immich/app.guard';
import { Auth, Authenticated, SharedLinkRoute } from 'src/middleware/auth.guard';
import { UUIDParamDto } from 'src/validation';

@ApiTags('Shared Link')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SystemConfigDto } from 'src/domain/system-config/dto/system-config.dto'
import { SystemConfigTemplateStorageOptionDto } from 'src/domain/system-config/response-dto/system-config-template-storage-option.dto';
import { MapThemeDto } from 'src/domain/system-config/system-config-map-theme.dto';
import { SystemConfigService } from 'src/domain/system-config/system-config.service';
import { AdminRoute, Authenticated } from 'src/immich/app.guard';
import { AdminRoute, Authenticated } from 'src/middleware/auth.guard';

@ApiTags('System Config')
@Controller('system-config')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AuthDto } from 'src/domain/auth/auth.dto';
import { TagResponseDto } from 'src/domain/tag/tag-response.dto';
import { CreateTagDto, UpdateTagDto } from 'src/domain/tag/tag.dto';
import { TagService } from 'src/domain/tag/tag.service';
import { Auth, Authenticated } from 'src/immich/app.guard';
import { Auth, Authenticated } from 'src/middleware/auth.guard';
import { UUIDParamDto } from 'src/validation';

@ApiTags('Tag')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ApiTags } from '@nestjs/swagger';
import { BulkIdsDto } from 'src/domain/asset/response-dto/asset-ids-response.dto';
import { AuthDto } from 'src/domain/auth/auth.dto';
import { TrashService } from 'src/domain/trash/trash.service';
import { Auth, Authenticated } from 'src/immich/app.guard';
import { Auth, Authenticated } from 'src/middleware/auth.guard';

@ApiTags('Trash')
@Controller('trash')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import { UpdateUserDto } from 'src/domain/user/dto/update-user.dto';
import { CreateProfileImageResponseDto } from 'src/domain/user/response-dto/create-profile-image-response.dto';
import { UserResponseDto } from 'src/domain/user/response-dto/user-response.dto';
import { UserService } from 'src/domain/user/user.service';
import { AdminRoute, Auth, Authenticated, FileResponse } from 'src/immich/app.guard';
import { sendFile } from 'src/immich/app.utils';
import { FileUploadInterceptor, Route } from 'src/immich/interceptors/file-upload.interceptor';
import { AdminRoute, Auth, Authenticated, FileResponse } from 'src/middleware/auth.guard';
import { FileUploadInterceptor, Route } from 'src/middleware/file-upload.interceptor';
import { UUIDParamDto } from 'src/validation';

@ApiTags('User')
Expand Down
9 changes: 2 additions & 7 deletions server/src/immich/api-v1/asset/asset.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,9 @@ import { AssetFileUploadResponseDto } from 'src/immich/api-v1/asset/response-dto
import { CheckExistingAssetsResponseDto } from 'src/immich/api-v1/asset/response-dto/check-existing-assets-response.dto';
import { CuratedLocationsResponseDto } from 'src/immich/api-v1/asset/response-dto/curated-locations-response.dto';
import { CuratedObjectsResponseDto } from 'src/immich/api-v1/asset/response-dto/curated-objects-response.dto';
import { Auth, Authenticated, FileResponse, SharedLinkRoute } from 'src/immich/app.guard';
import { sendFile } from 'src/immich/app.utils';
import {
FileUploadInterceptor,
ImmichFile,
Route,
mapToUploadFile,
} from 'src/immich/interceptors/file-upload.interceptor';
import { Auth, Authenticated, FileResponse, SharedLinkRoute } from 'src/middleware/auth.guard';
import { FileUploadInterceptor, ImmichFile, Route, mapToUploadFile } from 'src/middleware/file-upload.interceptor';
import { FileNotEmptyValidator, UUIDParamDto } from 'src/validation';

interface UploadFiles {
Expand Down
50 changes: 25 additions & 25 deletions server/src/immich/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@ 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 { ActivityController } from 'src/controllers/activity.controller';
import { AlbumController } from 'src/controllers/album.controller';
import { APIKeyController } from 'src/controllers/api-key.controller';
import { AppController } from 'src/controllers/app.controller';
import { AssetController, AssetsController } from 'src/controllers/asset.controller';
import { AuditController } from 'src/controllers/audit.controller';
import { AuthController } from 'src/controllers/auth.controller';
import { DownloadController } from 'src/controllers/download.controller';
import { FaceController } from 'src/controllers/face.controller';
import { JobController } from 'src/controllers/job.controller';
import { LibraryController } from 'src/controllers/library.controller';
import { OAuthController } from 'src/controllers/oauth.controller';
import { PartnerController } from 'src/controllers/partner.controller';
import { PersonController } from 'src/controllers/person.controller';
import { SearchController } from 'src/controllers/search.controller';
import { ServerInfoController } from 'src/controllers/server-info.controller';
import { SharedLinkController } from 'src/controllers/shared-link.controller';
import { SystemConfigController } from 'src/controllers/system-config.controller';
import { TagController } from 'src/controllers/tag.controller';
import { TrashController } from 'src/controllers/trash.controller';
import { UserController } from 'src/controllers/user.controller';
import { DomainModule } from 'src/domain/domain.module';
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 { AppGuard } from 'src/immich/app.guard';
import { AppService } from 'src/immich/app.service';
import { ActivityController } from 'src/immich/controllers/activity.controller';
import { AlbumController } from 'src/immich/controllers/album.controller';
import { APIKeyController } from 'src/immich/controllers/api-key.controller';
import { AppController } from 'src/immich/controllers/app.controller';
import { AssetController, AssetsController } from 'src/immich/controllers/asset.controller';
import { AuditController } from 'src/immich/controllers/audit.controller';
import { AuthController } from 'src/immich/controllers/auth.controller';
import { DownloadController } from 'src/immich/controllers/download.controller';
import { FaceController } from 'src/immich/controllers/face.controller';
import { JobController } from 'src/immich/controllers/job.controller';
import { LibraryController } from 'src/immich/controllers/library.controller';
import { OAuthController } from 'src/immich/controllers/oauth.controller';
import { PartnerController } from 'src/immich/controllers/partner.controller';
import { PersonController } from 'src/immich/controllers/person.controller';
import { SearchController } from 'src/immich/controllers/search.controller';
import { ServerInfoController } from 'src/immich/controllers/server-info.controller';
import { SharedLinkController } from 'src/immich/controllers/shared-link.controller';
import { SystemConfigController } from 'src/immich/controllers/system-config.controller';
import { TagController } from 'src/immich/controllers/tag.controller';
import { TrashController } from 'src/immich/controllers/trash.controller';
import { UserController } from 'src/immich/controllers/user.controller';
import { ErrorInterceptor } from 'src/immich/interceptors/error.interceptor';
import { FileUploadInterceptor } from 'src/immich/interceptors/file-upload.interceptor';
import { AssetEntity } from 'src/infra/entities/asset.entity';
import { ExifEntity } from 'src/infra/entities/exif.entity';
import { InfraModule } from 'src/infra/infra.module';
import { AuthGuard } from 'src/middleware/auth.guard';
import { ErrorInterceptor } from 'src/middleware/error.interceptor';
import { FileUploadInterceptor } from 'src/middleware/file-upload.interceptor';

@Module({
imports: [
Expand Down Expand Up @@ -71,7 +71,7 @@ import { InfraModule } from 'src/infra/infra.module';
providers: [
{ provide: APP_PIPE, useValue: new ValidationPipe({ transform: true, whitelist: true }) },
{ provide: APP_INTERCEPTOR, useClass: ErrorInterceptor },
{ provide: APP_GUARD, useClass: AppGuard },
{ provide: APP_GUARD, useClass: AuthGuard },
{ provide: IAssetRepositoryV1, useClass: AssetRepositoryV1 },
AppService,
AssetServiceV1,
Expand Down
2 changes: 1 addition & 1 deletion server/src/immich/app.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { promisify } from 'node:util';
import { IMMICH_ACCESS_COOKIE, IMMICH_API_KEY_HEADER, IMMICH_API_KEY_NAME } from 'src/domain/auth/auth.constant';
import { serverVersion } from 'src/domain/domain.constant';
import { ImmichReadStream } from 'src/domain/repositories/storage.repository';
import { Metadata } from 'src/immich/app.guard';
import { ImmichLogger } from 'src/infra/logger';
import { Metadata } from 'src/middleware/auth.guard';
import { CacheControl, ImmichFileResponse, isConnectionAborted } from 'src/utils';

type SendFile = Parameters<Response['sendFile']>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export interface AuthRequest extends Request {
}

@Injectable()
export class AppGuard implements CanActivate {
private logger = new ImmichLogger(AppGuard.name);
export class AuthGuard implements CanActivate {
private logger = new ImmichLogger(AuthGuard.name);

constructor(
private reflector: Reflector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import multer, { StorageEngine, diskStorage } from 'multer';
import { createHash, randomUUID } from 'node:crypto';
import { Observable } from 'rxjs';
import { AssetService, UploadFieldName, UploadFile } from 'src/domain/asset/asset.service';
import { AuthRequest } from 'src/immich/app.guard';
import { ImmichLogger } from 'src/infra/logger';
import { AuthRequest } from 'src/middleware/auth.guard';

export enum Route {
ASSET = 'asset',
Expand Down
Loading