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 116 additions and 175 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(

View File

@ -79,7 +79,7 @@ Class | Method | HTTP request | Description
*AssetApi* | [**checkDuplicateAsset**](doc//AssetApi.md#checkduplicateasset) | **POST** /asset/check | *AssetApi* | [**checkDuplicateAsset**](doc//AssetApi.md#checkduplicateasset) | **POST** /asset/check |
*AssetApi* | [**checkExistingAssets**](doc//AssetApi.md#checkexistingassets) | **POST** /asset/exist | *AssetApi* | [**checkExistingAssets**](doc//AssetApi.md#checkexistingassets) | **POST** /asset/exist |
*AssetApi* | [**deleteAsset**](doc//AssetApi.md#deleteasset) | **DELETE** /asset | *AssetApi* | [**deleteAsset**](doc//AssetApi.md#deleteasset) | **DELETE** /asset |
*AssetApi* | [**downloadFile**](doc//AssetApi.md#downloadfile) | **GET** /asset/download | *AssetApi* | [**downloadFile**](doc//AssetApi.md#downloadfile) | **GET** /asset/download/{assetId} |
*AssetApi* | [**downloadLibrary**](doc//AssetApi.md#downloadlibrary) | **GET** /asset/download-library | *AssetApi* | [**downloadLibrary**](doc//AssetApi.md#downloadlibrary) | **GET** /asset/download-library |
*AssetApi* | [**getAllAssets**](doc//AssetApi.md#getallassets) | **GET** /asset | *AssetApi* | [**getAllAssets**](doc//AssetApi.md#getallassets) | **GET** /asset |
*AssetApi* | [**getAssetById**](doc//AssetApi.md#getassetbyid) | **GET** /asset/assetById/{assetId} | *AssetApi* | [**getAssetById**](doc//AssetApi.md#getassetbyid) | **GET** /asset/assetById/{assetId} |
@ -92,7 +92,7 @@ Class | Method | HTTP request | Description
*AssetApi* | [**getCuratedObjects**](doc//AssetApi.md#getcuratedobjects) | **GET** /asset/curated-objects | *AssetApi* | [**getCuratedObjects**](doc//AssetApi.md#getcuratedobjects) | **GET** /asset/curated-objects |
*AssetApi* | [**getUserAssetsByDeviceId**](doc//AssetApi.md#getuserassetsbydeviceid) | **GET** /asset/{deviceId} | *AssetApi* | [**getUserAssetsByDeviceId**](doc//AssetApi.md#getuserassetsbydeviceid) | **GET** /asset/{deviceId} |
*AssetApi* | [**searchAsset**](doc//AssetApi.md#searchasset) | **POST** /asset/search | *AssetApi* | [**searchAsset**](doc//AssetApi.md#searchasset) | **POST** /asset/search |
*AssetApi* | [**serveFile**](doc//AssetApi.md#servefile) | **GET** /asset/file | *AssetApi* | [**serveFile**](doc//AssetApi.md#servefile) | **GET** /asset/file/{assetId} |
*AssetApi* | [**updateAssetById**](doc//AssetApi.md#updateassetbyid) | **PUT** /asset/assetById/{assetId} | *AssetApi* | [**updateAssetById**](doc//AssetApi.md#updateassetbyid) | **PUT** /asset/assetById/{assetId} |
*AssetApi* | [**uploadFile**](doc//AssetApi.md#uploadfile) | **POST** /asset/upload | *AssetApi* | [**uploadFile**](doc//AssetApi.md#uploadfile) | **POST** /asset/upload |
*AuthenticationApi* | [**adminSignUp**](doc//AuthenticationApi.md#adminsignup) | **POST** /auth/admin-sign-up | *AuthenticationApi* | [**adminSignUp**](doc//AuthenticationApi.md#adminsignup) | **POST** /auth/admin-sign-up |

View File

@ -12,7 +12,7 @@ Method | HTTP request | Description
[**checkDuplicateAsset**](AssetApi.md#checkduplicateasset) | **POST** /asset/check | [**checkDuplicateAsset**](AssetApi.md#checkduplicateasset) | **POST** /asset/check |
[**checkExistingAssets**](AssetApi.md#checkexistingassets) | **POST** /asset/exist | [**checkExistingAssets**](AssetApi.md#checkexistingassets) | **POST** /asset/exist |
[**deleteAsset**](AssetApi.md#deleteasset) | **DELETE** /asset | [**deleteAsset**](AssetApi.md#deleteasset) | **DELETE** /asset |
[**downloadFile**](AssetApi.md#downloadfile) | **GET** /asset/download | [**downloadFile**](AssetApi.md#downloadfile) | **GET** /asset/download/{assetId} |
[**downloadLibrary**](AssetApi.md#downloadlibrary) | **GET** /asset/download-library | [**downloadLibrary**](AssetApi.md#downloadlibrary) | **GET** /asset/download-library |
[**getAllAssets**](AssetApi.md#getallassets) | **GET** /asset | [**getAllAssets**](AssetApi.md#getallassets) | **GET** /asset |
[**getAssetById**](AssetApi.md#getassetbyid) | **GET** /asset/assetById/{assetId} | [**getAssetById**](AssetApi.md#getassetbyid) | **GET** /asset/assetById/{assetId} |
@ -25,7 +25,7 @@ Method | HTTP request | Description
[**getCuratedObjects**](AssetApi.md#getcuratedobjects) | **GET** /asset/curated-objects | [**getCuratedObjects**](AssetApi.md#getcuratedobjects) | **GET** /asset/curated-objects |
[**getUserAssetsByDeviceId**](AssetApi.md#getuserassetsbydeviceid) | **GET** /asset/{deviceId} | [**getUserAssetsByDeviceId**](AssetApi.md#getuserassetsbydeviceid) | **GET** /asset/{deviceId} |
[**searchAsset**](AssetApi.md#searchasset) | **POST** /asset/search | [**searchAsset**](AssetApi.md#searchasset) | **POST** /asset/search |
[**serveFile**](AssetApi.md#servefile) | **GET** /asset/file | [**serveFile**](AssetApi.md#servefile) | **GET** /asset/file/{assetId} |
[**updateAssetById**](AssetApi.md#updateassetbyid) | **PUT** /asset/assetById/{assetId} | [**updateAssetById**](AssetApi.md#updateassetbyid) | **PUT** /asset/assetById/{assetId} |
[**uploadFile**](AssetApi.md#uploadfile) | **POST** /asset/upload | [**uploadFile**](AssetApi.md#uploadfile) | **POST** /asset/upload |
@ -176,7 +176,7 @@ Name | Type | Description | Notes
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **downloadFile** # **downloadFile**
> Object downloadFile(aid, did, isThumb, isWeb) > Object downloadFile(assetId, isThumb, isWeb)
@ -191,13 +191,12 @@ import 'package:openapi/api.dart';
//defaultApiClient.getAuthentication<HttpBearerAuth>('bearer').setAccessToken(yourTokenGeneratorFunction); //defaultApiClient.getAuthentication<HttpBearerAuth>('bearer').setAccessToken(yourTokenGeneratorFunction);
final api_instance = AssetApi(); final api_instance = AssetApi();
final aid = aid_example; // String | final assetId = assetId_example; // String |
final did = did_example; // String |
final isThumb = true; // bool | final isThumb = true; // bool |
final isWeb = true; // bool | final isWeb = true; // bool |
try { try {
final result = api_instance.downloadFile(aid, did, isThumb, isWeb); final result = api_instance.downloadFile(assetId, isThumb, isWeb);
print(result); print(result);
} catch (e) { } catch (e) {
print('Exception when calling AssetApi->downloadFile: $e\n'); print('Exception when calling AssetApi->downloadFile: $e\n');
@ -208,8 +207,7 @@ try {
Name | Type | Description | Notes Name | Type | Description | Notes
------------- | ------------- | ------------- | ------------- ------------- | ------------- | ------------- | -------------
**aid** | **String**| | **assetId** | **String**| |
**did** | **String**| |
**isThumb** | **bool**| | [optional] **isThumb** | **bool**| | [optional]
**isWeb** | **bool**| | [optional] **isWeb** | **bool**| | [optional]
@ -781,7 +779,7 @@ Name | Type | Description | Notes
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **serveFile** # **serveFile**
> Object serveFile(aid, did, isThumb, isWeb) > Object serveFile(assetId, isThumb, isWeb)
@ -796,13 +794,12 @@ import 'package:openapi/api.dart';
//defaultApiClient.getAuthentication<HttpBearerAuth>('bearer').setAccessToken(yourTokenGeneratorFunction); //defaultApiClient.getAuthentication<HttpBearerAuth>('bearer').setAccessToken(yourTokenGeneratorFunction);
final api_instance = AssetApi(); final api_instance = AssetApi();
final aid = aid_example; // String | final assetId = assetId_example; // String |
final did = did_example; // String |
final isThumb = true; // bool | final isThumb = true; // bool |
final isWeb = true; // bool | final isWeb = true; // bool |
try { try {
final result = api_instance.serveFile(aid, did, isThumb, isWeb); final result = api_instance.serveFile(assetId, isThumb, isWeb);
print(result); print(result);
} catch (e) { } catch (e) {
print('Exception when calling AssetApi->serveFile: $e\n'); print('Exception when calling AssetApi->serveFile: $e\n');
@ -813,8 +810,7 @@ try {
Name | Type | Description | Notes Name | Type | Description | Notes
------------- | ------------- | ------------- | ------------- ------------- | ------------- | ------------- | -------------
**aid** | **String**| | **assetId** | **String**| |
**did** | **String**| |
**isThumb** | **bool**| | [optional] **isThumb** | **bool**| | [optional]
**isWeb** | **bool**| | [optional] **isWeb** | **bool**| | [optional]

View File

@ -178,19 +178,18 @@ class AssetApi {
return null; return null;
} }
/// Performs an HTTP 'GET /asset/download' operation and returns the [Response]. /// Performs an HTTP 'GET /asset/download/{assetId}' operation and returns the [Response].
/// Parameters: /// Parameters:
/// ///
/// * [String] aid (required): /// * [String] assetId (required):
///
/// * [String] did (required):
/// ///
/// * [bool] isThumb: /// * [bool] isThumb:
/// ///
/// * [bool] isWeb: /// * [bool] isWeb:
Future<Response> downloadFileWithHttpInfo(String aid, String did, { bool? isThumb, bool? isWeb, }) async { Future<Response> downloadFileWithHttpInfo(String assetId, { bool? isThumb, bool? isWeb, }) async {
// ignore: prefer_const_declarations // ignore: prefer_const_declarations
final path = r'/asset/download'; final path = r'/asset/download/{assetId}'
.replaceAll('{assetId}', assetId);
// ignore: prefer_final_locals // ignore: prefer_final_locals
Object? postBody; Object? postBody;
@ -199,8 +198,6 @@ class AssetApi {
final headerParams = <String, String>{}; final headerParams = <String, String>{};
final formParams = <String, String>{}; final formParams = <String, String>{};
queryParams.addAll(_queryParams('', 'aid', aid));
queryParams.addAll(_queryParams('', 'did', did));
if (isThumb != null) { if (isThumb != null) {
queryParams.addAll(_queryParams('', 'isThumb', isThumb)); queryParams.addAll(_queryParams('', 'isThumb', isThumb));
} }
@ -224,15 +221,13 @@ class AssetApi {
/// Parameters: /// Parameters:
/// ///
/// * [String] aid (required): /// * [String] assetId (required):
///
/// * [String] did (required):
/// ///
/// * [bool] isThumb: /// * [bool] isThumb:
/// ///
/// * [bool] isWeb: /// * [bool] isWeb:
Future<Object?> downloadFile(String aid, String did, { bool? isThumb, bool? isWeb, }) async { Future<Object?> downloadFile(String assetId, { bool? isThumb, bool? isWeb, }) async {
final response = await downloadFileWithHttpInfo(aid, did, isThumb: isThumb, isWeb: isWeb, ); final response = await downloadFileWithHttpInfo(assetId, isThumb: isThumb, isWeb: isWeb, );
if (response.statusCode >= HttpStatus.badRequest) { if (response.statusCode >= HttpStatus.badRequest) {
throw ApiException(response.statusCode, await _decodeBodyBytes(response)); throw ApiException(response.statusCode, await _decodeBodyBytes(response));
} }
@ -841,19 +836,18 @@ class AssetApi {
return null; return null;
} }
/// Performs an HTTP 'GET /asset/file' operation and returns the [Response]. /// Performs an HTTP 'GET /asset/file/{assetId}' operation and returns the [Response].
/// Parameters: /// Parameters:
/// ///
/// * [String] aid (required): /// * [String] assetId (required):
///
/// * [String] did (required):
/// ///
/// * [bool] isThumb: /// * [bool] isThumb:
/// ///
/// * [bool] isWeb: /// * [bool] isWeb:
Future<Response> serveFileWithHttpInfo(String aid, String did, { bool? isThumb, bool? isWeb, }) async { Future<Response> serveFileWithHttpInfo(String assetId, { bool? isThumb, bool? isWeb, }) async {
// ignore: prefer_const_declarations // ignore: prefer_const_declarations
final path = r'/asset/file'; final path = r'/asset/file/{assetId}'
.replaceAll('{assetId}', assetId);
// ignore: prefer_final_locals // ignore: prefer_final_locals
Object? postBody; Object? postBody;
@ -862,8 +856,6 @@ class AssetApi {
final headerParams = <String, String>{}; final headerParams = <String, String>{};
final formParams = <String, String>{}; final formParams = <String, String>{};
queryParams.addAll(_queryParams('', 'aid', aid));
queryParams.addAll(_queryParams('', 'did', did));
if (isThumb != null) { if (isThumb != null) {
queryParams.addAll(_queryParams('', 'isThumb', isThumb)); queryParams.addAll(_queryParams('', 'isThumb', isThumb));
} }
@ -887,15 +879,13 @@ class AssetApi {
/// Parameters: /// Parameters:
/// ///
/// * [String] aid (required): /// * [String] assetId (required):
///
/// * [String] did (required):
/// ///
/// * [bool] isThumb: /// * [bool] isThumb:
/// ///
/// * [bool] isWeb: /// * [bool] isWeb:
Future<Object?> serveFile(String aid, String did, { bool? isThumb, bool? isWeb, }) async { Future<Object?> serveFile(String assetId, { bool? isThumb, bool? isWeb, }) async {
final response = await serveFileWithHttpInfo(aid, did, isThumb: isThumb, isWeb: isWeb, ); final response = await serveFileWithHttpInfo(assetId, isThumb: isThumb, isWeb: isWeb, );
if (response.statusCode >= HttpStatus.badRequest) { if (response.statusCode >= HttpStatus.badRequest) {
throw ApiException(response.statusCode, await _decodeBodyBytes(response)); throw ApiException(response.statusCode, await _decodeBodyBytes(response));
} }

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",
@ -144,4 +145,4 @@
"^@app/system-config(|/.*)$": "<rootDir>/libs/system-config/src/$1" "^@app/system-config(|/.*)$": "<rootDir>/libs/system-config/src/$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,22 +101,16 @@
$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, responseType: 'blob',
asset.deviceId, onDownloadProgress: (progressEvent) => {
false, if (progressEvent.lengthComputable) {
false, const total = progressEvent.total;
{ const current = progressEvent.loaded;
responseType: 'blob', $downloadAssets[imageFileName] = Math.floor((current / total) * 100);
onDownloadProgress: (progressEvent) => {
if (progressEvent.lengthComputable) {
const total = progressEvent.total;
const current = progressEvent.loaded;
$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, responseType: 'blob'
deviceId, });
false,
true,
{
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) => {