From b71d7e33bb2e0c6fc3426e79a6d7c7ae898695da Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Tue, 11 Jul 2023 23:56:30 -0400 Subject: [PATCH] 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 --- cli/src/api/open-api/api.ts | 48 +----- cli/src/commands/upload.ts | 3 - cli/src/cores/models/crawled-asset.ts | 13 -- cli/src/services/upload.service.spec.ts | 1 - .../backup/services/backup.service.dart | 22 +-- mobile/lib/shared/services/user.service.dart | 8 - mobile/lib/utils/files_helper.dart | 150 ------------------ mobile/openapi/doc/AssetApi.md | Bin 56107 -> 55860 bytes mobile/openapi/doc/ImportAssetDto.md | Bin 917 -> 857 bytes mobile/openapi/lib/api/asset_api.dart | Bin 51103 -> 50527 bytes .../openapi/lib/model/import_asset_dto.dart | Bin 7612 -> 7345 bytes mobile/openapi/test/asset_api_test.dart | Bin 5342 -> 5295 bytes .../openapi/test/import_asset_dto_test.dart | Bin 1758 -> 1648 bytes server/immich-openapi-specs.json | 12 -- server/src/domain/domain.constant.ts | 16 +- server/src/immich/api-v1/asset/asset.core.ts | 4 +- .../immich/api-v1/asset/asset.service.spec.ts | 1 - .../api-v1/asset/dto/create-asset.dto.ts | 11 +- web/src/api/open-api/api.ts | 52 +----- .../upload-asset-preview.svelte | 3 +- web/src/lib/models/upload-asset.ts | 1 - web/src/lib/utils/asset-utils.spec.ts | 87 +--------- web/src/lib/utils/asset-utils.ts | 60 ------- web/src/lib/utils/file-uploader.ts | 137 +++++++--------- 24 files changed, 90 insertions(+), 539 deletions(-) delete mode 100644 mobile/lib/utils/files_helper.dart diff --git a/cli/src/api/open-api/api.ts b/cli/src/api/open-api/api.ts index a4cb44696e..da189929ca 100644 --- a/cli/src/api/open-api/api.ts +++ b/cli/src/api/open-api/api.ts @@ -1375,12 +1375,6 @@ export interface GetAssetCountByTimeBucketDto { * @interface ImportAssetDto */ export interface ImportAssetDto { - /** - * - * @type {AssetTypeEnum} - * @memberof ImportAssetDto - */ - 'assetType': AssetTypeEnum; /** * * @type {boolean} @@ -1448,8 +1442,6 @@ export interface ImportAssetDto { */ 'duration'?: string; } - - /** * * @export @@ -5690,9 +5682,7 @@ export const AssetApiAxiosParamCreator = function (configuration?: Configuration }, /** * - * @param {AssetTypeEnum} assetType * @param {File} assetData - * @param {string} fileExtension * @param {string} deviceAssetId * @param {string} deviceId * @param {string} fileCreatedAt @@ -5708,13 +5698,9 @@ export const AssetApiAxiosParamCreator = function (configuration?: Configuration * @param {*} [options] Override http request option. * @throws {RequiredError} */ - uploadFile: async (assetType: AssetTypeEnum, assetData: File, fileExtension: string, deviceAssetId: string, deviceId: string, fileCreatedAt: string, fileModifiedAt: string, isFavorite: boolean, key?: string, livePhotoData?: File, sidecarData?: File, isReadOnly?: boolean, isArchived?: boolean, isVisible?: boolean, duration?: string, options: AxiosRequestConfig = {}): Promise => { - // verify required parameter 'assetType' is not null or undefined - assertParamExists('uploadFile', 'assetType', assetType) + uploadFile: async (assetData: File, deviceAssetId: string, deviceId: string, fileCreatedAt: string, fileModifiedAt: string, isFavorite: boolean, key?: string, livePhotoData?: File, sidecarData?: File, isReadOnly?: boolean, isArchived?: boolean, isVisible?: boolean, duration?: string, options: AxiosRequestConfig = {}): Promise => { // verify required parameter 'assetData' is not null or undefined assertParamExists('uploadFile', 'assetData', assetData) - // verify required parameter 'fileExtension' is not null or undefined - assertParamExists('uploadFile', 'fileExtension', fileExtension) // verify required parameter 'deviceAssetId' is not null or undefined assertParamExists('uploadFile', 'deviceAssetId', deviceAssetId) // verify required parameter 'deviceId' is not null or undefined @@ -5752,10 +5738,6 @@ export const AssetApiAxiosParamCreator = function (configuration?: Configuration } - if (assetType !== undefined) { - localVarFormParams.append('assetType', new Blob([JSON.stringify(assetType)], { type: "application/json", })); - } - if (assetData !== undefined) { localVarFormParams.append('assetData', assetData as any); } @@ -5772,10 +5754,6 @@ export const AssetApiAxiosParamCreator = function (configuration?: Configuration localVarFormParams.append('isReadOnly', isReadOnly as any); } - if (fileExtension !== undefined) { - localVarFormParams.append('fileExtension', fileExtension as any); - } - if (deviceAssetId !== undefined) { localVarFormParams.append('deviceAssetId', deviceAssetId as any); } @@ -6089,9 +6067,7 @@ export const AssetApiFp = function(configuration?: Configuration) { }, /** * - * @param {AssetTypeEnum} assetType * @param {File} assetData - * @param {string} fileExtension * @param {string} deviceAssetId * @param {string} deviceId * @param {string} fileCreatedAt @@ -6107,8 +6083,8 @@ export const AssetApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async uploadFile(assetType: AssetTypeEnum, assetData: File, fileExtension: string, deviceAssetId: string, deviceId: string, fileCreatedAt: string, fileModifiedAt: string, isFavorite: boolean, key?: string, livePhotoData?: File, sidecarData?: File, isReadOnly?: boolean, isArchived?: boolean, isVisible?: boolean, duration?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.uploadFile(assetType, assetData, fileExtension, deviceAssetId, deviceId, fileCreatedAt, fileModifiedAt, isFavorite, key, livePhotoData, sidecarData, isReadOnly, isArchived, isVisible, duration, options); + async uploadFile(assetData: File, deviceAssetId: string, deviceId: string, fileCreatedAt: string, fileModifiedAt: string, isFavorite: boolean, key?: string, livePhotoData?: File, sidecarData?: File, isReadOnly?: boolean, isArchived?: boolean, isVisible?: boolean, duration?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.uploadFile(assetData, deviceAssetId, deviceId, fileCreatedAt, fileModifiedAt, isFavorite, key, livePhotoData, sidecarData, isReadOnly, isArchived, isVisible, duration, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, } @@ -6339,7 +6315,7 @@ export const AssetApiFactory = function (configuration?: Configuration, basePath * @throws {RequiredError} */ uploadFile(requestParameters: AssetApiUploadFileRequest, options?: AxiosRequestConfig): AxiosPromise { - return localVarFp.uploadFile(requestParameters.assetType, requestParameters.assetData, requestParameters.fileExtension, requestParameters.deviceAssetId, requestParameters.deviceId, requestParameters.fileCreatedAt, requestParameters.fileModifiedAt, requestParameters.isFavorite, requestParameters.key, requestParameters.livePhotoData, requestParameters.sidecarData, requestParameters.isReadOnly, requestParameters.isArchived, requestParameters.isVisible, requestParameters.duration, options).then((request) => request(axios, basePath)); + return localVarFp.uploadFile(requestParameters.assetData, requestParameters.deviceAssetId, requestParameters.deviceId, requestParameters.fileCreatedAt, requestParameters.fileModifiedAt, requestParameters.isFavorite, requestParameters.key, requestParameters.livePhotoData, requestParameters.sidecarData, requestParameters.isReadOnly, requestParameters.isArchived, requestParameters.isVisible, requestParameters.duration, options).then((request) => request(axios, basePath)); }, }; }; @@ -6763,13 +6739,6 @@ export interface AssetApiUpdateAssetRequest { * @interface AssetApiUploadFileRequest */ export interface AssetApiUploadFileRequest { - /** - * - * @type {AssetTypeEnum} - * @memberof AssetApiUploadFile - */ - readonly assetType: AssetTypeEnum - /** * * @type {File} @@ -6777,13 +6746,6 @@ export interface AssetApiUploadFileRequest { */ readonly assetData: File - /** - * - * @type {string} - * @memberof AssetApiUploadFile - */ - readonly fileExtension: string - /** * * @type {string} @@ -7143,7 +7105,7 @@ export class AssetApi extends BaseAPI { * @memberof AssetApi */ public uploadFile(requestParameters: AssetApiUploadFileRequest, options?: AxiosRequestConfig) { - return AssetApiFp(this.configuration).uploadFile(requestParameters.assetType, requestParameters.assetData, requestParameters.fileExtension, requestParameters.deviceAssetId, requestParameters.deviceId, requestParameters.fileCreatedAt, requestParameters.fileModifiedAt, requestParameters.isFavorite, requestParameters.key, requestParameters.livePhotoData, requestParameters.sidecarData, requestParameters.isReadOnly, requestParameters.isArchived, requestParameters.isVisible, requestParameters.duration, options).then((request) => request(this.axios, this.basePath)); + return AssetApiFp(this.configuration).uploadFile(requestParameters.assetData, requestParameters.deviceAssetId, requestParameters.deviceId, requestParameters.fileCreatedAt, requestParameters.fileModifiedAt, requestParameters.isFavorite, requestParameters.key, requestParameters.livePhotoData, requestParameters.sidecarData, requestParameters.isReadOnly, requestParameters.isArchived, requestParameters.isVisible, requestParameters.duration, options).then((request) => request(this.axios, this.basePath)); } } diff --git a/cli/src/commands/upload.ts b/cli/src/commands/upload.ts index 5ded203f9b..fcff0edbaf 100644 --- a/cli/src/commands/upload.ts +++ b/cli/src/commands/upload.ts @@ -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) { diff --git a/cli/src/cores/models/crawled-asset.ts b/cli/src/cores/models/crawled-asset.ts index 6e93327b60..41bc934427 100644 --- a/cli/src/cores/models/crawled-asset.ts +++ b/cli/src/cores/models/crawled-asset.ts @@ -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 diff --git a/cli/src/services/upload.service.spec.ts b/cli/src/services/upload.service.spec.ts index 9215a851c3..7c1dfc0365 100644 --- a/cli/src/services/upload.service.spec.ts +++ b/cli/src/services/upload.service.spec.ts @@ -21,7 +21,6 @@ describe('UploadService', () => { it('should upload a single file', async () => { const data = new FormData(); - data.append('assetType', 'image'); uploadService.upload(data); diff --git a/mobile/lib/modules/backup/services/backup.service.dart b/mobile/lib/modules/backup/services/backup.service.dart index cedc9e4886..520c8310bf 100644 --- a/mobile/lib/modules/backup/services/backup.service.dart +++ b/mobile/lib/modules/backup/services/backup.service.dart @@ -14,15 +14,13 @@ import 'package:immich_mobile/shared/models/store.dart'; import 'package:immich_mobile/shared/providers/api.provider.dart'; import 'package:immich_mobile/shared/providers/db.provider.dart'; import 'package:immich_mobile/shared/services/api.service.dart'; -import 'package:immich_mobile/utils/files_helper.dart'; import 'package:isar/isar.dart'; import 'package:logging/logging.dart'; import 'package:openapi/api.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:photo_manager/photo_manager.dart'; -import 'package:http_parser/http_parser.dart'; -import 'package:path/path.dart' as p; import 'package:cancellation_token_http/http.dart' as http; +import 'package:path/path.dart' as p; final backupServiceProvider = Provider( (ref) => BackupService( @@ -230,18 +228,12 @@ class BackupService { if (file != null) { String originalFileName = await entity.titleAsync; - var fileExtension = p.extension(file.path); - var mimeType = FileHelper.getMimeType(file.path); var fileStream = file.openRead(); var assetRawUploadData = http.MultipartFile( "assetData", fileStream, file.lengthSync(), filename: originalFileName, - contentType: MediaType( - mimeType["type"], - mimeType["subType"], - ), ); var req = MultipartRequest( @@ -256,12 +248,10 @@ class BackupService { req.fields['deviceAssetId'] = entity.id; req.fields['deviceId'] = deviceId; - req.fields['assetType'] = _getAssetType(entity.type); req.fields['fileCreatedAt'] = entity.createDateTime.toIso8601String(); req.fields['fileModifiedAt'] = entity.modifiedDateTime.toIso8601String(); req.fields['isFavorite'] = entity.isFavorite.toString(); - req.fields['fileExtension'] = fileExtension; req.fields['duration'] = entity.videoDuration.toString(); req.files.add(assetRawUploadData); @@ -342,18 +332,12 @@ class BackupService { var validPath = motionFilePath.replaceAll('file://', ''); var motionFile = File(validPath); var fileStream = motionFile.openRead(); - String originalFileName = await entity.titleAsync; - var mimeType = FileHelper.getMimeType(validPath); - + String fileName = p.basename(motionFile.path); return http.MultipartFile( "livePhotoData", fileStream, motionFile.lengthSync(), - filename: originalFileName, - contentType: MediaType( - mimeType["type"], - mimeType["subType"], - ), + filename: fileName, ); } diff --git a/mobile/lib/shared/services/user.service.dart b/mobile/lib/shared/services/user.service.dart index 89cf25f649..51e3cbc25a 100644 --- a/mobile/lib/shared/services/user.service.dart +++ b/mobile/lib/shared/services/user.service.dart @@ -1,7 +1,6 @@ import 'package:collection/collection.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:http/http.dart'; -import 'package:http_parser/http_parser.dart'; import 'package:image_picker/image_picker.dart'; import 'package:immich_mobile/modules/partner/services/partner.service.dart'; import 'package:immich_mobile/shared/models/store.dart'; @@ -11,7 +10,6 @@ import 'package:immich_mobile/shared/providers/db.provider.dart'; import 'package:immich_mobile/shared/services/api.service.dart'; import 'package:immich_mobile/shared/services/sync.service.dart'; import 'package:immich_mobile/utils/diff.dart'; -import 'package:immich_mobile/utils/files_helper.dart'; import 'package:isar/isar.dart'; import 'package:logging/logging.dart'; import 'package:openapi/api.dart'; @@ -59,17 +57,11 @@ class UserService { Future uploadProfileImage(XFile image) async { try { - var mimeType = FileHelper.getMimeType(image.path); - return await _apiService.userApi.createProfileImage( MultipartFile.fromBytes( 'file', await image.readAsBytes(), filename: image.name, - contentType: MediaType( - mimeType["type"], - mimeType["subType"], - ), ), ); } catch (e) { diff --git a/mobile/lib/utils/files_helper.dart b/mobile/lib/utils/files_helper.dart deleted file mode 100644 index ec93cd0974..0000000000 --- a/mobile/lib/utils/files_helper.dart +++ /dev/null @@ -1,150 +0,0 @@ -import 'package:path/path.dart' as p; - -class FileHelper { - static getMimeType(String filePath) { - var fileExtension = p.extension(filePath).split(".")[1]; - - switch (fileExtension.toLowerCase()) { - case 'gif': - return {"type": "image", "subType": "gif"}; - - case 'jpeg': - return {"type": "image", "subType": "jpeg"}; - - case 'jpg': - return {"type": "image", "subType": "jpeg"}; - - case 'png': - return {"type": "image", "subType": "png"}; - - case 'tif': - return {"type": "image", "subType": "tiff"}; - - case 'mov': - return {"type": "video", "subType": "quicktime"}; - - case 'mp4': - return {"type": "video", "subType": "mp4"}; - - case 'avi': - return {"type": "video", "subType": "x-msvideo"}; - - case 'heic': - return {"type": "image", "subType": "heic"}; - - case 'heif': - return {"type": "image", "subType": "heif"}; - - case 'dng': - return {"type": "image", "subType": "dng"}; - - case 'webp': - return {"type": "image", "subType": "webp"}; - - case '3gp': - return {"type": "video", "subType": "3gpp"}; - - case 'webm': - return {"type": "video", "subType": "webm"}; - - case 'avif': - return {"type": "image", "subType": "avif"}; - - case 'insp': - return {"type": "image", "subType": "jpeg"}; - - case 'insv': - return {"type": "video", "subType": "mp4"}; - - case 'arw': - return {"type": "image", "subType": "x-sony-arw"}; - - case 'raf': - return {"type": "image", "subType": "x-fuji-raf"}; - - case 'nef': - return {"type": "image", "subType": "x-nikon-nef"}; - - case 'srw': - return {"type": "image", "subType": "x-samsung-srw"}; - - case 'crw': - return {"type": "image", "subType": "x-canon-crw"}; - - case 'cr2': - return {"type": "image", "subType": "x-canon-cr2"}; - - case 'cr3': - return {"type": "image", "subType": "x-canon-cr3"}; - - case 'erf': - return {"type": "image", "subType": "x-epson-erf"}; - - case 'dcr': - return {"type": "image", "subType": "x-kodak-dcr"}; - - case 'k25': - return {"type": "image", "subType": "x-kodak-k25"}; - - case 'kdc': - return {"type": "image", "subType": "x-kodak-kdc"}; - - case 'mrw': - return {"type": "image", "subType": "x-minolta-mrw"}; - - case 'orf': - return {"type": "image", "subType": "x-olympus-orf"}; - - case 'raw': - return {"type": "image", "subType": "x-panasonic-raw"}; - - case 'pef': - return {"type": "image", "subType": "x-panasonic-pef"}; - - case 'x3f': - return {"type": "image", "subType": "x-sigma-x3f"}; - - case 'srf': - return {"type": "image", "subType": "x-sony-srf"}; - - case 'sr2': - return {"type": "image", "subType": "x-sony-sr2"}; - - case '3fr': - return {"type": "image", "subType": "x-hasselblad-3fr"}; - - case 'fff': - return {"type": "image", "subType": "x-hasselblad-fff"}; - - case 'rwl': - return {"type": "image", "subType": "x-leica-rwl"}; - - case 'ori': - return {"type": "image", "subType": "x-olympus-ori"}; - - case 'iiq': - return {"type": "image", "subType": "x-phaseone-iiq"}; - - case 'ari': - return {"type": "image", "subType": "x-arriflex-ari"}; - - case 'cap': - return {"type": "image", "subType": "x-phaseone-cap"}; - - case 'cin': - return {"type": "image", "subType": "x-phantom-cin"}; - - case 'jxl': - return {"type": "image", "subType": "jxl"}; - - case 'mts': - return {"type": "video", "subType": "mp2t"}; - - case 'm2ts': - return {"type": "video", "subType": "mp2t"}; - - default: - return {"type": "unsupport", "subType": "unsupport"}; - } - } -} diff --git a/mobile/openapi/doc/AssetApi.md b/mobile/openapi/doc/AssetApi.md index c71b4151d3adf98aef58c2fbed5757cba6e74eaf..998836d09f6650227b8491db5b1e2e8732a4bd82 100644 GIT binary patch delta 50 zcmZ3zjd{x!<_!U7SzHoJ5;y0a-NiCF;F9s?y_d?Fz(SMr&Q6~E^y=fuEZ3Dc`&_@z F3;<%v7{UMm delta 252 zcmdn8g?aTh<_!U7cNRGxPH%@3}I0^YgRn zEE*tn3bqQ?3i|pAjv&<_0oT0JT!k71uC&aknrlj|=V%c7V8)P=&I9C%QC@&t3X z&5oDKnF!dwdC!$HMq`jwT3SGhqP4V8?AFqX)j$!@%T3X&Q2?r(ta(j`7uDJcha@(K IUc1i>00F~bs{jB1 diff --git a/mobile/openapi/doc/ImportAssetDto.md b/mobile/openapi/doc/ImportAssetDto.md index da612b0abccf785753179fa9a0657540e8afbc85..408e3519cf28b7555c279812794a64d47b2b3d93 100644 GIT binary patch delta 11 ScmbQrev@s&&CQ~W4NL$WX9O?+ delta 68 zcmcb~HkEzCP0PgM;?$Cm%7RoaErl9|Xe}*An1E|uX|9%5tOkmJUT%seP#q9$yw=PF E0ATbOk^lez diff --git a/mobile/openapi/lib/api/asset_api.dart b/mobile/openapi/lib/api/asset_api.dart index a73ec3b1ec224aede71ed2ee04971bd69a7d4a17..1c609a7277d05ec9717ebdc548150f4ac9609a30 100644 GIT binary patch delta 88 zcmbQ=&wRg&dBcN^lcyczpKNkKck`qJHyJ12w&$9hvPFFInnMbkPi^_hwAp5d0n_4- hyI7HwF)~4=85t)l@QF|Uby$YQC9x!Nv&oTcW&oNFDM0`L delta 373 zcmccL#XP^CdBcN^lNFR%g+nR}QeE>(b7K_}i;GiBK-|d_5@aSn*l5F>mYI|4T2Ydk zSDcxj2NvBhk#DoorZ0?=jxfa_y$G#33X|s?P(anVS$7K)Gc(ZO$rHG~Hv8=qWF^}_ml-FQ9MB-qPh5lF84Qc_iZx8DPvzip32$M@4 Eap74Lz5oCK delta 255 zcmdmJxyO1#9iv21YGG++QEG}pNk(R|USe@^YDq|CL8{K?N=9QwaYq>6HLo;R0WQ0F zInzBhF*sMj))q;wjFW>&6fUQikyxDJoS%}asi3{Ng8MQfLYu7$T$PT(W^djsMj5z( zdaQyinv*s! = { const isType = (filename: string, lookup: Record) => !!lookup[extname(filename).toLowerCase()]; const getType = (filename: string, lookup: Record) => lookup[extname(filename).toLowerCase()]; +const lookup = (filename: string) => + getType(filename, { ...image, ...video, ...sidecar }) || 'application/octet-stream'; export const mimeTypes = { image, @@ -102,5 +105,16 @@ export const mimeTypes = { isProfile: (filename: string) => isType(filename, profile), isSidecar: (filename: string) => isType(filename, sidecar), isVideo: (filename: string) => isType(filename, video), - lookup: (filename: string) => getType(filename, { ...image, ...video, ...sidecar }) || 'application/octet-stream', + lookup, + assetType: (filename: string) => { + const contentType = lookup(filename).split('/')[0]; + switch (contentType) { + case 'image': + return AssetType.IMAGE; + case 'video': + return AssetType.VIDEO; + default: + return AssetType.OTHER; + } + }, }; diff --git a/server/src/immich/api-v1/asset/asset.core.ts b/server/src/immich/api-v1/asset/asset.core.ts index 7508e4f6c0..28a140a46e 100644 --- a/server/src/immich/api-v1/asset/asset.core.ts +++ b/server/src/immich/api-v1/asset/asset.core.ts @@ -1,4 +1,4 @@ -import { AuthUserDto, IJobRepository, JobName, UploadFile } from '@app/domain'; +import { AuthUserDto, IJobRepository, JobName, mimeTypes, UploadFile } from '@app/domain'; import { AssetEntity, UserEntity } from '@app/infra/entities'; import { parse } from 'node:path'; import { IAssetRepository } from './asset-repository'; @@ -26,7 +26,7 @@ export class AssetCore { fileCreatedAt: dto.fileCreatedAt, fileModifiedAt: dto.fileModifiedAt, - type: dto.assetType, + type: mimeTypes.assetType(file.originalPath), isFavorite: dto.isFavorite, isArchived: dto.isArchived ?? false, duration: dto.duration || null, diff --git a/server/src/immich/api-v1/asset/asset.service.spec.ts b/server/src/immich/api-v1/asset/asset.service.spec.ts index f0115a34b4..97725f149e 100644 --- a/server/src/immich/api-v1/asset/asset.service.spec.ts +++ b/server/src/immich/api-v1/asset/asset.service.spec.ts @@ -32,7 +32,6 @@ const _getCreateAssetDto = (): CreateAssetDto => { const createAssetDto = new CreateAssetDto(); createAssetDto.deviceAssetId = 'deviceAssetId'; createAssetDto.deviceId = 'deviceId'; - createAssetDto.assetType = AssetType.OTHER; createAssetDto.fileCreatedAt = new Date('2022-06-19T23:41:36.910Z'); createAssetDto.fileModifiedAt = new Date('2022-06-19T23:41:36.910Z'); createAssetDto.isFavorite = false; diff --git a/server/src/immich/api-v1/asset/dto/create-asset.dto.ts b/server/src/immich/api-v1/asset/dto/create-asset.dto.ts index 590296a1ec..512da5605f 100644 --- a/server/src/immich/api-v1/asset/dto/create-asset.dto.ts +++ b/server/src/immich/api-v1/asset/dto/create-asset.dto.ts @@ -1,8 +1,7 @@ import { toBoolean, toSanitized, UploadFieldName } from '@app/domain'; -import { AssetType } from '@app/infra/entities'; import { ApiProperty } from '@nestjs/swagger'; import { Transform } from 'class-transformer'; -import { IsBoolean, IsEnum, IsNotEmpty, IsOptional, IsString } from 'class-validator'; +import { IsBoolean, IsNotEmpty, IsOptional, IsString } from 'class-validator'; export class CreateAssetBase { @IsNotEmpty() @@ -11,11 +10,6 @@ export class CreateAssetBase { @IsNotEmpty() deviceId!: string; - @IsNotEmpty() - @IsEnum(AssetType) - @ApiProperty({ enumName: 'AssetTypeEnum', enum: AssetType }) - assetType!: AssetType; - @IsNotEmpty() fileCreatedAt!: Date; @@ -43,9 +37,6 @@ export class CreateAssetDto extends CreateAssetBase { @Transform(toBoolean) isReadOnly?: boolean = false; - @IsNotEmpty() - fileExtension!: string; - // The properties below are added to correctly generate the API docs // and client SDKs. Validation should be handled in the controller. @ApiProperty({ type: 'string', format: 'binary' }) diff --git a/web/src/api/open-api/api.ts b/web/src/api/open-api/api.ts index 3ca2b95a60..89633647cf 100644 --- a/web/src/api/open-api/api.ts +++ b/web/src/api/open-api/api.ts @@ -1375,12 +1375,6 @@ export interface GetAssetCountByTimeBucketDto { * @interface ImportAssetDto */ export interface ImportAssetDto { - /** - * - * @type {AssetTypeEnum} - * @memberof ImportAssetDto - */ - 'assetType': AssetTypeEnum; /** * * @type {boolean} @@ -1448,8 +1442,6 @@ export interface ImportAssetDto { */ 'duration'?: string; } - - /** * * @export @@ -5699,9 +5691,7 @@ export const AssetApiAxiosParamCreator = function (configuration?: Configuration }, /** * - * @param {AssetTypeEnum} assetType * @param {File} assetData - * @param {string} fileExtension * @param {string} deviceAssetId * @param {string} deviceId * @param {string} fileCreatedAt @@ -5717,13 +5707,9 @@ export const AssetApiAxiosParamCreator = function (configuration?: Configuration * @param {*} [options] Override http request option. * @throws {RequiredError} */ - uploadFile: async (assetType: AssetTypeEnum, assetData: File, fileExtension: string, deviceAssetId: string, deviceId: string, fileCreatedAt: string, fileModifiedAt: string, isFavorite: boolean, key?: string, livePhotoData?: File, sidecarData?: File, isReadOnly?: boolean, isArchived?: boolean, isVisible?: boolean, duration?: string, options: AxiosRequestConfig = {}): Promise => { - // verify required parameter 'assetType' is not null or undefined - assertParamExists('uploadFile', 'assetType', assetType) + uploadFile: async (assetData: File, deviceAssetId: string, deviceId: string, fileCreatedAt: string, fileModifiedAt: string, isFavorite: boolean, key?: string, livePhotoData?: File, sidecarData?: File, isReadOnly?: boolean, isArchived?: boolean, isVisible?: boolean, duration?: string, options: AxiosRequestConfig = {}): Promise => { // verify required parameter 'assetData' is not null or undefined assertParamExists('uploadFile', 'assetData', assetData) - // verify required parameter 'fileExtension' is not null or undefined - assertParamExists('uploadFile', 'fileExtension', fileExtension) // verify required parameter 'deviceAssetId' is not null or undefined assertParamExists('uploadFile', 'deviceAssetId', deviceAssetId) // verify required parameter 'deviceId' is not null or undefined @@ -5761,10 +5747,6 @@ export const AssetApiAxiosParamCreator = function (configuration?: Configuration } - if (assetType !== undefined) { - localVarFormParams.append('assetType', new Blob([JSON.stringify(assetType)], { type: "application/json", })); - } - if (assetData !== undefined) { localVarFormParams.append('assetData', assetData as any); } @@ -5781,10 +5763,6 @@ export const AssetApiAxiosParamCreator = function (configuration?: Configuration localVarFormParams.append('isReadOnly', isReadOnly as any); } - if (fileExtension !== undefined) { - localVarFormParams.append('fileExtension', fileExtension as any); - } - if (deviceAssetId !== undefined) { localVarFormParams.append('deviceAssetId', deviceAssetId as any); } @@ -6098,9 +6076,7 @@ export const AssetApiFp = function(configuration?: Configuration) { }, /** * - * @param {AssetTypeEnum} assetType * @param {File} assetData - * @param {string} fileExtension * @param {string} deviceAssetId * @param {string} deviceId * @param {string} fileCreatedAt @@ -6116,8 +6092,8 @@ export const AssetApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async uploadFile(assetType: AssetTypeEnum, assetData: File, fileExtension: string, deviceAssetId: string, deviceId: string, fileCreatedAt: string, fileModifiedAt: string, isFavorite: boolean, key?: string, livePhotoData?: File, sidecarData?: File, isReadOnly?: boolean, isArchived?: boolean, isVisible?: boolean, duration?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.uploadFile(assetType, assetData, fileExtension, deviceAssetId, deviceId, fileCreatedAt, fileModifiedAt, isFavorite, key, livePhotoData, sidecarData, isReadOnly, isArchived, isVisible, duration, options); + async uploadFile(assetData: File, deviceAssetId: string, deviceId: string, fileCreatedAt: string, fileModifiedAt: string, isFavorite: boolean, key?: string, livePhotoData?: File, sidecarData?: File, isReadOnly?: boolean, isArchived?: boolean, isVisible?: boolean, duration?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.uploadFile(assetData, deviceAssetId, deviceId, fileCreatedAt, fileModifiedAt, isFavorite, key, livePhotoData, sidecarData, isReadOnly, isArchived, isVisible, duration, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, } @@ -6364,9 +6340,7 @@ export const AssetApiFactory = function (configuration?: Configuration, basePath }, /** * - * @param {AssetTypeEnum} assetType * @param {File} assetData - * @param {string} fileExtension * @param {string} deviceAssetId * @param {string} deviceId * @param {string} fileCreatedAt @@ -6382,8 +6356,8 @@ export const AssetApiFactory = function (configuration?: Configuration, basePath * @param {*} [options] Override http request option. * @throws {RequiredError} */ - uploadFile(assetType: AssetTypeEnum, assetData: File, fileExtension: string, deviceAssetId: string, deviceId: string, fileCreatedAt: string, fileModifiedAt: string, isFavorite: boolean, key?: string, livePhotoData?: File, sidecarData?: File, isReadOnly?: boolean, isArchived?: boolean, isVisible?: boolean, duration?: string, options?: any): AxiosPromise { - return localVarFp.uploadFile(assetType, assetData, fileExtension, deviceAssetId, deviceId, fileCreatedAt, fileModifiedAt, isFavorite, key, livePhotoData, sidecarData, isReadOnly, isArchived, isVisible, duration, options).then((request) => request(axios, basePath)); + uploadFile(assetData: File, deviceAssetId: string, deviceId: string, fileCreatedAt: string, fileModifiedAt: string, isFavorite: boolean, key?: string, livePhotoData?: File, sidecarData?: File, isReadOnly?: boolean, isArchived?: boolean, isVisible?: boolean, duration?: string, options?: any): AxiosPromise { + return localVarFp.uploadFile(assetData, deviceAssetId, deviceId, fileCreatedAt, fileModifiedAt, isFavorite, key, livePhotoData, sidecarData, isReadOnly, isArchived, isVisible, duration, options).then((request) => request(axios, basePath)); }, }; }; @@ -6807,13 +6781,6 @@ export interface AssetApiUpdateAssetRequest { * @interface AssetApiUploadFileRequest */ export interface AssetApiUploadFileRequest { - /** - * - * @type {AssetTypeEnum} - * @memberof AssetApiUploadFile - */ - readonly assetType: AssetTypeEnum - /** * * @type {File} @@ -6821,13 +6788,6 @@ export interface AssetApiUploadFileRequest { */ readonly assetData: File - /** - * - * @type {string} - * @memberof AssetApiUploadFile - */ - readonly fileExtension: string - /** * * @type {string} @@ -7187,7 +7147,7 @@ export class AssetApi extends BaseAPI { * @memberof AssetApi */ public uploadFile(requestParameters: AssetApiUploadFileRequest, options?: AxiosRequestConfig) { - return AssetApiFp(this.configuration).uploadFile(requestParameters.assetType, requestParameters.assetData, requestParameters.fileExtension, requestParameters.deviceAssetId, requestParameters.deviceId, requestParameters.fileCreatedAt, requestParameters.fileModifiedAt, requestParameters.isFavorite, requestParameters.key, requestParameters.livePhotoData, requestParameters.sidecarData, requestParameters.isReadOnly, requestParameters.isArchived, requestParameters.isVisible, requestParameters.duration, options).then((request) => request(this.axios, this.basePath)); + return AssetApiFp(this.configuration).uploadFile(requestParameters.assetData, requestParameters.deviceAssetId, requestParameters.deviceId, requestParameters.fileCreatedAt, requestParameters.fileModifiedAt, requestParameters.isFavorite, requestParameters.key, requestParameters.livePhotoData, requestParameters.sidecarData, requestParameters.isReadOnly, requestParameters.isArchived, requestParameters.isVisible, requestParameters.duration, options).then((request) => request(this.axios, this.basePath)); } } diff --git a/web/src/lib/components/shared-components/upload-asset-preview.svelte b/web/src/lib/components/shared-components/upload-asset-preview.svelte index 5af410625e..431c3008c5 100644 --- a/web/src/lib/components/shared-components/upload-asset-preview.svelte +++ b/web/src/lib/components/shared-components/upload-asset-preview.svelte @@ -4,6 +4,7 @@ import { asByteUnitString } from '$lib/utils/byte-units'; import { fade } from 'svelte/transition'; import ImmichLogo from './immich-logo.svelte'; + import { getFilenameExtension } from '../../utils/asset-utils'; export let uploadAsset: UploadAsset; @@ -42,7 +43,7 @@

- .{uploadAsset.fileExtension} + .{getFilenameExtension(uploadAsset.file.name)}

diff --git a/web/src/lib/models/upload-asset.ts b/web/src/lib/models/upload-asset.ts index c4de5458b8..1b8bb0a256 100644 --- a/web/src/lib/models/upload-asset.ts +++ b/web/src/lib/models/upload-asset.ts @@ -2,5 +2,4 @@ export type UploadAsset = { id: string; file: File; progress: number; - fileExtension: string; }; diff --git a/web/src/lib/utils/asset-utils.spec.ts b/web/src/lib/utils/asset-utils.spec.ts index d9abbdcdc1..2046e6c4ec 100644 --- a/web/src/lib/utils/asset-utils.spec.ts +++ b/web/src/lib/utils/asset-utils.spec.ts @@ -1,6 +1,6 @@ import type { AssetResponseDto } from '@api'; import { describe, expect, it } from '@jest/globals'; -import { getAssetFilename, getFileMimeType, getFilenameExtension } from './asset-utils'; +import { getAssetFilename, getFilenameExtension } from './asset-utils'; describe('get file extension from filename', () => { it('returns the extension without including the dot', () => { @@ -57,88 +57,3 @@ describe('get asset filename', () => { }); }); }); - -describe('get file mime type', () => { - for (const { mimetype, extension } of [ - { mimetype: 'image/avif', extension: 'avif' }, - { mimetype: 'image/gif', extension: 'gif' }, - { mimetype: 'image/heic', extension: 'heic' }, - { mimetype: 'image/heif', extension: 'heif' }, - { mimetype: 'image/jpeg', extension: 'jpeg' }, - { mimetype: 'image/jpeg', extension: 'jpg' }, - { mimetype: 'image/jxl', extension: 'jxl' }, - { mimetype: 'image/png', extension: 'png' }, - { mimetype: 'image/tiff', extension: 'tiff' }, - { mimetype: 'image/webp', extension: 'webp' }, - { mimetype: 'image/x-adobe-dng', extension: 'dng' }, - { mimetype: 'image/x-arriflex-ari', extension: 'ari' }, - { mimetype: 'image/x-canon-cr2', extension: 'cr2' }, - { mimetype: 'image/x-canon-cr3', extension: 'cr3' }, - { mimetype: 'image/x-canon-crw', extension: 'crw' }, - { mimetype: 'image/x-epson-erf', extension: 'erf' }, - { mimetype: 'image/x-fuji-raf', extension: 'raf' }, - { mimetype: 'image/x-hasselblad-3fr', extension: '3fr' }, - { mimetype: 'image/x-hasselblad-fff', extension: 'fff' }, - { mimetype: 'image/x-kodak-dcr', extension: 'dcr' }, - { mimetype: 'image/x-kodak-k25', extension: 'k25' }, - { mimetype: 'image/x-kodak-kdc', extension: 'kdc' }, - { mimetype: 'image/x-leica-rwl', extension: 'rwl' }, - { mimetype: 'image/x-minolta-mrw', extension: 'mrw' }, - { mimetype: 'image/x-nikon-nef', extension: 'nef' }, - { mimetype: 'image/x-olympus-orf', extension: 'orf' }, - { mimetype: 'image/x-olympus-ori', extension: 'ori' }, - { mimetype: 'image/x-panasonic-raw', extension: 'raw' }, - { mimetype: 'image/x-pentax-pef', extension: 'pef' }, - { mimetype: 'image/x-phantom-cin', extension: 'cin' }, - { mimetype: 'image/x-phaseone-cap', extension: 'cap' }, - { mimetype: 'image/x-phaseone-iiq', extension: 'iiq' }, - { mimetype: 'image/x-samsung-srw', extension: 'srw' }, - { mimetype: 'image/x-sigma-x3f', extension: 'x3f' }, - { mimetype: 'image/x-sony-arw', extension: 'arw' }, - { mimetype: 'image/x-sony-sr2', extension: 'sr2' }, - { mimetype: 'image/x-sony-srf', extension: 'srf' }, - { mimetype: 'video/3gpp', extension: '3gp' }, - { mimetype: 'video/avi', extension: 'avi' }, - { mimetype: 'video/mp2t', extension: 'm2ts' }, - { mimetype: 'video/mp2t', extension: 'mts' }, - { mimetype: 'video/mp4', extension: 'mp4' }, - { mimetype: 'video/mpeg', extension: 'mpg' }, - { mimetype: 'video/quicktime', extension: 'mov' }, - { mimetype: 'video/webm', extension: 'webm' }, - { mimetype: 'video/x-flv', extension: 'flv' }, - { mimetype: 'video/x-matroska', extension: 'mkv' }, - { mimetype: 'video/x-ms-wmv', extension: 'wmv' }, - ]) { - it(`returns the mime type for ${extension}`, () => { - expect(getFileMimeType({ name: `filename.${extension}` } as File)).toEqual(mimetype); - }); - } - - it('returns the mime type from the file', () => { - [ - { - file: { - name: 'filename.jpg', - type: 'image/jpeg', - }, - result: 'image/jpeg', - }, - { - file: { - name: 'filename.txt', - type: 'text/plain', - }, - result: 'text/plain', - }, - { - file: { - name: 'filename.txt', - type: '', - }, - result: '', - }, - ].forEach(({ file, result }) => { - expect(getFileMimeType(file as File)).toEqual(result); - }); - }); -}); diff --git a/web/src/lib/utils/asset-utils.ts b/web/src/lib/utils/asset-utils.ts index 13c7c26b09..ff35bdb502 100644 --- a/web/src/lib/utils/asset-utils.ts +++ b/web/src/lib/utils/asset-utils.ts @@ -136,66 +136,6 @@ export function getAssetFilename(asset: AssetResponseDto): string { return `${asset.originalFileName}.${fileExtension}`; } -/** - * Returns the MIME type of the file and an empty string when not found. - */ -export function getFileMimeType(file: File): string { - const mimeTypes: Record = { - '3fr': 'image/x-hasselblad-3fr', - '3gp': 'video/3gpp', - ari: 'image/x-arriflex-ari', - arw: 'image/x-sony-arw', - avi: 'video/avi', - avif: 'image/avif', - cap: 'image/x-phaseone-cap', - cin: 'image/x-phantom-cin', - cr2: 'image/x-canon-cr2', - cr3: 'image/x-canon-cr3', - crw: 'image/x-canon-crw', - dcr: 'image/x-kodak-dcr', - dng: 'image/x-adobe-dng', - erf: 'image/x-epson-erf', - fff: 'image/x-hasselblad-fff', - flv: 'video/x-flv', - gif: 'image/gif', - heic: 'image/heic', - heif: 'image/heif', - iiq: 'image/x-phaseone-iiq', - insp: 'image/jpeg', - insv: 'video/mp4', - jpeg: 'image/jpeg', - jpg: 'image/jpeg', - jxl: 'image/jxl', - k25: 'image/x-kodak-k25', - kdc: 'image/x-kodak-kdc', - m2ts: 'video/mp2t', - mkv: 'video/x-matroska', - mov: 'video/quicktime', - mp4: 'video/mp4', - mpg: 'video/mpeg', - mrw: 'image/x-minolta-mrw', - mts: 'video/mp2t', - nef: 'image/x-nikon-nef', - orf: 'image/x-olympus-orf', - ori: 'image/x-olympus-ori', - pef: 'image/x-pentax-pef', - png: 'image/png', - raf: 'image/x-fuji-raf', - raw: 'image/x-panasonic-raw', - rwl: 'image/x-leica-rwl', - sr2: 'image/x-sony-sr2', - srf: 'image/x-sony-srf', - srw: 'image/x-samsung-srw', - tiff: 'image/tiff', - webm: 'video/webm', - webp: 'image/webp', - wmv: 'video/x-ms-wmv', - x3f: 'image/x-sigma-x3f', - }; - // Return the MIME type determined by the browser or the MIME type based on the file extension. - return file.type || (mimeTypes[getFilenameExtension(file.name)] ?? ''); -} - function isRotated90CW(orientation: number) { return orientation == 6 || orientation == 90; } diff --git a/web/src/lib/utils/file-uploader.ts b/web/src/lib/utils/file-uploader.ts index 2e5a411a26..badfd690c8 100644 --- a/web/src/lib/utils/file-uploader.ts +++ b/web/src/lib/utils/file-uploader.ts @@ -1,11 +1,59 @@ import { uploadAssetsStore } from '$lib/stores/upload'; -import { addAssetsToAlbum, getFileMimeType, getFilenameExtension } from '$lib/utils/asset-utils'; +import { addAssetsToAlbum, getFilenameExtension } from '$lib/utils/asset-utils'; import type { AssetFileUploadResponseDto } from '@api'; import axios from 'axios'; import { combineLatestAll, filter, firstValueFrom, from, mergeMap, of } from 'rxjs'; -import type { UploadAsset } from '../models/upload-asset'; import { notificationController, NotificationType } from './../components/shared-components/notification/notification'; +const extensions = [ + '.3fr', + '.3gp', + '.ari', + '.arw', + '.avi', + '.avif', + '.cap', + '.cin', + '.cr2', + '.cr3', + '.crw', + '.dcr', + '.dng', + '.erf', + '.fff', + '.flv', + '.gif', + '.heic', + '.heif', + '.iiq', + '.jpeg', + '.jpg', + '.k25', + '.kdc', + '.mkv', + '.mov', + '.mp2t', + '.mp4', + '.mpeg', + '.mrw', + '.nef', + '.orf', + '.ori', + '.pef', + '.png', + '.raf', + '.raw', + '.rwl', + '.sr2', + '.srf', + '.srw', + '.tiff', + '.webm', + '.webp', + '.wmv', + '.x3f', +]; + export const openFileUploadDialog = async ( albumId: string | undefined = undefined, sharedKey: string | undefined = undefined, @@ -16,52 +64,7 @@ export const openFileUploadDialog = async ( fileSelector.type = 'file'; fileSelector.multiple = true; - - // When adding a content type that is unsupported by browsers, make sure - // to also add it to getFileMimeType() otherwise the upload will fail. - fileSelector.accept = [ - 'image/*', - 'video/*', - '.3fr', - '.3gp', - '.ari', - '.arw', - '.avif', - '.cap', - '.cin', - '.cr2', - '.cr3', - '.crw', - '.dcr', - '.dng', - '.erf', - '.fff', - '.heic', - '.heif', - '.iiq', - '.insp', - '.insv', - '.jxl', - '.k25', - '.kdc', - '.m2ts', - '.mov', - '.mrw', - '.mts', - '.nef', - '.orf', - '.ori', - '.pef', - '.raf', - '.raf', - '.raw', - '.rwl', - '.sr2', - '.srf', - '.srw', - '.x3f', - ].join(','); - + fileSelector.accept = extensions.join(','); fileSelector.onchange = async (e: Event) => { const target = e.target as HTMLInputElement; if (!target.files) { @@ -87,10 +90,7 @@ export const fileUploadHandler = async ( ) => { return firstValueFrom( from(files).pipe( - filter((file) => { - const assetType = getFileMimeType(file).split('/')[0]; - return assetType === 'video' || assetType === 'image'; - }), + filter((file) => extensions.includes('.' + getFilenameExtension(file.name))), mergeMap(async (file) => of(await fileUploader(file, albumId, sharedKey)), 2), combineLatestAll(), ), @@ -103,51 +103,24 @@ async function fileUploader( albumId: string | undefined = undefined, sharedKey: string | undefined = undefined, ): Promise { - const mimeType = getFileMimeType(asset); - const assetType = mimeType.split('/')[0].toUpperCase(); - const fileExtension = getFilenameExtension(asset.name); const formData = new FormData(); const fileCreatedAt = new Date(asset.lastModified).toISOString(); const deviceAssetId = 'web' + '-' + asset.name + '-' + asset.lastModified; try { - // Create and add pseudo-unique ID of asset on the device formData.append('deviceAssetId', deviceAssetId); - - // Get device id - for web -> use WEB formData.append('deviceId', 'WEB'); - - // Get asset type - formData.append('assetType', assetType); - - // Get Asset Created Date formData.append('fileCreatedAt', fileCreatedAt); - - // Get Asset Modified At formData.append('fileModifiedAt', new Date(asset.lastModified).toISOString()); - - // Set Asset is Favorite to false formData.append('isFavorite', 'false'); - - // Get asset duration formData.append('duration', '0:00:00.000000'); + formData.append('assetData', new File([asset], asset.name)); - // Get asset file extension - formData.append('fileExtension', '.' + fileExtension); - - // Get asset binary data with a custom MIME type, because browsers will - // use application/octet-stream for unsupported MIME types, leading to - // failed uploads. - formData.append('assetData', new File([asset], asset.name, { type: mimeType })); - - const newUploadAsset: UploadAsset = { + uploadAssetsStore.addNewUploadAsset({ id: deviceAssetId, file: asset, progress: 0, - fileExtension: fileExtension, - }; - - uploadAssetsStore.addNewUploadAsset(newUploadAsset); + }); const response = await axios.post(`/api/asset/upload`, formData, { params: {