-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
165 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,97 @@ | ||
export function pushToPodlove(episodeId: Number, user: string, appId: string, url: string, text: string) { | ||
|
||
// check if episode exist | ||
const podloveUrlEpispde = url + '/wp-json/podlove/v2/episodes/' + episodeId.toString(); | ||
fetch(podloveUrlEpispde, { | ||
method: "GET", | ||
headers: { | ||
export function pushToPodlove( | ||
episodeId: number, | ||
user: string, | ||
appId: string, | ||
url: string, | ||
text: string, | ||
) { | ||
// check if episode exist | ||
const podloveUrlEpispde = url + '/wp-json/podlove/v2/episodes/' + episodeId.toString(); | ||
fetch(podloveUrlEpispde, { | ||
method: 'GET', | ||
headers: { | ||
'Content-type': 'application/json;charset=UTF-8', | ||
Authorization: `Basic ${btoa(`${user}:${appId}`)}`, | ||
}, | ||
}) | ||
.then((response) => { | ||
// export the vtt to the podlove publisher | ||
if (response.status === 200) { | ||
const podloveUrlTranscript = | ||
url + '/wp-json/podlove/v2/transcripts/' + episodeId.toString(); | ||
const podloveData = { | ||
type: 'vtt', | ||
content: text, | ||
}; | ||
fetch(podloveUrlTranscript, { | ||
method: 'POST', | ||
body: JSON.stringify(podloveData), | ||
headers: { | ||
'Content-type': 'application/json;charset=UTF-8', | ||
'Authorization': `Basic ${btoa(`${user}:${appId}`)}` | ||
} | ||
}) | ||
.then(response => { | ||
// export the vtt to the podlove publisher | ||
if (response.status === 200) { | ||
const podloveUrlTranscript = url + '/wp-json/podlove/v2/transcripts/' + episodeId.toString(); | ||
const podloveData = { | ||
type: "vtt", | ||
content: text | ||
} | ||
fetch(podloveUrlTranscript, { | ||
method: "POST", | ||
body: JSON.stringify(podloveData), | ||
headers: { | ||
'Content-type': 'application/json;charset=UTF-8', | ||
'Authorization': `Basic ${btoa(`${user}:${appId}`)}` | ||
} | ||
}) | ||
.then(response => response.json()) | ||
.catch(err => console.error(err)); | ||
} | ||
Authorization: `Basic ${btoa(`${user}:${appId}`)}`, | ||
}, | ||
}) | ||
.catch(err => console.error(err)) | ||
.then((response) => response.json()) | ||
.catch((err) => console.error(err)); | ||
} | ||
}) | ||
.catch((err) => console.error(err)); | ||
} | ||
|
||
export function isEpisodeExistAtPodlove(episodeId: Number, url: string) { | ||
const podloveUrlEpispde = url + '/wp-json/podlove/v2/episodes/' + episodeId.toString(); | ||
fetch(podloveUrlEpispde, { | ||
method: "GET" | ||
export function checkIsPodloveExportPossible( | ||
episodeId: number, | ||
user: string, | ||
appId: string, | ||
url: string, | ||
setIsPodloveUploadPossible: (v: boolean) => void, | ||
) { | ||
if (url.length < 1 || appId.length < 1 || user.length < 1 || episodeId < 1) { | ||
setIsPodloveUploadPossible(false); | ||
} | ||
|
||
const podloveUrlEpispde = url + '/wp-json/podlove/v2/episodes/' + episodeId.toString(); | ||
fetch(podloveUrlEpispde, { | ||
method: 'GET', | ||
}) | ||
.then((response) => { | ||
// export the vtt to the podlove publisher | ||
if (response.status === 200) { | ||
setIsPodloveUploadPossible(true); | ||
} else { | ||
if (response.status === 401) { | ||
fetch(podloveUrlEpispde, { | ||
method: 'GET', | ||
headers: { | ||
'Content-type': 'application/json;charset=UTF-8', | ||
Authorization: `Basic ${btoa(`${user}:${appId}`)}`, | ||
}, | ||
}) | ||
.then((response) => { | ||
if (response.status === 200) { | ||
setIsPodloveUploadPossible(true); | ||
} else { | ||
if (response.status === 401) { | ||
setIsPodloveUploadPossible(false); | ||
} | ||
if (response.status === 404) { | ||
setIsPodloveUploadPossible(false); | ||
} | ||
setIsPodloveUploadPossible(false); | ||
} | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
setIsPodloveUploadPossible(false); | ||
}); | ||
} | ||
if (response.status === 404) { | ||
setIsPodloveUploadPossible(false); | ||
} | ||
setIsPodloveUploadPossible(false); | ||
} | ||
}) | ||
.then(response => { | ||
// export the vtt to the podlove publisher | ||
if (response.status === 200) { | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
return false; | ||
}) | ||
} | ||
.catch((err) => { | ||
console.error(err); | ||
setIsPodloveUploadPossible(false); | ||
}); | ||
} |