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 dc58702923.

* 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:
Jason Rasmussen 2023-07-11 23:56:30 -04:00 committed by GitHub
parent 93462aafbc
commit b71d7e33bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 97 additions and 580 deletions

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