Skip to content

Commit

Permalink
Change download edge selection to be round robin and only select from…
Browse files Browse the repository at this point in the history
… download enabled edges
  • Loading branch information
Inrixia committed Sep 19, 2022
1 parent 934a6ff commit 8733b61
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/lib/Video.ts
Expand Up @@ -27,6 +27,7 @@ export default class Video {
public videoAttachments: BlogPost["videoAttachments"];

public channel: Channel;
private static edgeSelector = 0;

constructor(video: BlogPost, channel: Channel) {
this.channel = channel;
Expand Down Expand Up @@ -160,9 +161,13 @@ export default class Video {
// Send download request video, assume the first video attached is the actual video as most will not have more than one video
const cdnInfo = await fApi.cdn.delivery("download", this.videoAttachments[i]);

// Pick a random edge to download off, eventual even distribution
if (cdnInfo.edges === undefined) throw new Error("No edges found for video");
const downloadEdge = cdnInfo.edges[Math.floor(Math.random() * cdnInfo.edges.length)];

// Round robin edges with download enabled
const edges = cdnInfo.edges.filter((edge) => edge.allowDownload);
if (Video.edgeSelector > edges.length - 1) Video.edgeSelector = 0;
const downloadEdge = edges[Video.edgeSelector++];

if (settings.floatplane.downloadEdge !== "") downloadEdge.hostname = settings.floatplane.downloadEdge;

// Convert the qualities into an array of resolutions and sorts them smallest to largest
Expand Down

0 comments on commit 8733b61

Please sign in to comment.