Skip to content

Commit

Permalink
Fix: Ensure default source is not decoded unnecessarily and handle UR…
Browse files Browse the repository at this point in the history
…L formats for embedding

- Added logic to skip decoding for the default source to prevent errors
- Enhanced formatUrlForEmbedding function to handle various URL formats for embedding
- Improved error handling in decodeShortlink function with logging
- Updated event listener to conditionally decode and format selected URLs
  • Loading branch information
Fauzanmhr committed Aug 26, 2024
1 parent a4ef200 commit 96ef673
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions views/episode.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
const decodedUrl = await response.text();
return decodedUrl;
} catch (error) {
console.error('Error decoding shortlink:', error);
return shortlink; // Return the original shortlink if decoding fails
}
}
Expand All @@ -96,9 +97,13 @@
document.getElementById('streaming-source').addEventListener('change', async function() {
const selectedUrl = this.value;
const decodedUrl = await decodeShortlink(selectedUrl);
const formattedUrl = formatUrlForEmbedding(decodedUrl);
document.getElementById('streaming-iframe').src = formattedUrl;
let decodedUrl = selectedUrl;
// Only decode if it's not the default source
if (selectedUrl !== "<%= episode.streamingUrl %>") {
decodedUrl = await decodeShortlink(selectedUrl);
}
document.getElementById('streaming-iframe').src = formatUrlForEmbedding(decodedUrl);
});
</script>
</body>
Expand Down

0 comments on commit 96ef673

Please sign in to comment.