Skip to content

Commit

Permalink
Add a file extension to download url (#2314)
Browse files Browse the repository at this point in the history
* Add a file extension to download url

* add a format mapping

* Update formats map
  • Loading branch information
mjh1 authored Sep 24, 2024
1 parent 896102c commit d19f3eb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 20 additions & 1 deletion packages/api/src/controllers/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = 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");
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/schema/api-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d19f3eb

Please sign in to comment.