From d19f3eb542a501c28943bc9cea9ef049360fdae2 Mon Sep 17 00:00:00 2001 From: Max Holland Date: Tue, 24 Sep 2024 10:12:09 +0100 Subject: [PATCH] Add a file extension to download url (#2314) * Add a file extension to download url * add a format mapping * Update formats map --- packages/api/src/controllers/asset.ts | 21 ++++++++++++++++++++- packages/api/src/schema/api-schema.yaml | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/api/src/controllers/asset.ts b/packages/api/src/controllers/asset.ts index 1f1ea3741..8118ce584 100644 --- a/packages/api/src/controllers/asset.ts +++ b/packages/api/src/controllers/asset.ts @@ -418,7 +418,26 @@ function getDownloadUrl( os.id !== vodObjectStoreId ? os.publicUrl : pathJoin(ingest, "asset"); const source = asset.files?.find((f) => f.type === "source_file"); if (source) { - return pathJoin(base, asset.playbackId, source.path); + const formatToFileExtension: Map = new Map([ + ["mpegts", "ts"], + ["mp4", "mp4"], + ["mov", "mov"], + ["matroska", "mkv"], + ["avi", "avi"], + ]); + + if ( + source.path != "video" || + !formatToFileExtension.has(asset.videoSpec.format) + ) { + return pathJoin(base, asset.playbackId, source.path); + } + return pathJoin( + base, + asset.playbackId, + source.path, + "download." + formatToFileExtension.get(asset.videoSpec.format), + ); } return pathJoin(base, asset.playbackId, "video"); } diff --git a/packages/api/src/schema/api-schema.yaml b/packages/api/src/schema/api-schema.yaml index 376f76feb..435067a2b 100644 --- a/packages/api/src/schema/api-schema.yaml +++ b/packages/api/src/schema/api-schema.yaml @@ -1059,7 +1059,7 @@ components: downloadUrl: readOnly: true type: string - example: "https://livepeercdn.com/asset/eaw4nk06ts2d0mzb/video" + example: "https://livepeercdn.com/asset/eaw4nk06ts2d0mzb/video/download.mp4" description: >- The URL to directly download the asset, e.g. `https://livepeercdn.com/asset/eawrrk06ts2d0mzb/video`. It is not