1
0
mirror of https://github.com/immich-app/immich.git synced 2024-11-30 09:47:31 +02:00

chore(server) refactor serveFile and downloadFile endpoint (#978)

This commit is contained in:
Alex 2022-11-16 00:11:16 -06:00 committed by GitHub
parent 1db255fd3e
commit e799f35dd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 88 additions and 133 deletions

View File

@ -23,8 +23,7 @@ class ImageViewerService {
String fileName = p.basename(asset.originalPath); String fileName = p.basename(asset.originalPath);
var res = await _apiService.assetApi.downloadFileWithHttpInfo( var res = await _apiService.assetApi.downloadFileWithHttpInfo(
asset.deviceAssetId, asset.id,
asset.deviceId,
isThumb: false, isThumb: false,
isWeb: false, isWeb: false,
); );

View File

@ -42,7 +42,7 @@ class VideoViewerPage extends HookConsumerWidget {
final box = Hive.box(userInfoBox); final box = Hive.box(userInfoBox);
final String jwtToken = box.get(accessTokenKey); final String jwtToken = box.get(accessTokenKey);
final String videoUrl = final String videoUrl =
'${box.get(serverEndpointKey)}/asset/file?aid=${asset.deviceAssetId}&did=${asset.deviceId}'; '${box.get(serverEndpointKey)}/asset/file/${asset.id}';
return Stack( return Stack(
children: [ children: [

View File

@ -28,8 +28,7 @@ class ShareService {
final fileName = basename(asset.remote!.originalPath); final fileName = basename(asset.remote!.originalPath);
final tempFile = await File('${tempDir.path}/$fileName').create(); final tempFile = await File('${tempDir.path}/$fileName').create();
final res = await _apiService.assetApi.downloadFileWithHttpInfo( final res = await _apiService.assetApi.downloadFileWithHttpInfo(
asset.remote!.deviceAssetId, asset.remote!.id,
asset.remote!.deviceId,
isThumb: false, isThumb: false,
isWeb: false, isWeb: false,
); );

View File

@ -22,7 +22,7 @@ String getAlbumThumbnailUrl(
String getImageUrl(final AssetResponseDto asset) { String getImageUrl(final AssetResponseDto asset) {
final box = Hive.box(userInfoBox); final box = Hive.box(userInfoBox);
return '${box.get(serverEndpointKey)}/asset/file?aid=${asset.deviceAssetId}&did=${asset.deviceId}&isThumb=false'; return '${box.get(serverEndpointKey)}/asset/file/${asset.id}?isThumb=false';
} }
String _getThumbnailUrl( String _getThumbnailUrl(

Binary file not shown.

Binary file not shown.

View File

@ -131,13 +131,13 @@ export class AssetController {
} }
} }
@Get('/download') @Get('/download/:assetId')
async downloadFile( async downloadFile(
@GetAuthUser() authUser: AuthUserDto,
@Response({ passthrough: true }) res: Res, @Response({ passthrough: true }) res: Res,
@Query(new ValidationPipe({ transform: true })) query: ServeFileDto, @Query(new ValidationPipe({ transform: true })) query: ServeFileDto,
@Param('assetId') assetId: string,
): Promise<any> { ): Promise<any> {
return this.assetService.downloadFile(query, res); return this.assetService.downloadFile(query, assetId, res);
} }
@Get('/download-library') @Get('/download-library')
@ -154,14 +154,15 @@ export class AssetController {
return stream; return stream;
} }
@Get('/file') @Get('/file/:assetId')
@Header('Cache-Control', 'max-age=300')
async serveFile( async serveFile(
@Headers() headers: Record<string, string>, @Headers() headers: Record<string, string>,
@GetAuthUser() authUser: AuthUserDto,
@Response({ passthrough: true }) res: Res, @Response({ passthrough: true }) res: Res,
@Query(new ValidationPipe({ transform: true })) query: ServeFileDto, @Query(new ValidationPipe({ transform: true })) query: ServeFileDto,
@Param('assetId') assetId: string,
): Promise<any> { ): Promise<any> {
return this.assetService.serveFile(authUser, query, res, headers); return this.assetService.serveFile(assetId, query, res, headers);
} }
@Get('/thumbnail/:assetId') @Get('/thumbnail/:assetId')

View File

@ -107,22 +107,6 @@ export class AssetService {
return assets.map((asset) => mapAsset(asset)); return assets.map((asset) => mapAsset(asset));
} }
// TODO - Refactor this to get asset by its own id
private async findAssetOfDevice(deviceId: string, assetId: string): Promise<AssetResponseDto> {
const rows = await this.assetRepository.query(
'SELECT * FROM assets a WHERE a."deviceAssetId" = $1 AND a."deviceId" = $2',
[assetId, deviceId],
);
if (rows.lengh == 0) {
throw new NotFoundException('Not Found');
}
const assetOnDevice = rows[0] as AssetEntity;
return mapAsset(assetOnDevice);
}
public async getAssetById(authUser: AuthUserDto, assetId: string): Promise<AssetResponseDto> { public async getAssetById(authUser: AuthUserDto, assetId: string): Promise<AssetResponseDto> {
const asset = await this._assetRepository.getById(assetId); const asset = await this._assetRepository.getById(assetId);
@ -150,10 +134,10 @@ export class AssetService {
return this.downloadService.downloadArchive(dto.name || `library`, assets); return this.downloadService.downloadArchive(dto.name || `library`, assets);
} }
public async downloadFile(query: ServeFileDto, res: Res) { public async downloadFile(query: ServeFileDto, assetId: string, res: Res) {
try { try {
let fileReadStream = null; let fileReadStream = null;
const asset = await this.findAssetOfDevice(query.did, query.aid); const asset = await this._assetRepository.getById(assetId);
// Download Video // Download Video
if (asset.type === AssetType.VIDEO) { if (asset.type === AssetType.VIDEO) {
@ -251,9 +235,9 @@ export class AssetService {
} }
} }
public async serveFile(authUser: AuthUserDto, query: ServeFileDto, res: Res, headers: any) { public async serveFile(assetId: string, query: ServeFileDto, res: Res, headers: any) {
let fileReadStream: ReadStream; let fileReadStream: ReadStream;
const asset = await this.findAssetOfDevice(query.did, query.aid); const asset = await this._assetRepository.getById(assetId);
if (!asset) { if (!asset) {
throw new NotFoundException('Asset does not exist'); throw new NotFoundException('Asset does not exist');

View File

@ -1,16 +1,8 @@
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer'; import { Transform } from 'class-transformer';
import { IsBoolean, IsNotEmpty, IsOptional } from 'class-validator'; import { IsBoolean, IsOptional } from 'class-validator';
export class ServeFileDto { export class ServeFileDto {
@IsNotEmpty()
@ApiProperty({ type: String, title: 'Device Asset ID' })
aid!: string;
@IsNotEmpty()
@ApiProperty({ type: String, title: 'Device ID' })
did!: string;
@IsOptional() @IsOptional()
@IsBoolean() @IsBoolean()
@Transform(({ value }) => { @Transform(({ value }) => {

File diff suppressed because one or more lines are too long

View File

@ -33,6 +33,7 @@
"diskusage": "^1.1.3", "diskusage": "^1.1.3",
"dotenv": "^14.2.0", "dotenv": "^14.2.0",
"exifr": "^7.1.3", "exifr": "^7.1.3",
"fdir": "^5.3.0",
"fluent-ffmpeg": "^2.1.2", "fluent-ffmpeg": "^2.1.2",
"geo-tz": "^7.0.2", "geo-tz": "^7.0.2",
"i18n-iso-countries": "^7.5.0", "i18n-iso-countries": "^7.5.0",
@ -5583,6 +5584,19 @@
"bser": "2.1.1" "bser": "2.1.1"
} }
}, },
"node_modules/fdir": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/fdir/-/fdir-5.3.0.tgz",
"integrity": "sha512-BtE53+jaa7nNHT+gPdfU6cFAXOJUWDs2b5GFox8dtl6zLXmfNf/N6im69b9nqNNwDyl27mpIWX8qR7AafWzSdQ==",
"peerDependencies": {
"picomatch": "2.x"
},
"peerDependenciesMeta": {
"picomatch": {
"optional": true
}
}
},
"node_modules/figures": { "node_modules/figures": {
"version": "3.2.0", "version": "3.2.0",
"resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz",
@ -8885,7 +8899,7 @@
"version": "2.3.1", "version": "2.3.1",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
"dev": true, "devOptional": true,
"engines": { "engines": {
"node": ">=8.6" "node": ">=8.6"
}, },
@ -15772,6 +15786,12 @@
"bser": "2.1.1" "bser": "2.1.1"
} }
}, },
"fdir": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/fdir/-/fdir-5.3.0.tgz",
"integrity": "sha512-BtE53+jaa7nNHT+gPdfU6cFAXOJUWDs2b5GFox8dtl6zLXmfNf/N6im69b9nqNNwDyl27mpIWX8qR7AafWzSdQ==",
"requires": {}
},
"figures": { "figures": {
"version": "3.2.0", "version": "3.2.0",
"resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz",
@ -18309,7 +18329,7 @@
"version": "2.3.1", "version": "2.3.1",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
"dev": true "devOptional": true
}, },
"pirates": { "pirates": {
"version": "4.0.5", "version": "4.0.5",

View File

@ -56,6 +56,7 @@
"diskusage": "^1.1.3", "diskusage": "^1.1.3",
"dotenv": "^14.2.0", "dotenv": "^14.2.0",
"exifr": "^7.1.3", "exifr": "^7.1.3",
"fdir": "^5.3.0",
"fluent-ffmpeg": "^2.1.2", "fluent-ffmpeg": "^2.1.2",
"geo-tz": "^7.0.2", "geo-tz": "^7.0.2",
"i18n-iso-countries": "^7.5.0", "i18n-iso-countries": "^7.5.0",
@ -63,8 +64,8 @@
"local-reverse-geocoder": "^0.12.5", "local-reverse-geocoder": "^0.12.5",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"luxon": "^3.0.3", "luxon": "^3.0.3",
"openid-client": "^5.2.1",
"nest-commander": "^3.3.0", "nest-commander": "^3.3.0",
"openid-client": "^5.2.1",
"passport": "^0.6.0", "passport": "^0.6.0",
"passport-jwt": "^4.0.0", "passport-jwt": "^4.0.0",
"pg": "^8.7.1", "pg": "^8.7.1",

View File

@ -2702,19 +2702,17 @@ export const AssetApiAxiosParamCreator = function (configuration?: Configuration
}, },
/** /**
* *
* @param {string} aid * @param {string} assetId
* @param {string} did
* @param {boolean} [isThumb] * @param {boolean} [isThumb]
* @param {boolean} [isWeb] * @param {boolean} [isWeb]
* @param {*} [options] Override http request option. * @param {*} [options] Override http request option.
* @throws {RequiredError} * @throws {RequiredError}
*/ */
downloadFile: async (aid: string, did: string, isThumb?: boolean, isWeb?: boolean, options: AxiosRequestConfig = {}): Promise<RequestArgs> => { downloadFile: async (assetId: string, isThumb?: boolean, isWeb?: boolean, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'aid' is not null or undefined // verify required parameter 'assetId' is not null or undefined
assertParamExists('downloadFile', 'aid', aid) assertParamExists('downloadFile', 'assetId', assetId)
// verify required parameter 'did' is not null or undefined const localVarPath = `/asset/download/{assetId}`
assertParamExists('downloadFile', 'did', did) .replace(`{${"assetId"}}`, encodeURIComponent(String(assetId)));
const localVarPath = `/asset/download`;
// use dummy base URL string because the URL constructor only accepts absolute URLs. // use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions; let baseOptions;
@ -2730,14 +2728,6 @@ export const AssetApiAxiosParamCreator = function (configuration?: Configuration
// http bearer authentication required // http bearer authentication required
await setBearerAuthToObject(localVarHeaderParameter, configuration) await setBearerAuthToObject(localVarHeaderParameter, configuration)
if (aid !== undefined) {
localVarQueryParameter['aid'] = aid;
}
if (did !== undefined) {
localVarQueryParameter['did'] = did;
}
if (isThumb !== undefined) { if (isThumb !== undefined) {
localVarQueryParameter['isThumb'] = isThumb; localVarQueryParameter['isThumb'] = isThumb;
} }
@ -3198,19 +3188,17 @@ export const AssetApiAxiosParamCreator = function (configuration?: Configuration
}, },
/** /**
* *
* @param {string} aid * @param {string} assetId
* @param {string} did
* @param {boolean} [isThumb] * @param {boolean} [isThumb]
* @param {boolean} [isWeb] * @param {boolean} [isWeb]
* @param {*} [options] Override http request option. * @param {*} [options] Override http request option.
* @throws {RequiredError} * @throws {RequiredError}
*/ */
serveFile: async (aid: string, did: string, isThumb?: boolean, isWeb?: boolean, options: AxiosRequestConfig = {}): Promise<RequestArgs> => { serveFile: async (assetId: string, isThumb?: boolean, isWeb?: boolean, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'aid' is not null or undefined // verify required parameter 'assetId' is not null or undefined
assertParamExists('serveFile', 'aid', aid) assertParamExists('serveFile', 'assetId', assetId)
// verify required parameter 'did' is not null or undefined const localVarPath = `/asset/file/{assetId}`
assertParamExists('serveFile', 'did', did) .replace(`{${"assetId"}}`, encodeURIComponent(String(assetId)));
const localVarPath = `/asset/file`;
// use dummy base URL string because the URL constructor only accepts absolute URLs. // use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions; let baseOptions;
@ -3226,14 +3214,6 @@ export const AssetApiAxiosParamCreator = function (configuration?: Configuration
// http bearer authentication required // http bearer authentication required
await setBearerAuthToObject(localVarHeaderParameter, configuration) await setBearerAuthToObject(localVarHeaderParameter, configuration)
if (aid !== undefined) {
localVarQueryParameter['aid'] = aid;
}
if (did !== undefined) {
localVarQueryParameter['did'] = did;
}
if (isThumb !== undefined) { if (isThumb !== undefined) {
localVarQueryParameter['isThumb'] = isThumb; localVarQueryParameter['isThumb'] = isThumb;
} }
@ -3385,15 +3365,14 @@ export const AssetApiFp = function(configuration?: Configuration) {
}, },
/** /**
* *
* @param {string} aid * @param {string} assetId
* @param {string} did
* @param {boolean} [isThumb] * @param {boolean} [isThumb]
* @param {boolean} [isWeb] * @param {boolean} [isWeb]
* @param {*} [options] Override http request option. * @param {*} [options] Override http request option.
* @throws {RequiredError} * @throws {RequiredError}
*/ */
async downloadFile(aid: string, did: string, isThumb?: boolean, isWeb?: boolean, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<object>> { async downloadFile(assetId: string, isThumb?: boolean, isWeb?: boolean, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<object>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.downloadFile(aid, did, isThumb, isWeb, options); const localVarAxiosArgs = await localVarAxiosParamCreator.downloadFile(assetId, isThumb, isWeb, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
}, },
/** /**
@ -3517,15 +3496,14 @@ export const AssetApiFp = function(configuration?: Configuration) {
}, },
/** /**
* *
* @param {string} aid * @param {string} assetId
* @param {string} did
* @param {boolean} [isThumb] * @param {boolean} [isThumb]
* @param {boolean} [isWeb] * @param {boolean} [isWeb]
* @param {*} [options] Override http request option. * @param {*} [options] Override http request option.
* @throws {RequiredError} * @throws {RequiredError}
*/ */
async serveFile(aid: string, did: string, isThumb?: boolean, isWeb?: boolean, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<object>> { async serveFile(assetId: string, isThumb?: boolean, isWeb?: boolean, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<object>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.serveFile(aid, did, isThumb, isWeb, options); const localVarAxiosArgs = await localVarAxiosParamCreator.serveFile(assetId, isThumb, isWeb, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
}, },
/** /**
@ -3591,15 +3569,14 @@ export const AssetApiFactory = function (configuration?: Configuration, basePath
}, },
/** /**
* *
* @param {string} aid * @param {string} assetId
* @param {string} did
* @param {boolean} [isThumb] * @param {boolean} [isThumb]
* @param {boolean} [isWeb] * @param {boolean} [isWeb]
* @param {*} [options] Override http request option. * @param {*} [options] Override http request option.
* @throws {RequiredError} * @throws {RequiredError}
*/ */
downloadFile(aid: string, did: string, isThumb?: boolean, isWeb?: boolean, options?: any): AxiosPromise<object> { downloadFile(assetId: string, isThumb?: boolean, isWeb?: boolean, options?: any): AxiosPromise<object> {
return localVarFp.downloadFile(aid, did, isThumb, isWeb, options).then((request) => request(axios, basePath)); return localVarFp.downloadFile(assetId, isThumb, isWeb, options).then((request) => request(axios, basePath));
}, },
/** /**
* *
@ -3710,15 +3687,14 @@ export const AssetApiFactory = function (configuration?: Configuration, basePath
}, },
/** /**
* *
* @param {string} aid * @param {string} assetId
* @param {string} did
* @param {boolean} [isThumb] * @param {boolean} [isThumb]
* @param {boolean} [isWeb] * @param {boolean} [isWeb]
* @param {*} [options] Override http request option. * @param {*} [options] Override http request option.
* @throws {RequiredError} * @throws {RequiredError}
*/ */
serveFile(aid: string, did: string, isThumb?: boolean, isWeb?: boolean, options?: any): AxiosPromise<object> { serveFile(assetId: string, isThumb?: boolean, isWeb?: boolean, options?: any): AxiosPromise<object> {
return localVarFp.serveFile(aid, did, isThumb, isWeb, options).then((request) => request(axios, basePath)); return localVarFp.serveFile(assetId, isThumb, isWeb, options).then((request) => request(axios, basePath));
}, },
/** /**
* Update an asset * Update an asset
@ -3787,16 +3763,15 @@ export class AssetApi extends BaseAPI {
/** /**
* *
* @param {string} aid * @param {string} assetId
* @param {string} did
* @param {boolean} [isThumb] * @param {boolean} [isThumb]
* @param {boolean} [isWeb] * @param {boolean} [isWeb]
* @param {*} [options] Override http request option. * @param {*} [options] Override http request option.
* @throws {RequiredError} * @throws {RequiredError}
* @memberof AssetApi * @memberof AssetApi
*/ */
public downloadFile(aid: string, did: string, isThumb?: boolean, isWeb?: boolean, options?: AxiosRequestConfig) { public downloadFile(assetId: string, isThumb?: boolean, isWeb?: boolean, options?: AxiosRequestConfig) {
return AssetApiFp(this.configuration).downloadFile(aid, did, isThumb, isWeb, options).then((request) => request(this.axios, this.basePath)); return AssetApiFp(this.configuration).downloadFile(assetId, isThumb, isWeb, options).then((request) => request(this.axios, this.basePath));
} }
/** /**
@ -3932,16 +3907,15 @@ export class AssetApi extends BaseAPI {
/** /**
* *
* @param {string} aid * @param {string} assetId
* @param {string} did
* @param {boolean} [isThumb] * @param {boolean} [isThumb]
* @param {boolean} [isWeb] * @param {boolean} [isWeb]
* @param {*} [options] Override http request option. * @param {*} [options] Override http request option.
* @throws {RequiredError} * @throws {RequiredError}
* @memberof AssetApi * @memberof AssetApi
*/ */
public serveFile(aid: string, did: string, isThumb?: boolean, isWeb?: boolean, options?: AxiosRequestConfig) { public serveFile(assetId: string, isThumb?: boolean, isWeb?: boolean, options?: AxiosRequestConfig) {
return AssetApiFp(this.configuration).serveFile(aid, did, isThumb, isWeb, options).then((request) => request(this.axios, this.basePath)); return AssetApiFp(this.configuration).serveFile(assetId, isThumb, isWeb, options).then((request) => request(this.axios, this.basePath));
} }
/** /**

View File

@ -1,10 +1,8 @@
const _basePath = '/api'; const _basePath = '/api';
export function getFileUrl(aid: string, did: string, isThumb?: boolean, isWeb?: boolean) { export function getFileUrl(assetId: string, isThumb?: boolean, isWeb?: boolean) {
const urlObj = new URL(`${window.location.origin}${_basePath}/asset/file`); const urlObj = new URL(`${window.location.origin}${_basePath}/asset/file/${assetId}`);
urlObj.searchParams.append('aid', aid);
urlObj.searchParams.append('did', did);
if (isThumb !== undefined && isThumb !== null) if (isThumb !== undefined && isThumb !== null)
urlObj.searchParams.append('isThumb', `${isThumb}`); urlObj.searchParams.append('isThumb', `${isThumb}`);
if (isWeb !== undefined && isWeb !== null) urlObj.searchParams.append('isWeb', `${isWeb}`); if (isWeb !== undefined && isWeb !== null) urlObj.searchParams.append('isWeb', `${isWeb}`);

View File

@ -101,12 +101,7 @@
$downloadAssets[imageFileName] = 0; $downloadAssets[imageFileName] = 0;
const { data, status } = await api.assetApi.downloadFile( const { data, status } = await api.assetApi.downloadFile(asset.id, false, false, {
asset.deviceAssetId,
asset.deviceId,
false,
false,
{
responseType: 'blob', responseType: 'blob',
onDownloadProgress: (progressEvent) => { onDownloadProgress: (progressEvent) => {
if (progressEvent.lengthComputable) { if (progressEvent.lengthComputable) {
@ -115,8 +110,7 @@
$downloadAssets[imageFileName] = Math.floor((current / total) * 100); $downloadAssets[imageFileName] = Math.floor((current / total) * 100);
} }
} }
} });
);
if (!(data instanceof Blob)) { if (!(data instanceof Blob)) {
return; return;
@ -262,7 +256,7 @@
<div class="row-start-1 row-span-full col-start-1 col-span-4"> <div class="row-start-1 row-span-full col-start-1 col-span-4">
{#key asset.id} {#key asset.id}
{#if asset.type === AssetTypeEnum.Image} {#if asset.type === AssetTypeEnum.Image}
<PhotoViewer assetId={asset.id} deviceId={asset.deviceId} on:close={closeViewer} /> <PhotoViewer assetId={asset.id} on:close={closeViewer} />
{:else} {:else}
<VideoViewer assetId={asset.id} on:close={closeViewer} /> <VideoViewer assetId={asset.id} on:close={closeViewer} />
{/if} {/if}

View File

@ -7,7 +7,6 @@
import Keydown from 'svelte-keydown'; import Keydown from 'svelte-keydown';
export let assetId: string; export let assetId: string;
export let deviceId: string;
let assetInfo: AssetResponseDto; let assetInfo: AssetResponseDto;
let assetData: string; let assetData: string;
@ -25,15 +24,9 @@
const loadAssetData = async () => { const loadAssetData = async () => {
try { try {
const { data } = await api.assetApi.serveFile( const { data } = await api.assetApi.serveFile(assetInfo.id, false, true, {
assetInfo.deviceAssetId,
deviceId,
false,
true,
{
responseType: 'blob' responseType: 'blob'
} });
);
if (!(data instanceof Blob)) { if (!(data instanceof Blob)) {
return; return;

View File

@ -24,7 +24,7 @@
const loadVideoData = async (assetInfo: AssetResponseDto) => { const loadVideoData = async (assetInfo: AssetResponseDto) => {
isVideoLoading = true; isVideoLoading = true;
videoUrl = getFileUrl(assetInfo.deviceAssetId, assetInfo.deviceId, false, true); videoUrl = getFileUrl(assetInfo.id, false, true);
return assetInfo; return assetInfo;
}; };

View File

@ -31,7 +31,7 @@
const loadVideoData = async () => { const loadVideoData = async () => {
isThumbnailVideoPlaying = false; isThumbnailVideoPlaying = false;
videoUrl = getFileUrl(asset.deviceAssetId, asset.deviceId, false, true); videoUrl = getFileUrl(asset.id, false, true);
}; };
const getVideoDurationInString = (currentTime: number) => { const getVideoDurationInString = (currentTime: number) => {