mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
Merge pull request #691 from Stremio/feature-check-external-urls
feat: check external urls
This commit is contained in:
commit
bc47d6eeff
5 changed files with 29 additions and 16 deletions
9
package-lock.json
generated
9
package-lock.json
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -93,6 +93,8 @@ const EXTERNAL_PLAYERS = [
|
|||
},
|
||||
];
|
||||
|
||||
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,
|
||||
SUBTITLES_SIZES,
|
||||
|
|
@ -110,4 +112,5 @@ module.exports = {
|
|||
TYPE_PRIORITIES,
|
||||
ICON_FOR_TYPE,
|
||||
EXTERNAL_PLAYERS,
|
||||
WHITELISTED_HOSTS,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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,11 +16,19 @@ const PlatformProvider = ({ children }: Props) => {
|
|||
const shell = useShell();
|
||||
|
||||
const openExternal = (url: string) => {
|
||||
if (shell.active) {
|
||||
shell.send('open-external', url);
|
||||
} else {
|
||||
window.open(url, '_blank');
|
||||
}
|
||||
try {
|
||||
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) {
|
||||
console.error('Failed to parse external url:', e);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
@ -36,4 +45,4 @@ const usePlatform = () => {
|
|||
export {
|
||||
PlatformProvider,
|
||||
usePlatform,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
@ -103,15 +104,16 @@ const Settings = () => {
|
|||
}
|
||||
}, [isTraktAuthenticated, profile.auth]);
|
||||
const subscribeCalendarOnClick = React.useCallback(() => {
|
||||
const url = `webcal://www.strem.io/calendar/${profile.auth.user._id}.ics`;
|
||||
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: 'Calendar has been added to your default caldendar app',
|
||||
title: platformName === 'ios' ? t('SETTINGS_SUBSCRIBE_CALENDAR_IOS_TOAST') : t('SETTINGS_SUBSCRIBE_CALENDAR_TOAST'),
|
||||
timeout: 25000
|
||||
});
|
||||
//Stremio 4 emits not documented event subscribeCalendar
|
||||
}, []);
|
||||
// Stremio 4 emits not documented event subscribeCalendar
|
||||
}, [profile.auth.user._id]);
|
||||
const exportDataOnClick = React.useCallback(() => {
|
||||
loadDataExport();
|
||||
}, []);
|
||||
|
|
|
|||
Loading…
Reference in a new issue