mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
refactor(server): calculate asset type server side (#3200)
* refactor(server): calculate asset type server-side * chore: open api * chore: remove comments * fix: linting * update * Revert "update" This reverts commit dc58702923250b9385d22468a7afe77dc9972a03. * fix: upload LivePhotos * chore: remove unused request fields for upload * remove unused method * mobile-fix: livePhoto filename * fix: revert check for livephotos filename and extension --------- Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
@@ -1,19 +1,14 @@
|
||||
import * as fs from 'fs';
|
||||
import * as mime from 'mime-types';
|
||||
import { basename } from 'node:path';
|
||||
import * as path from 'path';
|
||||
import crypto from 'crypto';
|
||||
import { AssetTypeEnum } from 'src/api/open-api';
|
||||
|
||||
export class CrawledAsset {
|
||||
public path: string;
|
||||
|
||||
public assetType?: AssetTypeEnum;
|
||||
public assetData?: fs.ReadStream;
|
||||
public deviceAssetId?: string;
|
||||
public fileCreatedAt?: string;
|
||||
public fileModifiedAt?: string;
|
||||
public fileExtension?: string;
|
||||
public sidecarData?: Buffer;
|
||||
public sidecarPath?: string;
|
||||
public fileSize!: number;
|
||||
@@ -30,16 +25,8 @@ export class CrawledAsset {
|
||||
async process() {
|
||||
const stats = await fs.promises.stat(this.path);
|
||||
this.deviceAssetId = `${basename(this.path)}-${stats.size}`.replace(/\s+/g, '');
|
||||
|
||||
// TODO: Determine file type from extension only
|
||||
const mimeType = mime.lookup(this.path);
|
||||
if (!mimeType) {
|
||||
throw Error('Cannot determine mime type of asset: ' + this.path);
|
||||
}
|
||||
this.assetType = mimeType.split('/')[0].toUpperCase() as AssetTypeEnum;
|
||||
this.fileCreatedAt = stats.ctime.toISOString();
|
||||
this.fileModifiedAt = stats.mtime.toISOString();
|
||||
this.fileExtension = path.extname(this.path);
|
||||
this.fileSize = stats.size;
|
||||
|
||||
// TODO: doesn't xmp replace the file extension? Will need investigation
|
||||
|
||||
Reference in New Issue
Block a user