Skip to content

Commit

Permalink
Merge pull request #716 from podverse/develop
Browse files Browse the repository at this point in the history
Release v4.15.19
  • Loading branch information
mitchdowney committed Dec 5, 2023
2 parents 0197b7a + 3d82b29 commit d4aef7c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "podverse-api",
"version": "4.15.18",
"version": "4.15.19",
"description": "Data API, database migration scripts, and backend services for all Podverse models.",
"contributors": [
"Mitch Downey"
Expand Down
14 changes: 13 additions & 1 deletion src/services/podcastIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ const csv = require('csvtojson')
const createError = require('http-errors')
const { podcastIndexConfig, userAgent } = config

/*
NOTE!!!
The episodeGuid needs to be encoded both on the client-side and server side if it is an http url guid.
Koa will automatically decode the encoded url param, and then Podcast Index API needs it
encoded once again before sending the request to PI API.
*/

const axiosRequest = async (url) => {
const apiHeaderTime = new Date().getTime() / 1000
const hash = sha1(config.podcastIndexConfig.authKey + config.podcastIndexConfig.secretKey + apiHeaderTime).toString(
Expand Down Expand Up @@ -242,6 +249,9 @@ export const getValueTagForChannelFromPodcastIndexByGuids = async (podcastGuid:

// see note above
export const getValueTagForItemFromPodcastIndexByGuids = async (podcastGuid: string, episodeGuid: string) => {
if (episodeGuid.indexOf('http') === 0) {
episodeGuid = encodeURIComponent(episodeGuid)
}
const url = `${podcastIndexConfig.baseUrl}/episodes/byguid?podcastguid=${podcastGuid}&guid=${episodeGuid}`
let episodeValueTag: ValueTag[] | null = null

Expand Down Expand Up @@ -612,8 +622,10 @@ export const hideDeadPodcasts = async (fileUrl?: string) => {
console.log('hideDeadPodcasts finished')
}

// the episodeGuid needs to be encoded client-side if it is an http url
export const getEpisodeByGuid = async (podcastIndexId: string, episodeGuid: string) => {
if (episodeGuid.indexOf('http') === 0) {
episodeGuid = encodeURIComponent(episodeGuid)
}
const url = `${podcastIndexConfig.baseUrl}/episodes/byguid?feedid=${podcastIndexId}&guid=${episodeGuid}`
const response = await axiosRequest(url)
return response && response.data
Expand Down

0 comments on commit d4aef7c

Please sign in to comment.