mirror of
https://github.com/immich-app/immich.git
synced 2026-02-15 05:18:37 +03:00
refactor(server): calculate asset type server-side
This commit is contained in:
@@ -71,7 +71,6 @@ export default class Upload extends BaseCommand {
|
||||
const importData = {
|
||||
assetPath: asset.path,
|
||||
deviceAssetId: asset.deviceAssetId,
|
||||
assetType: asset.assetType,
|
||||
deviceId: this.deviceId,
|
||||
fileCreatedAt: asset.fileCreatedAt,
|
||||
fileModifiedAt: asset.fileModifiedAt,
|
||||
@@ -157,8 +156,6 @@ export default class Upload extends BaseCommand {
|
||||
uploadFormData.append('fileCreatedAt', asset.fileCreatedAt);
|
||||
uploadFormData.append('fileModifiedAt', asset.fileModifiedAt);
|
||||
uploadFormData.append('isFavorite', String(false));
|
||||
uploadFormData.append('fileExtension', asset.fileExtension);
|
||||
uploadFormData.append('assetType', asset.assetType);
|
||||
uploadFormData.append('assetData', asset.assetData, { filename: asset.path });
|
||||
|
||||
if (asset.sidecarData) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -21,7 +21,6 @@ describe('UploadService', () => {
|
||||
|
||||
it('should upload a single file', async () => {
|
||||
const data = new FormData();
|
||||
data.append('assetType', 'image');
|
||||
|
||||
uploadService.upload(data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user