mirror of
https://github.com/immich-app/immich.git
synced 2025-05-31 20:25:32 -04:00
refactor(server): auth enums (#13552)
This commit is contained in:
parent
d9949434f6
commit
e3fc4d7b0a
@ -3,13 +3,13 @@ import { CronExpression } from '@nestjs/schedule';
|
|||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import Joi, { Root } from 'joi';
|
import Joi, { Root } from 'joi';
|
||||||
import { CLS_ID, ClsModuleOptions } from 'nestjs-cls';
|
import { CLS_ID, ClsModuleOptions } from 'nestjs-cls';
|
||||||
import { ImmichHeader } from 'src/dtos/auth.dto';
|
|
||||||
import {
|
import {
|
||||||
AudioCodec,
|
AudioCodec,
|
||||||
Colorspace,
|
Colorspace,
|
||||||
CQMode,
|
CQMode,
|
||||||
ImageFormat,
|
ImageFormat,
|
||||||
ImmichEnvironment,
|
ImmichEnvironment,
|
||||||
|
ImmichHeader,
|
||||||
LogLevel,
|
LogLevel,
|
||||||
ToneMapping,
|
ToneMapping,
|
||||||
TranscodeHWAccel,
|
TranscodeHWAccel,
|
||||||
|
@ -32,8 +32,8 @@ import {
|
|||||||
CheckExistingAssetsDto,
|
CheckExistingAssetsDto,
|
||||||
UploadFieldName,
|
UploadFieldName,
|
||||||
} from 'src/dtos/asset-media.dto';
|
} from 'src/dtos/asset-media.dto';
|
||||||
import { AuthDto, ImmichHeader } from 'src/dtos/auth.dto';
|
import { AuthDto } from 'src/dtos/auth.dto';
|
||||||
import { RouteKey } from 'src/enum';
|
import { ImmichHeader, RouteKey } from 'src/enum';
|
||||||
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
||||||
import { AssetUploadInterceptor } from 'src/middleware/asset-upload.interceptor';
|
import { AssetUploadInterceptor } from 'src/middleware/asset-upload.interceptor';
|
||||||
import { Auth, Authenticated, FileResponse } from 'src/middleware/auth.guard';
|
import { Auth, Authenticated, FileResponse } from 'src/middleware/auth.guard';
|
||||||
|
@ -4,7 +4,6 @@ import { Request, Response } from 'express';
|
|||||||
import {
|
import {
|
||||||
AuthDto,
|
AuthDto,
|
||||||
ChangePasswordDto,
|
ChangePasswordDto,
|
||||||
ImmichCookie,
|
|
||||||
LoginCredentialDto,
|
LoginCredentialDto,
|
||||||
LoginResponseDto,
|
LoginResponseDto,
|
||||||
LogoutResponseDto,
|
LogoutResponseDto,
|
||||||
@ -12,7 +11,7 @@ import {
|
|||||||
ValidateAccessTokenResponseDto,
|
ValidateAccessTokenResponseDto,
|
||||||
} from 'src/dtos/auth.dto';
|
} from 'src/dtos/auth.dto';
|
||||||
import { UserAdminResponseDto } from 'src/dtos/user.dto';
|
import { UserAdminResponseDto } from 'src/dtos/user.dto';
|
||||||
import { AuthType } from 'src/enum';
|
import { AuthType, ImmichCookie } from 'src/enum';
|
||||||
import { Auth, Authenticated, GetLoginDetails } from 'src/middleware/auth.guard';
|
import { Auth, Authenticated, GetLoginDetails } from 'src/middleware/auth.guard';
|
||||||
import { AuthService, LoginDetails } from 'src/services/auth.service';
|
import { AuthService, LoginDetails } from 'src/services/auth.service';
|
||||||
import { respondWithCookie, respondWithoutCookie } from 'src/utils/response';
|
import { respondWithCookie, respondWithoutCookie } from 'src/utils/response';
|
||||||
|
@ -3,14 +3,13 @@ import { ApiTags } from '@nestjs/swagger';
|
|||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import {
|
import {
|
||||||
AuthDto,
|
AuthDto,
|
||||||
ImmichCookie,
|
|
||||||
LoginResponseDto,
|
LoginResponseDto,
|
||||||
OAuthAuthorizeResponseDto,
|
OAuthAuthorizeResponseDto,
|
||||||
OAuthCallbackDto,
|
OAuthCallbackDto,
|
||||||
OAuthConfigDto,
|
OAuthConfigDto,
|
||||||
} from 'src/dtos/auth.dto';
|
} from 'src/dtos/auth.dto';
|
||||||
import { UserAdminResponseDto } from 'src/dtos/user.dto';
|
import { UserAdminResponseDto } from 'src/dtos/user.dto';
|
||||||
import { AuthType } from 'src/enum';
|
import { AuthType, ImmichCookie } from 'src/enum';
|
||||||
import { Auth, Authenticated, GetLoginDetails } from 'src/middleware/auth.guard';
|
import { Auth, Authenticated, GetLoginDetails } from 'src/middleware/auth.guard';
|
||||||
import { AuthService, LoginDetails } from 'src/services/auth.service';
|
import { AuthService, LoginDetails } from 'src/services/auth.service';
|
||||||
import { respondWithCookie } from 'src/utils/response';
|
import { respondWithCookie } from 'src/utils/response';
|
||||||
|
@ -3,14 +3,14 @@ import { ApiTags } from '@nestjs/swagger';
|
|||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import { AssetIdsResponseDto } from 'src/dtos/asset-ids.response.dto';
|
import { AssetIdsResponseDto } from 'src/dtos/asset-ids.response.dto';
|
||||||
import { AssetIdsDto } from 'src/dtos/asset.dto';
|
import { AssetIdsDto } from 'src/dtos/asset.dto';
|
||||||
import { AuthDto, ImmichCookie } from 'src/dtos/auth.dto';
|
import { AuthDto } from 'src/dtos/auth.dto';
|
||||||
import {
|
import {
|
||||||
SharedLinkCreateDto,
|
SharedLinkCreateDto,
|
||||||
SharedLinkEditDto,
|
SharedLinkEditDto,
|
||||||
SharedLinkPasswordDto,
|
SharedLinkPasswordDto,
|
||||||
SharedLinkResponseDto,
|
SharedLinkResponseDto,
|
||||||
} from 'src/dtos/shared-link.dto';
|
} from 'src/dtos/shared-link.dto';
|
||||||
import { Permission } from 'src/enum';
|
import { ImmichCookie, Permission } from 'src/enum';
|
||||||
import { Auth, Authenticated, GetLoginDetails } from 'src/middleware/auth.guard';
|
import { Auth, Authenticated, GetLoginDetails } from 'src/middleware/auth.guard';
|
||||||
import { LoginDetails } from 'src/services/auth.service';
|
import { LoginDetails } from 'src/services/auth.service';
|
||||||
import { SharedLinkService } from 'src/services/shared-link.service';
|
import { SharedLinkService } from 'src/services/shared-link.service';
|
||||||
|
@ -5,30 +5,9 @@ import { APIKeyEntity } from 'src/entities/api-key.entity';
|
|||||||
import { SessionEntity } from 'src/entities/session.entity';
|
import { SessionEntity } from 'src/entities/session.entity';
|
||||||
import { SharedLinkEntity } from 'src/entities/shared-link.entity';
|
import { SharedLinkEntity } from 'src/entities/shared-link.entity';
|
||||||
import { UserEntity } from 'src/entities/user.entity';
|
import { UserEntity } from 'src/entities/user.entity';
|
||||||
|
import { ImmichCookie } from 'src/enum';
|
||||||
import { toEmail } from 'src/validation';
|
import { toEmail } from 'src/validation';
|
||||||
|
|
||||||
export enum ImmichCookie {
|
|
||||||
ACCESS_TOKEN = 'immich_access_token',
|
|
||||||
AUTH_TYPE = 'immich_auth_type',
|
|
||||||
IS_AUTHENTICATED = 'immich_is_authenticated',
|
|
||||||
SHARED_LINK_TOKEN = 'immich_shared_link_token',
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum ImmichHeader {
|
|
||||||
API_KEY = 'x-api-key',
|
|
||||||
USER_TOKEN = 'x-immich-user-token',
|
|
||||||
SESSION_TOKEN = 'x-immich-session-token',
|
|
||||||
SHARED_LINK_KEY = 'x-immich-share-key',
|
|
||||||
CHECKSUM = 'x-immich-checksum',
|
|
||||||
CID = 'x-immich-cid',
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum ImmichQuery {
|
|
||||||
SHARED_LINK_KEY = 'key',
|
|
||||||
API_KEY = 'apiKey',
|
|
||||||
SESSION_KEY = 'sessionKey',
|
|
||||||
}
|
|
||||||
|
|
||||||
export type CookieResponse = {
|
export type CookieResponse = {
|
||||||
isSecure: boolean;
|
isSecure: boolean;
|
||||||
values: Array<{ key: ImmichCookie; value: string }>;
|
values: Array<{ key: ImmichCookie; value: string }>;
|
||||||
|
@ -3,6 +3,28 @@ export enum AuthType {
|
|||||||
OAUTH = 'oauth',
|
OAUTH = 'oauth',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum ImmichCookie {
|
||||||
|
ACCESS_TOKEN = 'immich_access_token',
|
||||||
|
AUTH_TYPE = 'immich_auth_type',
|
||||||
|
IS_AUTHENTICATED = 'immich_is_authenticated',
|
||||||
|
SHARED_LINK_TOKEN = 'immich_shared_link_token',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum ImmichHeader {
|
||||||
|
API_KEY = 'x-api-key',
|
||||||
|
USER_TOKEN = 'x-immich-user-token',
|
||||||
|
SESSION_TOKEN = 'x-immich-session-token',
|
||||||
|
SHARED_LINK_KEY = 'x-immich-share-key',
|
||||||
|
CHECKSUM = 'x-immich-checksum',
|
||||||
|
CID = 'x-immich-cid',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum ImmichQuery {
|
||||||
|
SHARED_LINK_KEY = 'key',
|
||||||
|
API_KEY = 'apiKey',
|
||||||
|
SESSION_KEY = 'sessionKey',
|
||||||
|
}
|
||||||
|
|
||||||
export enum AssetType {
|
export enum AssetType {
|
||||||
IMAGE = 'IMAGE',
|
IMAGE = 'IMAGE',
|
||||||
VIDEO = 'VIDEO',
|
VIDEO = 'VIDEO',
|
||||||
|
@ -2,7 +2,7 @@ import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nes
|
|||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { AssetMediaResponseDto, AssetMediaStatus } from 'src/dtos/asset-media-response.dto';
|
import { AssetMediaResponseDto, AssetMediaStatus } from 'src/dtos/asset-media-response.dto';
|
||||||
import { ImmichHeader } from 'src/dtos/auth.dto';
|
import { ImmichHeader } from 'src/enum';
|
||||||
import { AuthenticatedRequest } from 'src/middleware/auth.guard';
|
import { AuthenticatedRequest } from 'src/middleware/auth.guard';
|
||||||
import { AssetMediaService } from 'src/services/asset-media.service';
|
import { AssetMediaService } from 'src/services/asset-media.service';
|
||||||
import { fromMaybeArray } from 'src/utils/request';
|
import { fromMaybeArray } from 'src/utils/request';
|
||||||
|
@ -10,8 +10,8 @@ import {
|
|||||||
import { Reflector } from '@nestjs/core';
|
import { Reflector } from '@nestjs/core';
|
||||||
import { ApiBearerAuth, ApiCookieAuth, ApiOkResponse, ApiQuery, ApiSecurity } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiCookieAuth, ApiOkResponse, ApiQuery, ApiSecurity } from '@nestjs/swagger';
|
||||||
import { Request } from 'express';
|
import { Request } from 'express';
|
||||||
import { AuthDto, ImmichQuery } from 'src/dtos/auth.dto';
|
import { AuthDto } from 'src/dtos/auth.dto';
|
||||||
import { MetadataKey, Permission } from 'src/enum';
|
import { ImmichQuery, MetadataKey, Permission } from 'src/enum';
|
||||||
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
||||||
import { AuthService, LoginDetails } from 'src/services/auth.service';
|
import { AuthService, LoginDetails } from 'src/services/auth.service';
|
||||||
import { UAParser } from 'ua-parser-js';
|
import { UAParser } from 'ua-parser-js';
|
||||||
|
@ -8,9 +8,6 @@ import { OnEvent } from 'src/decorators';
|
|||||||
import {
|
import {
|
||||||
AuthDto,
|
AuthDto,
|
||||||
ChangePasswordDto,
|
ChangePasswordDto,
|
||||||
ImmichCookie,
|
|
||||||
ImmichHeader,
|
|
||||||
ImmichQuery,
|
|
||||||
LoginCredentialDto,
|
LoginCredentialDto,
|
||||||
LogoutResponseDto,
|
LogoutResponseDto,
|
||||||
OAuthAuthorizeResponseDto,
|
OAuthAuthorizeResponseDto,
|
||||||
@ -21,7 +18,7 @@ import {
|
|||||||
} from 'src/dtos/auth.dto';
|
} from 'src/dtos/auth.dto';
|
||||||
import { UserAdminResponseDto, mapUserAdmin } from 'src/dtos/user.dto';
|
import { UserAdminResponseDto, mapUserAdmin } from 'src/dtos/user.dto';
|
||||||
import { UserEntity } from 'src/entities/user.entity';
|
import { UserEntity } from 'src/entities/user.entity';
|
||||||
import { AuthType, Permission } from 'src/enum';
|
import { AuthType, ImmichCookie, ImmichHeader, ImmichQuery, Permission } from 'src/enum';
|
||||||
import { OAuthProfile } from 'src/interfaces/oauth.interface';
|
import { OAuthProfile } from 'src/interfaces/oauth.interface';
|
||||||
import { BaseService } from 'src/services/base.service';
|
import { BaseService } from 'src/services/base.service';
|
||||||
import { isGranted } from 'src/utils/access';
|
import { isGranted } from 'src/utils/access';
|
||||||
|
@ -12,8 +12,7 @@ import { writeFileSync } from 'node:fs';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { SystemConfig } from 'src/config';
|
import { SystemConfig } from 'src/config';
|
||||||
import { CLIP_MODEL_INFO, serverVersion } from 'src/constants';
|
import { CLIP_MODEL_INFO, serverVersion } from 'src/constants';
|
||||||
import { ImmichCookie, ImmichHeader } from 'src/dtos/auth.dto';
|
import { ImmichCookie, ImmichHeader, MetadataKey } from 'src/enum';
|
||||||
import { MetadataKey } from 'src/enum';
|
|
||||||
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
||||||
|
|
||||||
export const getExternalDomain = (server: SystemConfig['server'], port: number) =>
|
export const getExternalDomain = (server: SystemConfig['server'], port: number) =>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { CookieOptions, Response } from 'express';
|
import { CookieOptions, Response } from 'express';
|
||||||
import { Duration } from 'luxon';
|
import { Duration } from 'luxon';
|
||||||
import { CookieResponse, ImmichCookie } from 'src/dtos/auth.dto';
|
import { CookieResponse } from 'src/dtos/auth.dto';
|
||||||
|
import { ImmichCookie } from 'src/enum';
|
||||||
|
|
||||||
export const respondWithCookie = <T>(res: Response, body: T, { isSecure, values }: CookieResponse) => {
|
export const respondWithCookie = <T>(res: Response, body: T, { isSecure, values }: CookieResponse) => {
|
||||||
const defaults: CookieOptions = {
|
const defaults: CookieOptions = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user