fix comment and playlist fallbacks

This commit is contained in:
chunky programmer 2023-05-08 21:09:16 -04:00
parent 1ffcc5584e
commit 98fdaa3605
8 changed files with 157 additions and 53 deletions

View File

@ -41,7 +41,11 @@ export default defineComponent({
}, },
computed: { computed: {
backendPreference: function () { backendPreference: function () {
return this.$store.getters.getBackendPreference let preference = this.$store.getters.getBackendPreference
if (preference === 'piped') {
preference = this.$store.getters.getFallbackPreference
}
return preference
}, },
currentInvidiousInstance: function () { currentInvidiousInstance: function () {
return this.$store.getters.getCurrentInvidiousInstance return this.$store.getters.getCurrentInvidiousInstance

View File

@ -33,7 +33,11 @@ export default defineComponent({
}, },
computed: { computed: {
backendPreference: function () { backendPreference: function () {
return this.$store.getters.getBackendPreference let preference = this.$store.getters.getBackendPreference
if (preference === 'piped') {
preference = this.$store.getters.getFallbackPreference
}
return preference
}, },
currentInvidiousInstance: function () { currentInvidiousInstance: function () {
return this.$store.getters.getCurrentInvidiousInstance return this.$store.getters.getCurrentInvidiousInstance

View File

@ -62,7 +62,11 @@ export default defineComponent({
}, },
computed: { computed: {
backendPreference: function () { backendPreference: function () {
return this.$store.getters.getBackendPreference let preference = this.$store.getters.getBackendPreference
if (preference === 'piped') {
preference = this.$store.getters.getFallbackPreference
}
return preference
}, },
autoplayVideos: function () { autoplayVideos: function () {

View File

@ -44,15 +44,15 @@ export default defineComponent({
}, },
computed: { computed: {
backendPreference: function () { backendPreference: function () {
let preference = this.$store.getters.getBackendPreference return this.$store.getters.getBackendPreference
if (preference === 'piped') { },
preference = this.$store.getters.getFallbackPreference
} fallbackPreference: function () {
return preference return this.$store.getters.getFallbackPreference
}, },
backendFallback: function () { backendFallback: function () {
return this.$store.getters.getBackendFallback && this.$store.getters.getBackendPreference !== 'piped' return this.$store.getters.getBackendFallback
}, },
hideCommentLikes: function () { hideCommentLikes: function () {
@ -207,8 +207,13 @@ export default defineComponent({
copyToClipboard(err) copyToClipboard(err)
}) })
if (this.backendFallback && this.backendPreference === 'local') { if (this.backendFallback && this.backendPreference === 'local') {
showToast(this.$t('Falling back to Invidious API')) if (this.fallbackPreference === 'invidious') {
this.getCommentDataInvidious() showToast(this.$t('Falling back to Invidious API'))
this.getCommentDataInvidious()
} else if (this.fallbackPreference === 'piped') {
showToast(this.$t('Falling back to Piped API'))
this.getCommentDataPiped()
}
} else { } else {
this.isLoading = false this.isLoading = false
} }
@ -240,8 +245,13 @@ export default defineComponent({
copyToClipboard(err) copyToClipboard(err)
}) })
if (this.backendFallback && this.backendPreference === 'local') { if (this.backendFallback && this.backendPreference === 'local') {
showToast(this.$t('Falling back to Invidious API')) if (this.fallbackPreference === 'invidious') {
this.getCommentDataInvidious() showToast(this.$t('Falling back to Invidious API'))
this.getCommentDataInvidious()
} else if (this.fallbackPreference === 'piped') {
showToast(this.$t('Falling back to Piped API'))
this.getCommentDataPiped()
}
} else { } else {
this.isLoading = false this.isLoading = false
} }
@ -249,27 +259,65 @@ export default defineComponent({
}, },
getCommentDataPiped: async function () { getCommentDataPiped: async function () {
const { comments, continuation } = await getPipedComments(this.id) try {
this.commentData = comments const { comments, continuation } = await getPipedComments(this.id)
this.nextPageToken = continuation this.commentData = comments
this.isLoading = false this.nextPageToken = continuation
this.showComments = true this.isLoading = false
this.showComments = true
} catch (err) {
console.error(err)
const errorMessage = this.$t('Piped API Error (Click to copy)')
showToast(`${errorMessage}: ${err}`, 10000, () => {
copyToClipboard(err)
})
if (this.backendFallback && this.backendPreference === 'piped') {
if (this.fallbackPreference === 'invidious') {
showToast(this.$t('Falling back to Invidious API'))
this.getCommentDataInvidious()
} else if (process.env.IS_ELECTRON && this.fallbackPreference === 'local') {
showToast(this.$t('Falling back to local API'))
this.getCommentDataLocal()
}
} else {
this.isLoading = false
}
}
}, },
getCommentDataPipedMore: async function(token, index = null) { getCommentDataPipedMore: async function(token, index = null) {
const { comments, continuation } = await getPipedCommentsMore({ try {
videoId: this.id, const { comments, continuation } = await getPipedCommentsMore({
continuation: token videoId: this.id,
}) continuation: token
if (index !== null) { })
this.commentData[index].replies = this.commentData[index].replies.concat(comments) if (index !== null) {
this.commentData[index].showReplies = true this.commentData[index].replies = this.commentData[index].replies.concat(comments)
this.commentData[index].replyToken = continuation this.commentData[index].showReplies = true
} else { this.commentData[index].replyToken = continuation
this.commentData = this.commentData.concat(comments) } else {
this.nextPageToken = continuation this.commentData = this.commentData.concat(comments)
this.nextPageToken = continuation
}
this.isLoading = false
} catch (err) {
console.error(err)
const errorMessage = this.$t('Piped API Error (Click to copy)')
showToast(`${errorMessage}: ${err}`, 10000, () => {
copyToClipboard(err)
})
if (this.backendFallback && this.backendPreference === 'piped') {
if (this.fallbackPreference === 'invidious') {
showToast(this.$t('Falling back to Invidious API'))
this.getCommentDataInvidious()
} else if (process.env.IS_ELECTRON && this.fallbackPreference === 'local') {
showToast(this.$t('Falling back to local API'))
this.getCommentDataLocal()
}
} else {
this.isLoading = false
}
} }
this.isLoading = false
}, },
getCommentDataInvidious: function () { getCommentDataInvidious: function () {
@ -288,9 +336,14 @@ export default defineComponent({
showToast(`${errorMessage}: ${xhr.responseText}`, 10000, () => { showToast(`${errorMessage}: ${xhr.responseText}`, 10000, () => {
copyToClipboard(xhr.responseText) copyToClipboard(xhr.responseText)
}) })
if (process.env.IS_ELECTRON && this.backendFallback && this.backendPreference === 'invidious') { if (this.backendFallback && this.backendPreference === 'invidious') {
showToast(this.$t('Falling back to local API')) if (this.fallbackPreference === 'piped') {
this.getCommentDataLocal() showToast(this.$t('Falling back to Piped API'))
this.getCommentDataPiped()
} else if (process.env.IS_ELECTRON && this.fallbackPreference === 'local') {
showToast(this.$t('Falling back to local API'))
this.getCommentDataLocal()
}
} else { } else {
this.isLoading = false this.isLoading = false
} }

View File

@ -398,9 +398,11 @@ export default defineComponent({
if (this.fallbackPreference === 'invidious') { if (this.fallbackPreference === 'invidious') {
showToast(this.$t('Falling back to Invidious API')) showToast(this.$t('Falling back to Invidious API'))
this.getPlaylistInformationInvidious() this.getPlaylistInformationInvidious()
} else { } else if (process.env.IS_ELECTRON && this.fallbackPreference === 'local') {
showToast(this.$t('Falling back to Piped API')) showToast(this.$t('Falling back to Piped API'))
this.getPlaylistInformationLocal() this.getPlaylistInformationLocal()
} else {
this.isLoading = false
} }
} else { } else {
this.isLoading = false this.isLoading = false

View File

@ -45,8 +45,10 @@ export default defineComponent({
}, },
computed: { computed: {
backendPreference: function () { backendPreference: function () {
return 'piped' return this.$store.getters.getBackendPreference
// return this.$store.getters.getBackendPreference },
fallbackPreference: function () {
return this.$store.getters.getFallbackPreference
}, },
backendFallback: function () { backendFallback: function () {
return this.$store.getters.getBackendFallback return this.$store.getters.getBackendFallback
@ -117,8 +119,13 @@ export default defineComponent({
}).catch((err) => { }).catch((err) => {
console.error(err) console.error(err)
if (this.backendPreference === 'local' && this.backendFallback) { if (this.backendPreference === 'local' && this.backendFallback) {
console.warn('Falling back to Invidious API') if (this.fallbackPreference === 'invidious') {
this.getPlaylistInvidious() console.warn('Falling back to Invidious API')
this.getPlaylistInvidious()
} else {
console.warn('Falling back to Piped API')
this.getPlaylistPiped()
}
} else { } else {
this.isLoading = false this.isLoading = false
} }
@ -156,9 +163,16 @@ export default defineComponent({
this.isLoading = false this.isLoading = false
}).catch((err) => { }).catch((err) => {
console.error(err) console.error(err)
if (process.env.IS_ELECTRON && this.backendPreference === 'invidious' && this.backendFallback) { if (this.backendPreference === 'invidious' && this.backendFallback) {
console.warn('Error getting data with Invidious, falling back to local backend') if (process.env.IS_ELECTRON && this.fallbackPreference === 'local') {
this.getPlaylistLocal() console.warn('Error getting data with Invidious, falling back to local backend')
this.getPlaylistLocal()
} else if (this.fallbackPreference === 'piped') {
console.warn('Error getting data with Invidious, falling back to Piped backend')
this.getPlaylistPiped()
} else {
this.isLoading = false
}
} else { } else {
this.isLoading = false this.isLoading = false
// TODO: Show toast with error message // TODO: Show toast with error message
@ -167,18 +181,36 @@ export default defineComponent({
}, },
getPlaylistPiped: async function () { getPlaylistPiped: async function () {
this.isLoading = true try {
const { playlist, videos, nextpage } = await getPipedPlaylist(this.playlistId) this.isLoading = true
this.infoData = playlist const { playlist, videos, nextpage } = await getPipedPlaylist(this.playlistId)
this.continuationData = nextpage this.infoData = playlist
this.playlistItems = this.playlistItems.concat(videos) this.continuationData = nextpage
this.playlistItems = this.playlistItems.concat(videos)
this.updateSubscriptionDetails({ this.updateSubscriptionDetails({
channelThumbnailUrl: pipedImageToYouTube(playlist.channelThumbnail), channelThumbnailUrl: pipedImageToYouTube(playlist.channelThumbnail),
channelName: playlist.channelName, channelName: playlist.channelName,
channelId: playlist.channelId channelId: playlist.channelId
}) })
this.isLoading = false this.isLoading = false
} catch (err) {
console.error(err)
if (this.backendPreference === 'invidious' && this.backendFallback) {
if (process.env.IS_ELECTRON && this.fallbackPreference === 'local') {
console.warn('Error getting data with Piped, falling back to local backend')
this.getPlaylistLocal()
} else if (this.fallbackPreference === 'invidious') {
console.warn('Error getting data with Piped, falling back to Invidious backend')
this.getPlaylistPiped()
} else {
this.isLoading = false
}
} else {
this.isLoading = false
// TODO: Show toast with error message
}
}
}, },
getNextPage: function () { getNextPage: function () {

View File

@ -59,7 +59,11 @@ export default defineComponent({
}, },
backendPreference: function () { backendPreference: function () {
return this.$store.getters.getBackendPreference let preference = this.$store.getters.getBackendPreference
if (preference === 'piped') {
preference = this.$store.getters.getFallbackPreference
}
return preference
}, },
currentInvidiousInstance: function () { currentInvidiousInstance: function () {

View File

@ -845,6 +845,7 @@ Tooltips:
# Toast Messages # Toast Messages
Local API Error (Click to copy): Local API Error (Click to copy) Local API Error (Click to copy): Local API Error (Click to copy)
Invidious API Error (Click to copy): Invidious API Error (Click to copy) Invidious API Error (Click to copy): Invidious API Error (Click to copy)
Piped API Error (Click to copy): Piped API Error (Click to copy)
Falling back to Invidious API: Falling back to Invidious API Falling back to Invidious API: Falling back to Invidious API
Falling back to Piped API: Falling back to Piped API Falling back to Piped API: Falling back to Piped API
Falling back to the local API: Falling back to the local API Falling back to the local API: Falling back to the local API