2023-03-24 05:55:15 +01:00
|
|
|
import { BadRequestException } from '@nestjs/common';
|
2023-07-10 19:56:45 +02:00
|
|
|
import { extname } from 'node:path';
|
2023-06-08 17:01:07 +02:00
|
|
|
import pkg from 'src/../../package.json';
|
2023-01-24 04:46:37 +01:00
|
|
|
|
|
|
|
const [major, minor, patch] = pkg.version.split('.');
|
2022-03-22 07:22:04 +01:00
|
|
|
|
2022-07-09 04:26:50 +02:00
|
|
|
export interface IServerVersion {
|
|
|
|
major: number;
|
|
|
|
minor: number;
|
|
|
|
patch: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const serverVersion: IServerVersion = {
|
2023-01-24 04:46:37 +01:00
|
|
|
major: Number(major),
|
|
|
|
minor: Number(minor),
|
|
|
|
patch: Number(patch),
|
2022-03-22 07:22:04 +01:00
|
|
|
};
|
2022-12-08 16:53:18 +01:00
|
|
|
|
|
|
|
export const SERVER_VERSION = `${serverVersion.major}.${serverVersion.minor}.${serverVersion.patch}`;
|
2023-03-22 03:49:19 +01:00
|
|
|
|
2023-03-25 15:50:57 +01:00
|
|
|
export const APP_MEDIA_LOCATION = process.env.IMMICH_MEDIA_LOCATION || './upload';
|
2023-03-24 05:55:15 +01:00
|
|
|
|
|
|
|
export const MACHINE_LEARNING_URL = process.env.IMMICH_MACHINE_LEARNING_URL || 'http://immich-machine-learning:3003';
|
|
|
|
export const MACHINE_LEARNING_ENABLED = MACHINE_LEARNING_URL !== 'false';
|
|
|
|
|
|
|
|
export function assertMachineLearningEnabled() {
|
|
|
|
if (!MACHINE_LEARNING_ENABLED) {
|
|
|
|
throw new BadRequestException('Machine learning is not enabled.');
|
|
|
|
}
|
|
|
|
}
|
feat(server): support for read-only assets and importing existing items in the filesystem (#2715)
* Added read-only flag for assets, endpoint to trigger file import vs upload
* updated fixtures with new property
* if upload is 'read-only', ensure there is no existing asset at the designated originalPath
* added test for file import as well as detecting existing image at read-only destination location
* Added storage service test for a case where it should not move read-only assets
* upload doesn't need the read-only flag available, just importing
* default isReadOnly on import endpoint to true
* formatting fixes
* create-asset dto needs isReadOnly, so set it to false by default on create, updated api generation
* updated code to reflect changes in MR
* fixed read stream promise return type
* new index for originalPath, check for existing path on import, reglardless of user, to prevent duplicates
* refactor: import asset
* chore: open api
* chore: tests
* Added externalPath support for individual users, updated UI to allow this to be set by admin
* added missing var for externalPath in ui
* chore: open api
* fix: compilation issues
* fix: server test
* built api, fixed user-response dto to include externalPath
* reverted accidental commit
* bad commit of duplicate externalPath in user response dto
* fixed tests to include externalPath on expected result
* fix: unit tests
* centralized supported filetypes, perform file type checking of asset and sidecar during file import process
* centralized supported filetype check method to keep regex DRY
* fixed typo
* combined migrations into one
* update api
* Removed externalPath from shared-link code, added column to admin user page whether external paths / import is enabled or not
* update mimetype
* Fixed detect correct mimetype
* revert asset-upload config
* reverted domain.constant
* refactor
* fix mime-type issue
* fix format
---------
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
2023-06-22 04:33:20 +02:00
|
|
|
|
2023-07-10 19:56:45 +02:00
|
|
|
const profile: Record<string, string> = {
|
|
|
|
'.avif': 'image/avif',
|
|
|
|
'.dng': 'image/x-adobe-dng',
|
|
|
|
'.heic': 'image/heic',
|
|
|
|
'.heif': 'image/heif',
|
|
|
|
'.jpeg': 'image/jpeg',
|
|
|
|
'.jpg': 'image/jpeg',
|
|
|
|
'.png': 'image/png',
|
|
|
|
'.webp': 'image/webp',
|
|
|
|
};
|
|
|
|
|
|
|
|
const image: Record<string, string> = {
|
|
|
|
...profile,
|
|
|
|
'.3fr': 'image/x-hasselblad-3fr',
|
|
|
|
'.ari': 'image/x-arriflex-ari',
|
|
|
|
'.arw': 'image/x-sony-arw',
|
|
|
|
'.cap': 'image/x-phaseone-cap',
|
|
|
|
'.cin': 'image/x-phantom-cin',
|
|
|
|
'.cr2': 'image/x-canon-cr2',
|
|
|
|
'.cr3': 'image/x-canon-cr3',
|
|
|
|
'.crw': 'image/x-canon-crw',
|
|
|
|
'.dcr': 'image/x-kodak-dcr',
|
|
|
|
'.erf': 'image/x-epson-erf',
|
|
|
|
'.fff': 'image/x-hasselblad-fff',
|
|
|
|
'.gif': 'image/gif',
|
|
|
|
'.iiq': 'image/x-phaseone-iiq',
|
|
|
|
'.k25': 'image/x-kodak-k25',
|
|
|
|
'.kdc': 'image/x-kodak-kdc',
|
|
|
|
'.mrw': 'image/x-minolta-mrw',
|
|
|
|
'.nef': 'image/x-nikon-nef',
|
|
|
|
'.orf': 'image/x-olympus-orf',
|
|
|
|
'.ori': 'image/x-olympus-ori',
|
|
|
|
'.pef': 'image/x-pentax-pef',
|
|
|
|
'.raf': 'image/x-fuji-raf',
|
|
|
|
'.raw': 'image/x-panasonic-raw',
|
|
|
|
'.rwl': 'image/x-leica-rwl',
|
|
|
|
'.sr2': 'image/x-sony-sr2',
|
|
|
|
'.srf': 'image/x-sony-srf',
|
|
|
|
'.srw': 'image/x-samsung-srw',
|
|
|
|
'.tiff': 'image/tiff',
|
|
|
|
'.x3f': 'image/x-sigma-x3f',
|
|
|
|
};
|
|
|
|
|
|
|
|
const video: Record<string, string> = {
|
|
|
|
'.3gp': 'video/3gpp',
|
|
|
|
'.avi': 'video/x-msvideo',
|
|
|
|
'.flv': 'video/x-flv',
|
|
|
|
'.mkv': 'video/x-matroska',
|
|
|
|
'.mov': 'video/quicktime',
|
|
|
|
'.mp2t': 'video/mp2t',
|
|
|
|
'.mp4': 'video/mp4',
|
|
|
|
'.mpeg': 'video/mpeg',
|
|
|
|
'.webm': 'video/webm',
|
|
|
|
'.wmv': 'video/x-ms-wmv',
|
|
|
|
};
|
|
|
|
|
|
|
|
const sidecar: Record<string, string> = {
|
|
|
|
'.xmp': 'application/xml',
|
|
|
|
};
|
|
|
|
|
|
|
|
const isType = (filename: string, lookup: Record<string, string>) => !!lookup[extname(filename).toLowerCase()];
|
|
|
|
const getType = (filename: string, lookup: Record<string, string>) => lookup[extname(filename).toLowerCase()];
|
|
|
|
|
|
|
|
export const mimeTypes = {
|
|
|
|
image,
|
|
|
|
profile,
|
|
|
|
sidecar,
|
|
|
|
video,
|
|
|
|
|
|
|
|
isAsset: (filename: string) => isType(filename, image) || isType(filename, video),
|
|
|
|
isProfile: (filename: string) => isType(filename, profile),
|
|
|
|
isSidecar: (filename: string) => isType(filename, sidecar),
|
|
|
|
isVideo: (filename: string) => isType(filename, video),
|
|
|
|
lookup: (filename: string) => getType(filename, { ...image, ...video, ...sidecar }) || 'application/octet-stream',
|
|
|
|
};
|