Don't always use YouTube API cache

This commit is contained in:
Ajay Ramachandran
2021-04-08 20:37:19 -04:00
parent 8088f37632
commit 6a9b218e22
6 changed files with 183 additions and 177 deletions

View File

@@ -9,61 +9,71 @@ YouTubeAPI.videos.list({
export class YouTubeApiMock {
static listVideos(videoID: string, callback: (ytErr: any, data: any) => void) {
static async listVideos(videoID: string, ignoreCache = false): Promise<{err: string | boolean, data?: any}> {
const obj = {
id: videoID
};
if (obj.id === "knownWrongID") {
callback(undefined, {
pageInfo: {
totalResults: 0,
},
items: [],
});
return {
err: null,
data: {
pageInfo: {
totalResults: 0,
},
items: [],
}
};
}
if (obj.id === "noDuration") {
callback(undefined, {
pageInfo: {
totalResults: 1,
},
items: [
{
contentDetails: {
duration: "PT0S",
},
snippet: {
title: "Example Title",
thumbnails: {
maxres: {
url: "https://sponsor.ajay.app/LogoSponsorBlockSimple256px.png",
return {
err: null,
data: {
pageInfo: {
totalResults: 1,
},
items: [
{
contentDetails: {
duration: "PT0S",
},
snippet: {
title: "Example Title",
thumbnails: {
maxres: {
url: "https://sponsor.ajay.app/LogoSponsorBlockSimple256px.png",
},
},
},
},
},
],
});
],
}
};
} else {
callback(undefined, {
pageInfo: {
totalResults: 1,
},
items: [
{
contentDetails: {
duration: "PT1H23M30S",
},
snippet: {
title: "Example Title",
thumbnails: {
maxres: {
url: "https://sponsor.ajay.app/LogoSponsorBlockSimple256px.png",
return {
err: null,
data: {
pageInfo: {
totalResults: 1,
},
items: [
{
contentDetails: {
duration: "PT1H23M30S",
},
snippet: {
title: "Example Title",
thumbnails: {
maxres: {
url: "https://sponsor.ajay.app/LogoSponsorBlockSimple256px.png",
},
},
},
},
},
],
});
],
}
};
}
}
}