diff options
-rw-r--r-- | src/components/settings/services/EditServiceForm.tsx | 8 | ||||
-rw-r--r-- | src/helpers/url-helpers.ts | 9 | ||||
-rw-r--r-- | src/models/Service.ts | 9 |
3 files changed, 13 insertions, 13 deletions
diff --git a/src/components/settings/services/EditServiceForm.tsx b/src/components/settings/services/EditServiceForm.tsx index 2b87dff1e..c04a53b50 100644 --- a/src/components/settings/services/EditServiceForm.tsx +++ b/src/components/settings/services/EditServiceForm.tsx | |||
@@ -2,7 +2,6 @@ import { Component, FormEvent, ReactElement } from 'react'; | |||
2 | import { observer } from 'mobx-react'; | 2 | import { observer } from 'mobx-react'; |
3 | import { Link } from 'react-router-dom'; | 3 | import { Link } from 'react-router-dom'; |
4 | import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl'; | 4 | import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl'; |
5 | import normalizeUrl from 'normalize-url'; | ||
6 | import { mdiInformation } from '@mdi/js'; | 5 | import { mdiInformation } from '@mdi/js'; |
7 | import { noop } from 'lodash'; | 6 | import { noop } from 'lodash'; |
8 | import Form from '../../../lib/Form'; | 7 | import Form from '../../../lib/Form'; |
@@ -20,6 +19,7 @@ import Icon from '../../ui/icon'; | |||
20 | import { H3 } from '../../ui/headline'; | 19 | import { H3 } from '../../ui/headline'; |
21 | import { IRecipe } from '../../../models/Recipe'; | 20 | import { IRecipe } from '../../../models/Recipe'; |
22 | import Service from '../../../models/Service'; | 21 | import Service from '../../../models/Service'; |
22 | import { normalizedUrl } from '../../../helpers/url-helpers'; | ||
23 | 23 | ||
24 | const messages = defineMessages({ | 24 | const messages = defineMessages({ |
25 | saveService: { | 25 | saveService: { |
@@ -194,11 +194,7 @@ class EditServiceForm extends Component<IProps, IState> { | |||
194 | if (recipe.validateUrl && values.customUrl) { | 194 | if (recipe.validateUrl && values.customUrl) { |
195 | this.setState({ isValidatingCustomUrl: true }); | 195 | this.setState({ isValidatingCustomUrl: true }); |
196 | try { | 196 | try { |
197 | values.customUrl = normalizeUrl(values.customUrl, { | 197 | values.customUrl = normalizedUrl(values.customUrl); |
198 | stripAuthentication: false, | ||
199 | stripWWW: false, | ||
200 | removeTrailingSlash: false, | ||
201 | }); | ||
202 | isValid = await recipe.validateUrl(values.customUrl); | 198 | isValid = await recipe.validateUrl(values.customUrl); |
203 | } catch (error) { | 199 | } catch (error) { |
204 | console.warn('ValidateURL', error); | 200 | console.warn('ValidateURL', error); |
diff --git a/src/helpers/url-helpers.ts b/src/helpers/url-helpers.ts index 9c5cf7752..795d3f2cb 100644 --- a/src/helpers/url-helpers.ts +++ b/src/helpers/url-helpers.ts | |||
@@ -2,6 +2,7 @@ | |||
2 | import { URL } from 'url'; | 2 | import { URL } from 'url'; |
3 | import { ensureDirSync, existsSync } from 'fs-extra'; | 3 | import { ensureDirSync, existsSync } from 'fs-extra'; |
4 | import { shell } from 'electron'; | 4 | import { shell } from 'electron'; |
5 | import normalizeUrl from 'normalize-url'; | ||
5 | import { ALLOWED_PROTOCOLS } from '../config'; | 6 | import { ALLOWED_PROTOCOLS } from '../config'; |
6 | 7 | ||
7 | const debug = require('../preload-safe-debug')('Ferdium:Helpers:url'); | 8 | const debug = require('../preload-safe-debug')('Ferdium:Helpers:url'); |
@@ -49,3 +50,11 @@ export function openExternalUrl( | |||
49 | shell.openExternal(fixedUrl.toString()); | 50 | shell.openExternal(fixedUrl.toString()); |
50 | } | 51 | } |
51 | } | 52 | } |
53 | |||
54 | export function normalizedUrl(url: string) { | ||
55 | return normalizeUrl(url, { | ||
56 | stripAuthentication: false, | ||
57 | stripWWW: false, | ||
58 | removeTrailingSlash: false, | ||
59 | }); | ||
60 | } | ||
diff --git a/src/models/Service.ts b/src/models/Service.ts index 0cbfa60e2..af0085185 100644 --- a/src/models/Service.ts +++ b/src/models/Service.ts | |||
@@ -1,12 +1,11 @@ | |||
1 | import { autorun, action, computed, makeObservable, observable } from 'mobx'; | 1 | import { autorun, action, computed, makeObservable, observable } from 'mobx'; |
2 | import { ipcRenderer } from 'electron'; | 2 | import { ipcRenderer } from 'electron'; |
3 | import { webContents } from '@electron/remote'; | 3 | import { webContents } from '@electron/remote'; |
4 | import normalizeUrl from 'normalize-url'; | ||
5 | import { join } from 'path'; | 4 | import { join } from 'path'; |
6 | import ElectronWebView from 'react-electron-web-view'; | 5 | import ElectronWebView from 'react-electron-web-view'; |
7 | 6 | ||
8 | import { todosStore } from '../features/todos'; | 7 | import { todosStore } from '../features/todos'; |
9 | import { isValidExternalURL } from '../helpers/url-helpers'; | 8 | import { isValidExternalURL, normalizedUrl } from '../helpers/url-helpers'; |
10 | import UserAgent from './UserAgent'; | 9 | import UserAgent from './UserAgent'; |
11 | import { DEFAULT_SERVICE_ORDER, DEFAULT_SERVICE_SETTINGS } from '../config'; | 10 | import { DEFAULT_SERVICE_ORDER, DEFAULT_SERVICE_SETTINGS } from '../config'; |
12 | import { ifUndefined } from '../jsUtils'; | 11 | import { ifUndefined } from '../jsUtils'; |
@@ -327,11 +326,7 @@ export default class Service { | |||
327 | if (this.recipe.hasCustomUrl && this.customUrl) { | 326 | if (this.recipe.hasCustomUrl && this.customUrl) { |
328 | let url: string = ''; | 327 | let url: string = ''; |
329 | try { | 328 | try { |
330 | url = normalizeUrl(this.customUrl, { | 329 | url = normalizedUrl(this.customUrl); |
331 | stripAuthentication: false, | ||
332 | stripWWW: false, | ||
333 | removeTrailingSlash: false, | ||
334 | }); | ||
335 | } catch { | 330 | } catch { |
336 | console.error( | 331 | console.error( |
337 | `Service (${this.recipe.name}): '${this.customUrl}' is not a valid Url.`, | 332 | `Service (${this.recipe.name}): '${this.customUrl}' is not a valid Url.`, |