aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/api/apiBase.ts7
-rw-r--r--src/components/auth/ChangeServer.js5
-rw-r--r--src/helpers/url-helpers.ts14
3 files changed, 16 insertions, 10 deletions
diff --git a/src/api/apiBase.ts b/src/api/apiBase.ts
index 7ed3616a8..c4acb5f68 100644
--- a/src/api/apiBase.ts
+++ b/src/api/apiBase.ts
@@ -9,6 +9,7 @@ import {
9 LOCAL_SERVER, 9 LOCAL_SERVER,
10 SERVER_NOT_LOADED, 10 SERVER_NOT_LOADED,
11} from '../config'; 11} from '../config';
12import { fixUrl } from '../helpers/url-helpers';
12 13
13// Note: This cannot be used from the internal-server since we are not running within the context of a browser window 14// Note: This cannot be used from the internal-server since we are not running within the context of a browser window
14const apiBase = (withVersion = true) => { 15const apiBase = (withVersion = true) => {
@@ -28,13 +29,13 @@ const apiBase = (withVersion = true) => {
28 }` 29 }`
29 : (window as any).ferdium.stores.settings.all.app.server; 30 : (window as any).ferdium.stores.settings.all.app.server;
30 31
31 return withVersion ? `${url}/${API_VERSION}` : url; 32 return fixUrl(withVersion ? `${url}/${API_VERSION}` : url);
32}; 33};
33 34
34export default apiBase; 35export default apiBase;
35 36
36export function termsBase() { 37export function termsBase() {
37 return (window as any).ferdium.stores.settings.all.app.server !== LIVE_FRANZ_API 38 return fixUrl((window as any).ferdium.stores.settings.all.app.server !== LIVE_FRANZ_API
38 ? (window as any).ferdium.stores.settings.all.app.server 39 ? (window as any).ferdium.stores.settings.all.app.server
39 : DEV_API_FRANZ_WEBSITE; 40 : DEV_API_FRANZ_WEBSITE);
40} 41}
diff --git a/src/components/auth/ChangeServer.js b/src/components/auth/ChangeServer.js
index 081f2d61f..aa4598928 100644
--- a/src/components/auth/ChangeServer.js
+++ b/src/components/auth/ChangeServer.js
@@ -121,7 +121,10 @@ class ChangeServer extends Component {
121 {!this.defaultServers.includes(form.$('server').value) && ( 121 {!this.defaultServers.includes(form.$('server').value) && (
122 <Input 122 <Input
123 placeholder="Custom Server" 123 placeholder="Custom Server"
124 onChange={e => this.submit(e)} 124 onChange={e => {
125 this.form.$('customServer').value = this.form.$('customServer').value.replace(/\/$/, "");
126 this.submit(e)
127 }}
125 field={form.$('customServer')} 128 field={form.$('customServer')}
126 /> 129 />
127 )} 130 )}
diff --git a/src/helpers/url-helpers.ts b/src/helpers/url-helpers.ts
index ef2805595..1eda325da 100644
--- a/src/helpers/url-helpers.ts
+++ b/src/helpers/url-helpers.ts
@@ -15,9 +15,6 @@ export function isValidExternalURL(url: string | URL) {
15 } catch { 15 } catch {
16 return false; 16 return false;
17 } 17 }
18 if (url.toString().endsWith('/')) {
19 return false;
20 }
21 18
22 const isAllowed = ALLOWED_PROTOCOLS.includes(parsedUrl.protocol); 19 const isAllowed = ALLOWED_PROTOCOLS.includes(parsedUrl.protocol);
23 20
@@ -26,6 +23,10 @@ export function isValidExternalURL(url: string | URL) {
26 return isAllowed; 23 return isAllowed;
27} 24}
28 25
26export function fixUrl(url: string | URL) {
27 return url.toString().replaceAll('//', '/').replace('http:/', 'http://').replace('https:/', 'https://').replace('file:/', 'file://');
28}
29
29export function isValidFileUrl(path: string) { 30export function isValidFileUrl(path: string) {
30 return path.startsWith('file') && existsSync(new URL(path)); 31 return path.startsWith('file') && existsSync(new URL(path));
31} 32}
@@ -40,8 +41,9 @@ export function openExternalUrl(
40 url: string | URL, 41 url: string | URL,
41 skipValidityCheck: boolean = false, 42 skipValidityCheck: boolean = false,
42) { 43) {
43 debug('Open url:', url, 'with skipValidityCheck:', skipValidityCheck); 44 const fixedUrl = fixUrl(url.toString());
44 if (skipValidityCheck || isValidExternalURL(url)) { 45 debug('Open url:', fixedUrl, 'with skipValidityCheck:', skipValidityCheck);
45 shell.openExternal(url.toString()); 46 if (skipValidityCheck || isValidExternalURL(fixedUrl)) {
47 shell.openExternal(fixedUrl.toString());
46 } 48 }
47} 49}