mirror of https://github.com/immich-app/immich.git
refactor(server): common (#2066)
parent
54f98053a8
commit
1efc74dabc
@ -1 +0,0 @@
|
||||
export * from './app.config';
|
||||
@ -1,10 +0,0 @@
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
|
||||
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.');
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
export * from './config';
|
||||
export * from './constants';
|
||||
export * from './utils';
|
||||
@ -1,20 +0,0 @@
|
||||
import { assetUtils } from './asset-utils';
|
||||
|
||||
describe('Asset Utilities', () => {
|
||||
describe('isWebPlayable', () => {
|
||||
it('Check that it returns true with mimetype webm', () => {
|
||||
const result = assetUtils.isWebPlayable('video/webm');
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
|
||||
it('Check that returns true with mimetype mp4', () => {
|
||||
const result = assetUtils.isWebPlayable('video/mp4');
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
|
||||
it('Check that returns false with mimetype quicktime', () => {
|
||||
const result = assetUtils.isWebPlayable('video/quicktime');
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,48 +0,0 @@
|
||||
import { AssetEntity } from '@app/infra/db/entities';
|
||||
import { AssetResponseDto } from '@app/domain';
|
||||
import fs from 'fs';
|
||||
|
||||
const deleteFiles = (asset: AssetEntity | AssetResponseDto) => {
|
||||
fs.unlink(asset.originalPath, (err) => {
|
||||
if (err) {
|
||||
console.log('error deleting ', asset.originalPath);
|
||||
}
|
||||
});
|
||||
|
||||
// TODO: what if there is no asset.resizePath. Should fail the Job?
|
||||
// => panoti report: Job not fail
|
||||
if (asset.resizePath) {
|
||||
fs.unlink(asset.resizePath, (err) => {
|
||||
if (err) {
|
||||
console.log('error deleting ', asset.resizePath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (asset.webpPath) {
|
||||
fs.unlink(asset.webpPath, (err) => {
|
||||
if (err) {
|
||||
console.log('error deleting ', asset.webpPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (asset.encodedVideoPath) {
|
||||
fs.unlink(asset.encodedVideoPath, (err) => {
|
||||
if (err) {
|
||||
console.log('error deleting ', asset.encodedVideoPath);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const isWebPlayable = (mimeType: string | null): boolean => {
|
||||
const WEB_PLAYABLE = ['video/webm', 'video/mp4'];
|
||||
|
||||
if (mimeType !== null) {
|
||||
return WEB_PLAYABLE.includes(mimeType);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
export const assetUtils = { deleteFiles, isWebPlayable };
|
||||
@ -1,14 +0,0 @@
|
||||
import { LogLevel } from '@nestjs/common';
|
||||
|
||||
export * from './time-utils';
|
||||
export * from './asset-utils';
|
||||
|
||||
export function getLogLevels() {
|
||||
const LOG_LEVELS: LogLevel[] = ['verbose', 'debug', 'log', 'warn', 'error'];
|
||||
let logLevel = process.env.LOG_LEVEL || 'log';
|
||||
if (logLevel === 'simple') {
|
||||
logLevel = 'log';
|
||||
}
|
||||
const logLevelIndex = LOG_LEVELS.indexOf(logLevel as LogLevel);
|
||||
return logLevelIndex === -1 ? [] : LOG_LEVELS.slice(logLevelIndex);
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
// create unit test for time utils
|
||||
|
||||
import { timeUtils } from './time-utils';
|
||||
|
||||
describe('Time Utilities', () => {
|
||||
describe('timezone', () => {
|
||||
it('should always be UTC', () => {
|
||||
expect(new Date().getTimezoneOffset()).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkValidTimestamp', () => {
|
||||
it('check for year 0000', () => {
|
||||
const result = timeUtils.checkValidTimestamp('0000-00-00T00:00:00.000Z');
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
|
||||
it('check for 6-digits year with plus sign', () => {
|
||||
const result = timeUtils.checkValidTimestamp('+12345-00-00T00:00:00.000Z');
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
|
||||
it('check for 6-digits year with negative sign', () => {
|
||||
const result = timeUtils.checkValidTimestamp('-12345-00-00T00:00:00.000Z');
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
|
||||
it('check for current date', () => {
|
||||
const result = timeUtils.checkValidTimestamp(new Date().toISOString());
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
|
||||
it('check for year before 1583', () => {
|
||||
const result = timeUtils.checkValidTimestamp('1582-12-31T23:59:59.999Z');
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
|
||||
it('check for year after 9999', () => {
|
||||
const result = timeUtils.checkValidTimestamp('10000-00-00T00:00:00.000Z');
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,21 +0,0 @@
|
||||
function createTimeUtils() {
|
||||
const checkValidTimestamp = (timestamp: string): boolean => {
|
||||
const parsedTimestamp = Date.parse(timestamp);
|
||||
|
||||
if (isNaN(parsedTimestamp)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const date = new Date(parsedTimestamp);
|
||||
|
||||
if (date.getFullYear() < 1583 || date.getFullYear() > 9999) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return date.getFullYear() > 0;
|
||||
};
|
||||
|
||||
return { checkValidTimestamp };
|
||||
}
|
||||
|
||||
export const timeUtils = createTimeUtils();
|
||||
@ -1,9 +0,0 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"outDir": "../../dist/libs/common"
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist", "test", "**/*spec.ts"]
|
||||
}
|
||||
Loading…
Reference in New Issue