refactor(server): calculate asset type server-side

This commit is contained in:
Jason Rasmussen
2023-07-10 15:12:43 -04:00
parent 6180828ed2
commit 120727889f
13 changed files with 74 additions and 253 deletions

View File

@@ -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) {

View File

@@ -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

View File

@@ -21,7 +21,6 @@ describe('UploadService', () => {
it('should upload a single file', async () => {
const data = new FormData();
data.append('assetType', 'image');
uploadService.upload(data);