Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use constants for API names #5693

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// IPC Channels
const IpcChannels = {
export const IpcChannels = {
ENABLE_PROXY: 'enable-proxy',
DISABLE_PROXY: 'disable-proxy',
OPEN_EXTERNAL_LINK: 'open-external-link',
Expand Down Expand Up @@ -40,7 +40,7 @@ const IpcChannels = {
SET_INVIDIOUS_AUTHORIZATION: 'set-invidious-authorization'
}

const DBActions = {
export const DBActions = {
GENERAL: {
CREATE: 'db-action-create',
FIND: 'db-action-find',
Expand Down Expand Up @@ -69,7 +69,7 @@ const DBActions = {
}
}

const SyncEvents = {
export const SyncEvents = {
GENERAL: {
CREATE: 'sync-create',
UPSERT: 'sync-upsert',
Expand All @@ -94,27 +94,21 @@ const SyncEvents = {
}

// Utils
const MAIN_PROFILE_ID = 'allChannels'
export const MAIN_PROFILE_ID = 'allChannels'

// Width threshold in px at which we switch to using a more heavily altered view for mobile users
const MOBILE_WIDTH_THRESHOLD = 680
export const MOBILE_WIDTH_THRESHOLD = 680

// Height threshold in px at which we switch to using a more heavily altered playlist view for mobile users
const PLAYLIST_HEIGHT_FORCE_LIST_THRESHOLD = 500
export const PLAYLIST_HEIGHT_FORCE_LIST_THRESHOLD = 500

// YouTube search character limit is 100 characters
const SEARCH_CHAR_LIMIT = 100
export const SEARCH_CHAR_LIMIT = 100

// Displayed on the about page and used in the main.js file to only allow bitcoin URLs with this wallet address to be opened
const ABOUT_BITCOIN_ADDRESS = '1Lih7Ho5gnxb1CwPD4o59ss78pwo2T91eS'

export {
IpcChannels,
DBActions,
SyncEvents,
MAIN_PROFILE_ID,
MOBILE_WIDTH_THRESHOLD,
PLAYLIST_HEIGHT_FORCE_LIST_THRESHOLD,
SEARCH_CHAR_LIMIT,
ABOUT_BITCOIN_ADDRESS,
export const ABOUT_BITCOIN_ADDRESS = '1Lih7Ho5gnxb1CwPD4o59ss78pwo2T91eS'

export const API_DATA_SOURCES = {
LOCAL_API: 'local',
INVIDIOUS_API: 'invidious'
Comment on lines +111 to +113
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you named it as API_DATA_SOURCES, why include API in constants names too?

}
3 changes: 2 additions & 1 deletion src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
DBActions,
SyncEvents,
ABOUT_BITCOIN_ADDRESS,
API_DATA_SOURCES,
} from '../constants'
import * as baseHandlers from '../datastores/handlers/base'
import { extractExpiryTimestamp, ImageCache } from './ImageCache'
Expand Down Expand Up @@ -1595,7 +1596,7 @@ function runApp() {
},
type: 'normal'
},
(!hidePopularVideos && (backendFallback || backendPreference === 'invidious')) && {
(!hidePopularVideos && (backendFallback || backendPreference === API_DATA_SOURCES.INVIDIOUS_API)) && {
label: 'Most Popular',
click: (_menuItem, browserWindow, _event) => {
navigateTo('/popular', browserWindow)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { A11y, Navigation, Pagination } from 'swiper/modules'

import { createWebURL, deepCopy, formatNumber, toLocalePublicationString } from '../../helpers/utils'
import { youtubeImageUrlToInvidious } from '../../helpers/api/invidious'
import { API_DATA_SOURCES } from '../../../constants'

export default defineComponent({
name: 'FtCommunityPost',
Expand Down Expand Up @@ -71,7 +72,7 @@ export default defineComponent({
return this.$store.getters.getBackendFallback
},
isInvidiousAllowed: function() {
return this.backendPreference === 'invidious' || this.backendFallback
return this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API || this.backendFallback
}
},
created: function () {
Expand Down Expand Up @@ -111,7 +112,7 @@ export default defineComponent({
this.postText = 'Shared post'
this.type = 'text'
let authorThumbnails = ['', 'https://yt3.ggpht.com/ytc/AAUvwnjm-0qglHJkAHqLFsCQQO97G7cCNDuDLldsrn25Lg=s88-c-k-c0x00ffffff-no-rj']
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) {
authorThumbnails = authorThumbnails.map(thumbnail => {
thumbnail.url = youtubeImageUrlToInvidious(thumbnail.url)
return thumbnail
Expand All @@ -122,7 +123,7 @@ export default defineComponent({
}
this.postText = autolinker.link(this.data.postText)
const authorThumbnails = deepCopy(this.data.authorThumbnails)
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) {
authorThumbnails.forEach(thumbnail => {
thumbnail.url = youtubeImageUrlToInvidious(thumbnail.url)
})
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/components/ft-list-channel/ft-list-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import FtSubscribeButton from '../../components/ft-subscribe-button/ft-subscribe
import { youtubeImageUrlToInvidious } from '../../helpers/api/invidious'
import { formatNumber } from '../../helpers/utils'
import { parseLocalSubscriberCount } from '../../helpers/api/local'
import { API_DATA_SOURCES } from '../../../constants'

export default defineComponent({
name: 'FtListChannel',
Expand Down Expand Up @@ -44,7 +45,7 @@ export default defineComponent({
}
},
created: function () {
if (this.data.dataSource === 'local') {
if (this.data.dataSource === API_DATA_SOURCES.LOCAL_API) {
this.parseLocalData()
} else {
this.parseInvidiousData()
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/components/ft-list-playlist/ft-list-playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineComponent } from 'vue'
import FtIconButton from '../ft-icon-button/ft-icon-button.vue'
import { mapActions } from 'vuex'
import { showToast } from '../../helpers/utils'
import { API_DATA_SOURCES } from '../../../constants'

export default defineComponent({
name: 'FtListPlaylist',
Expand Down Expand Up @@ -104,7 +105,7 @@ export default defineComponent({
created: function () {
if (this.isUserPlaylist) {
this.parseUserData()
} else if (this.data.dataSource === 'local') {
} else if (this.data.dataSource === API_DATA_SOURCES.LOCAL_API) {
this.parseLocalData()
} else {
this.parseInvidiousData()
Expand Down Expand Up @@ -158,7 +159,7 @@ export default defineComponent({
this.title = this.data.playlistName
if (this.thumbnailCanBeShown && this.data.videos.length > 0) {
const thumbnailURL = `https://i.ytimg.com/vi/${this.data.videos[0].videoId}/mqdefault.jpg`
if (this.backendPreference === 'invidious') {
if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) {
this.thumbnail = thumbnailURL.replace('https://i.ytimg.com', this.currentInvidiousInstanceUrl)
} else {
this.thumbnail = thumbnailURL
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/components/ft-list-video/ft-list-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '../../helpers/utils'
import { deArrowData, deArrowThumbnail } from '../../helpers/sponsorblock'
import debounce from 'lodash.debounce'
import { API_DATA_SOURCES } from '../../../constants'

export default defineComponent({
name: 'FtListVideo',
Expand Down Expand Up @@ -337,7 +338,7 @@ export default defineComponent({
}

let baseUrl
if (this.backendPreference === 'invidious') {
if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) {
baseUrl = this.currentInvidiousInstanceUrl
} else {
baseUrl = 'https://i.ytimg.com'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineComponent } from 'vue'
import FtIconButton from '../ft-icon-button/ft-icon-button.vue'
import { mapActions } from 'vuex'
import { API_DATA_SOURCES } from '../../../constants'

export default defineComponent({
name: 'FtPlaylistSelector',
Expand Down Expand Up @@ -128,7 +129,7 @@ export default defineComponent({
this.title = this.playlist.playlistName
if (this.playlist.videos.length > 0) {
const thumbnailURL = `https://i.ytimg.com/vi/${this.playlist.videos[0].videoId}/mqdefault.jpg`
if (this.backendPreference === 'invidious') {
if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) {
this.thumbnail = thumbnailURL.replace('https://i.ytimg.com', this.currentInvidiousInstanceUrl)
} else {
this.thumbnail = thumbnailURL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import FtButton from '../../components/ft-button/ft-button.vue'
import FtPrompt from '../../components/ft-prompt/ft-prompt.vue'
import { deepCopy, showToast } from '../../helpers/utils'
import { youtubeImageUrlToInvidious } from '../../helpers/api/invidious'
import { API_DATA_SOURCES } from '../../../constants'

export default defineComponent({
name: 'FtProfileChannelList',
Expand Down Expand Up @@ -75,7 +76,7 @@ export default defineComponent({
return a.name?.toLowerCase().localeCompare(b.name?.toLowerCase(), this.locale)
})
subscriptions.forEach((channel) => {
if (this.backendPreference === 'invidious') {
if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) {
channel.thumbnail = youtubeImageUrlToInvidious(channel.thumbnail, this.currentInvidiousInstanceUrl)
}
channel.selected = false
Expand All @@ -91,7 +92,7 @@ export default defineComponent({
return a.name?.toLowerCase().localeCompare(b.name?.toLowerCase(), this.locale)
})
subscriptions.forEach((channel) => {
if (this.backendPreference === 'invidious') {
if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) {
channel.thumbnail = youtubeImageUrlToInvidious(channel.thumbnail, this.currentInvidiousInstanceUrl)
}
channel.selected = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import FtButton from '../../components/ft-button/ft-button.vue'
import FtSelect from '../ft-select/ft-select.vue'
import { deepCopy, showToast } from '../../helpers/utils'
import { youtubeImageUrlToInvidious } from '../../helpers/api/invidious'
import { MAIN_PROFILE_ID } from '../../../constants'
import { API_DATA_SOURCES, MAIN_PROFILE_ID } from '../../../constants'

export default defineComponent({
name: 'FtProfileFilterChannelsList',
Expand Down Expand Up @@ -70,7 +70,7 @@ export default defineComponent({

return index === -1
}).map((channel) => {
if (this.backendPreference === 'invidious') {
if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) {
channel.thumbnail = youtubeImageUrlToInvidious(channel.thumbnail, this.currentInvidiousInstanceUrl)
}
channel.selected = false
Expand All @@ -91,7 +91,7 @@ export default defineComponent({

return index === -1
}).map((channel) => {
if (this.backendPreference === 'invidious') {
if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) {
channel.thumbnail = youtubeImageUrlToInvidious(channel.thumbnail, this.currentInvidiousInstanceUrl)
}
channel.selected = false
Expand Down
13 changes: 7 additions & 6 deletions src/renderer/components/general-settings/general-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import debounce from 'lodash.debounce'
import allLocales from '../../../../static/locales/activeLocales.json'
import { randomArrayItem, showToast } from '../../helpers/utils'
import { translateWindowTitle } from '../../helpers/strings'
import { API_DATA_SOURCES } from '../../../constants'

export default defineComponent({
name: 'GeneralSettings',
Expand All @@ -26,11 +27,11 @@ export default defineComponent({
return {
backendValues: process.env.SUPPORTS_LOCAL_API
? [
'invidious',
'local'
API_DATA_SOURCES.INVIDIOUS_API,
API_DATA_SOURCES.LOCAL_API
]
: [
'invidious'
API_DATA_SOURCES.INVIDIOUS_API
],
viewTypeValues: [
'grid',
Expand Down Expand Up @@ -92,7 +93,7 @@ export default defineComponent({
let includedPageNames = this.includedDefaultPageNames
if (this.hideTrendingVideos) includedPageNames = includedPageNames.filter((pageName) => pageName !== 'trending')
if (this.hidePlaylists) includedPageNames = includedPageNames.filter((pageName) => pageName !== 'userPlaylists')
if (!(!this.hidePopularVideos && (this.backendFallback || this.backendPreference === 'invidious'))) includedPageNames = includedPageNames.filter((pageName) => pageName !== 'popular')
if (!(!this.hidePopularVideos && (this.backendFallback || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API))) includedPageNames = includedPageNames.filter((pageName) => pageName !== 'popular')
return this.$router.getRoutes().filter((route) => includedPageNames.includes(route.name))
},
defaultPageNames: function () {
Expand All @@ -103,8 +104,8 @@ export default defineComponent({
return this.defaultPages.map((route) => route.path.substring(1))
},
backendPreference: function () {
if (!process.env.SUPPORTS_LOCAL_API && this.$store.getters.getBackendPreference === 'local') {
this.handlePreferredApiBackend('invidious')
if (!process.env.SUPPORTS_LOCAL_API && this.$store.getters.getBackendPreference === API_DATA_SOURCES.LOCAL_API) {
this.handlePreferredApiBackend(API_DATA_SOURCES.INVIDIOUS_API)
}

return this.$store.getters.getBackendPreference
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/components/playlist-info/playlist-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
showToast,
} from '../../helpers/utils'
import debounce from 'lodash.debounce'
import { API_DATA_SOURCES } from '../../../constants'

export default defineComponent({
name: 'PlaylistInfo',
Expand Down Expand Up @@ -203,7 +204,7 @@ export default defineComponent({
}

let baseUrl = 'https://i.ytimg.com'
if (this.backendPreference === 'invidious') {
if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) {
baseUrl = this.currentInvidiousInstanceUrl
} else if (typeof this.playlistThumbnail === 'string' && this.playlistThumbnail.length > 0) {
// Use playlist thumbnail provided by YT when available
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/components/side-nav/side-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import FtFlexBox from '../ft-flex-box/ft-flex-box.vue'
import SideNavMoreOptions from '../side-nav-more-options/side-nav-more-options.vue'
import { youtubeImageUrlToInvidious } from '../../helpers/api/invidious'
import { deepCopy } from '../../helpers/utils'
import { API_DATA_SOURCES } from '../../../constants'

export default defineComponent({
name: 'SideNav',
Expand Down Expand Up @@ -45,7 +46,7 @@ export default defineComponent({
return a.name?.toLowerCase().localeCompare(b.name?.toLowerCase(), this.locale)
})

if (this.backendPreference === 'invidious') {
if (this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) {
subscriptions.forEach((channel) => {
channel.thumbnail = youtubeImageUrlToInvidious(channel.thumbnail, this.currentInvidiousInstanceUrl)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import SubscriptionsTabUI from '../subscriptions-tab-ui/subscriptions-tab-ui.vue
import { calculatePublishedDate, copyToClipboard, getRelativeTimeFromDate, showToast } from '../../helpers/utils'
import { getLocalChannelCommunity } from '../../helpers/api/local'
import { invidiousGetCommunityPosts } from '../../helpers/api/invidious'
import { API_DATA_SOURCES } from '../../../constants'

export default defineComponent({
name: 'SubscriptionsCommunity',
Expand Down Expand Up @@ -141,7 +142,7 @@ export default defineComponent({

const postListFromRemote = (await Promise.all(channelsToLoadFromRemote.map(async (channel) => {
let posts = []
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) {
posts = await this.getChannelPostsInvidious(channel)
} else {
posts = await this.getChannelPostsLocal(channel)
Expand Down Expand Up @@ -221,7 +222,7 @@ export default defineComponent({
showToast(`${errorMessage}: ${err}`, 10000, () => {
copyToClipboard(err)
})
if (this.backendPreference === 'local' && this.backendFallback) {
if (this.backendPreference === API_DATA_SOURCES.LOCAL_API && this.backendFallback) {
showToast(this.$t('Falling back to Invidious API'))
return await this.getChannelPostsInvidious(channel)
}
Expand All @@ -242,7 +243,7 @@ export default defineComponent({
showToast(`${errorMessage}: ${err}`, 10000, () => {
copyToClipboard(err)
})
if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === 'invidious' && this.backendFallback) {
if (process.env.SUPPORTS_LOCAL_API && this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API && this.backendFallback) {
showToast(this.$t('Falling back to Local API'))
resolve(this.getChannelPostsLocal(channel))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { invidiousAPICall, invidiousFetch } from '../../helpers/api/invidious'
import { getLocalChannelLiveStreams } from '../../helpers/api/local'
import { parseYouTubeRSSFeed, updateVideoListAfterProcessing } from '../../helpers/subscriptions'
import { API_DATA_SOURCES } from '../../../constants'

export default defineComponent({
name: 'SubscriptionsLive',
Expand Down Expand Up @@ -156,7 +157,7 @@ export default defineComponent({
let videos = []
let name, thumbnailUrl

if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) {
if (useRss) {
({ videos, name, thumbnailUrl } = await this.getChannelLiveInvidiousRSS(channel))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
showToast
} from '../../helpers/utils'
import { invidiousFetch } from '../../helpers/api/invidious'
import { API_DATA_SOURCES } from '../../../constants'

export default defineComponent({
name: 'SubscriptionsShorts',
Expand Down Expand Up @@ -142,7 +143,7 @@ export default defineComponent({
let videos = []
let name

if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === 'invidious') {
if (!process.env.SUPPORTS_LOCAL_API || this.backendPreference === API_DATA_SOURCES.INVIDIOUS_API) {
({ videos, name } = await this.getChannelShortsInvidious(channel))
} else {
({ videos, name } = await this.getChannelShortsLocal(channel))
Expand Down
Loading