From 4173fca28cb6f3d2c95aa635a77e1e4fd88c4c4e Mon Sep 17 00:00:00 2001 From: "Timothy Z." Date: Thu, 26 Sep 2024 12:28:48 +0300 Subject: [PATCH 01/10] feature: check if url is whitelisted --- src/common/CONSTANTS.js | 3 +++ src/common/Platform/Platform.tsx | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/common/CONSTANTS.js b/src/common/CONSTANTS.js index 742c138d6..c64c84bcd 100644 --- a/src/common/CONSTANTS.js +++ b/src/common/CONSTANTS.js @@ -93,6 +93,8 @@ const EXTERNAL_PLAYERS = [ }, ]; +const WHITELISTED_HOSTS = ['www.stremio.com', 'blog.stremio.com', 'web.stremio.com', 'web.strem.io', 'stremio.zendesk.com', 'www.google.com', 'www.youtube.com', 'www.twitch.tv', 'twitter.com', 'www.netflix.com', 'www.adex.network', 'www.amazon.com', 'docs.google.com', 'blog.stremio.com', 'forms.gle']; + module.exports = { CHROMECAST_RECEIVER_APP_ID, SUBTITLES_SIZES, @@ -110,4 +112,5 @@ module.exports = { TYPE_PRIORITIES, ICON_FOR_TYPE, EXTERNAL_PLAYERS, + WHITELISTED_HOSTS, }; diff --git a/src/common/Platform/Platform.tsx b/src/common/Platform/Platform.tsx index c93064d78..0804d512b 100644 --- a/src/common/Platform/Platform.tsx +++ b/src/common/Platform/Platform.tsx @@ -1,5 +1,6 @@ import React, { createContext, useContext } from 'react'; import useShell from './useShell'; +import { WHITELISTED_HOSTS } from 'stremio/common/CONSTANTS'; interface PlatformContext { openExternal: (url: string) => void, @@ -15,10 +16,22 @@ const PlatformProvider = ({ children }: Props) => { const shell = useShell(); const openExternal = (url: string) => { + let finalUrl = url; + try { + const parsedUrl = new URL(url); + const hostname = parsedUrl.hostname; + const isWhitelisted = WHITELISTED_HOSTS.some((host: string) => hostname === host || hostname.endsWith('.' + host)); + if (!isWhitelisted) { + finalUrl = 'https://www.stremio.com/warning#' + encodeURIComponent(url); + } + } catch (e) { + finalUrl = 'https://www.stremio.com/warning#' + encodeURIComponent(url); + } + if (shell.active) { - shell.send('open-external', url); + shell.send('open-external', finalUrl); } else { - window.open(url, '_blank'); + window.open(finalUrl, '_blank'); } }; @@ -36,4 +49,4 @@ const usePlatform = () => { export { PlatformProvider, usePlatform, -}; \ No newline at end of file +}; From 50b93014babbe80b3b53f943be2a911936cb8154 Mon Sep 17 00:00:00 2001 From: "Timothy Z." Date: Thu, 26 Sep 2024 13:06:57 +0300 Subject: [PATCH 02/10] refactor: wrap everything in try catch --- src/common/Platform/Platform.tsx | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/common/Platform/Platform.tsx b/src/common/Platform/Platform.tsx index 0804d512b..13e8592ad 100644 --- a/src/common/Platform/Platform.tsx +++ b/src/common/Platform/Platform.tsx @@ -16,23 +16,19 @@ const PlatformProvider = ({ children }: Props) => { const shell = useShell(); const openExternal = (url: string) => { - let finalUrl = url; try { - const parsedUrl = new URL(url); - const hostname = parsedUrl.hostname; - const isWhitelisted = WHITELISTED_HOSTS.some((host: string) => hostname === host || hostname.endsWith('.' + host)); - if (!isWhitelisted) { - finalUrl = 'https://www.stremio.com/warning#' + encodeURIComponent(url); + const { hostname } = new URL(url); + const isWhitelisted = WHITELISTED_HOSTS.some((host: string) => hostname.endsWith(host)); + const finalUrl = !isWhitelisted ? 'https://www.stremio.com/warning#' + encodeURIComponent(url) : url; + + if (shell.active) { + shell.send('open-external', finalUrl); + } else { + window.open(finalUrl, '_blank'); } } catch (e) { - finalUrl = 'https://www.stremio.com/warning#' + encodeURIComponent(url); - } - - if (shell.active) { - shell.send('open-external', finalUrl); - } else { - window.open(finalUrl, '_blank'); - } + console.error('Failed to parse external url:', e); + } }; return ( From c1b9a057309215e97f4949331ea2f0b931b3721d Mon Sep 17 00:00:00 2001 From: "Timothy Z." Date: Thu, 26 Sep 2024 13:09:08 +0300 Subject: [PATCH 03/10] refactor: whitelisted hosts list --- src/common/CONSTANTS.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/CONSTANTS.js b/src/common/CONSTANTS.js index c64c84bcd..c08cf471d 100644 --- a/src/common/CONSTANTS.js +++ b/src/common/CONSTANTS.js @@ -93,7 +93,7 @@ const EXTERNAL_PLAYERS = [ }, ]; -const WHITELISTED_HOSTS = ['www.stremio.com', 'blog.stremio.com', 'web.stremio.com', 'web.strem.io', 'stremio.zendesk.com', 'www.google.com', 'www.youtube.com', 'www.twitch.tv', 'twitter.com', 'www.netflix.com', 'www.adex.network', 'www.amazon.com', 'docs.google.com', 'blog.stremio.com', 'forms.gle']; +const WHITELISTED_HOSTS = ['stremio.com', 'strem.io', 'stremio.zendesk.com', 'google.com', 'youtube.com', 'twitch.tv', 'twitter.com', 'netflix.com', 'adex.network', 'amazon.com', 'forms.gle']; module.exports = { CHROMECAST_RECEIVER_APP_ID, From bd1305927919c9260195901c5327afccd4c5e610 Mon Sep 17 00:00:00 2001 From: "Timothy Z." Date: Thu, 26 Sep 2024 14:51:12 +0300 Subject: [PATCH 04/10] refactor: turn button into a link --- src/routes/Settings/Settings.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/routes/Settings/Settings.js b/src/routes/Settings/Settings.js index 5c5d51774..ab69d26f6 100644 --- a/src/routes/Settings/Settings.js +++ b/src/routes/Settings/Settings.js @@ -11,6 +11,7 @@ const { Button, Checkbox, MainNavBars, Multiselect, ColorInput, TextInput, Modal const useProfileSettingsInputs = require('./useProfileSettingsInputs'); const useStreamingServerSettingsInputs = require('./useStreamingServerSettingsInputs'); const useDataExport = require('./useDataExport'); +const { name: platformName } = require('stremio/common/platform'); const styles = require('./styles'); const GENERAL_SECTION = 'general'; @@ -102,16 +103,20 @@ const Settings = () => { }); } }, [isTraktAuthenticated, profile.auth]); + const protocol = platformName === 'ios' ? 'webcal' : 'http'; + const calendarUrl = `${protocol}://www.strem.io/calendar/${profile.auth.user._id}.ics`; + const calendarFileName = `${profile.auth.user._id}.ics`; const subscribeCalendarOnClick = React.useCallback(() => { - const url = `webcal://www.strem.io/calendar/${profile.auth.user._id}.ics`; - platform.openExternal(url); + platform.openExternal(calendarUrl); toast.show({ type: 'success', - title: 'Calendar has been added to your default caldendar app', + title: platformName === 'android' ? + 'Calendar has been downloaded. Please open it in your calendar app.' : + 'Calendar has been added to your default calendar app.', timeout: 25000 }); - //Stremio 4 emits not documented event subscribeCalendar - }, []); + // Stremio 4 emits not documented event subscribeCalendar + }, [platformName, profile.auth.user._id, platform, toast]); const exportDataOnClick = React.useCallback(() => { loadDataExport(); }, []); @@ -269,7 +274,7 @@ const Settings = () => { { profile.auth !== null && profile.auth.user !== null && typeof profile.auth.user._id === 'string' ?
-
From 0ee4b6d396417d43c9caafd3f1884998d97229c6 Mon Sep 17 00:00:00 2001 From: "Timothy Z." Date: Thu, 26 Sep 2024 14:55:43 +0300 Subject: [PATCH 05/10] remove: download file name --- src/routes/Settings/Settings.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/routes/Settings/Settings.js b/src/routes/Settings/Settings.js index ab69d26f6..7b1afe620 100644 --- a/src/routes/Settings/Settings.js +++ b/src/routes/Settings/Settings.js @@ -103,9 +103,8 @@ const Settings = () => { }); } }, [isTraktAuthenticated, profile.auth]); - const protocol = platformName === 'ios' ? 'webcal' : 'http'; + const protocol = platformName === 'ios' ? 'webcal' : 'https'; const calendarUrl = `${protocol}://www.strem.io/calendar/${profile.auth.user._id}.ics`; - const calendarFileName = `${profile.auth.user._id}.ics`; const subscribeCalendarOnClick = React.useCallback(() => { platform.openExternal(calendarUrl); toast.show({ @@ -274,7 +273,7 @@ const Settings = () => { { profile.auth !== null && profile.auth.user !== null && typeof profile.auth.user._id === 'string' ?
-
From 9b160a0c6b60a85011705dfbf3a0e41ea4393412 Mon Sep 17 00:00:00 2001 From: "Timothy Z." Date: Thu, 26 Sep 2024 14:57:40 +0300 Subject: [PATCH 06/10] remove: href and target on button --- src/routes/Settings/Settings.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/routes/Settings/Settings.js b/src/routes/Settings/Settings.js index 7b1afe620..3b2846305 100644 --- a/src/routes/Settings/Settings.js +++ b/src/routes/Settings/Settings.js @@ -103,10 +103,10 @@ const Settings = () => { }); } }, [isTraktAuthenticated, profile.auth]); - const protocol = platformName === 'ios' ? 'webcal' : 'https'; - const calendarUrl = `${protocol}://www.strem.io/calendar/${profile.auth.user._id}.ics`; const subscribeCalendarOnClick = React.useCallback(() => { - platform.openExternal(calendarUrl); + const protocol = platformName === 'ios' ? 'webcal' : 'https'; + const url = `${protocol}://www.strem.io/calendar/${profile.auth.user._id}.ics`; + platform.openExternal(url); toast.show({ type: 'success', title: platformName === 'android' ? @@ -273,7 +273,7 @@ const Settings = () => { { profile.auth !== null && profile.auth.user !== null && typeof profile.auth.user._id === 'string' ?
-
From 0ebdf83c7f3988502e6282cd3733bbe5071233ff Mon Sep 17 00:00:00 2001 From: "Timothy Z." Date: Thu, 26 Sep 2024 14:59:32 +0300 Subject: [PATCH 07/10] refactor: dependencies on useCallback --- src/routes/Settings/Settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/Settings/Settings.js b/src/routes/Settings/Settings.js index 3b2846305..fb97d7386 100644 --- a/src/routes/Settings/Settings.js +++ b/src/routes/Settings/Settings.js @@ -115,7 +115,7 @@ const Settings = () => { timeout: 25000 }); // Stremio 4 emits not documented event subscribeCalendar - }, [platformName, profile.auth.user._id, platform, toast]); + }, [profile.auth.user._id]); const exportDataOnClick = React.useCallback(() => { loadDataExport(); }, []); From dab0169038cf537430958d91d3512d641321cae1 Mon Sep 17 00:00:00 2001 From: "Timothy Z." Date: Thu, 26 Sep 2024 15:02:50 +0300 Subject: [PATCH 08/10] refactor: add translations --- src/routes/Settings/Settings.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/routes/Settings/Settings.js b/src/routes/Settings/Settings.js index fb97d7386..92ad44763 100644 --- a/src/routes/Settings/Settings.js +++ b/src/routes/Settings/Settings.js @@ -109,9 +109,7 @@ const Settings = () => { platform.openExternal(url); toast.show({ type: 'success', - title: platformName === 'android' ? - 'Calendar has been downloaded. Please open it in your calendar app.' : - 'Calendar has been added to your default calendar app.', + title: platformName === 'ios' ? t('SETTINGS_SUBSCRIBE_CALENDAR_IOS') : t('SETTINGS_SUBSCRIBE_CALENDAR'), timeout: 25000 }); // Stremio 4 emits not documented event subscribeCalendar From f84bc813f9c71b0759cedea082d05f0ca399ffbb Mon Sep 17 00:00:00 2001 From: "Timothy Z." Date: Thu, 26 Sep 2024 15:08:47 +0300 Subject: [PATCH 09/10] refactor: translations strings --- src/routes/Settings/Settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/Settings/Settings.js b/src/routes/Settings/Settings.js index 92ad44763..3e0c4cf8e 100644 --- a/src/routes/Settings/Settings.js +++ b/src/routes/Settings/Settings.js @@ -109,7 +109,7 @@ const Settings = () => { platform.openExternal(url); toast.show({ type: 'success', - title: platformName === 'ios' ? t('SETTINGS_SUBSCRIBE_CALENDAR_IOS') : t('SETTINGS_SUBSCRIBE_CALENDAR'), + title: platformName === 'ios' ? t('SETTINGS_SUBSCRIBE_CALENDAR_IOS_TOAST') : t('SETTINGS_SUBSCRIBE_CALENDAR_TOAST'), timeout: 25000 }); // Stremio 4 emits not documented event subscribeCalendar From 8e2da823eaf041435ad7d9782570a599aba13d8e Mon Sep 17 00:00:00 2001 From: "Timothy Z." Date: Thu, 26 Sep 2024 16:00:55 +0300 Subject: [PATCH 10/10] chore: update translations pkg --- package-lock.json | 9 ++++----- package.json | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5775eb1a9..31a0fdda8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,7 +36,7 @@ "react-i18next": "^12.1.1", "react-is": "18.2.0", "spatial-navigation-polyfill": "github:Stremio/spatial-navigation#64871b1422466f5f45d24ebc8bbd315b2ebab6a6", - "stremio-translations": "github:Stremio/stremio-translations#b13b3e2653bd0dcf644d2a20ffa32074fe6532dd", + "stremio-translations": "github:Stremio/stremio-translations#378218c9617f3e763ba5f6755e4d39c1c158747d", "url": "0.11.0", "use-long-press": "^3.1.5" }, @@ -12470,10 +12470,9 @@ } }, "node_modules/stremio-translations": { - "version": "1.44.7", - "resolved": "git+ssh://git@github.com/Stremio/stremio-translations.git#b13b3e2653bd0dcf644d2a20ffa32074fe6532dd", - "integrity": "sha512-OtRAM3j9ie89llgI379p4utCbgnNMswE+LtL/lyLRVLfm5B+jpBLp4ozpU25iQg0O4tvN+OHBjXZ870CCHtZMA==", - "license": "MIT" + "version": "1.44.9", + "resolved": "git+ssh://git@github.com/Stremio/stremio-translations.git#378218c9617f3e763ba5f6755e4d39c1c158747d", + "integrity": "sha512-3GboN8JS2LgrdIVK/gW+n6r1kLrGG+D/tWkRv8PJo2mZLzh49HTzS2u7XXUSkNmA4AGUyEf8QRjyBhlOg8JNTQ==" }, "node_modules/string_decoder": { "version": "1.1.1", diff --git a/package.json b/package.json index 6610395a6..1339ba710 100755 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "react-i18next": "^12.1.1", "react-is": "18.2.0", "spatial-navigation-polyfill": "github:Stremio/spatial-navigation#64871b1422466f5f45d24ebc8bbd315b2ebab6a6", - "stremio-translations": "github:Stremio/stremio-translations#b13b3e2653bd0dcf644d2a20ffa32074fe6532dd", + "stremio-translations": "github:Stremio/stremio-translations#378218c9617f3e763ba5f6755e4d39c1c158747d", "url": "0.11.0", "use-long-press": "^3.1.5" },