aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers
diff options
context:
space:
mode:
authorLibravatar muhamedsalih-tw <104364298+muhamedsalih-tw@users.noreply.github.com>2022-11-20 17:35:21 +0530
committerLibravatar GitHub <noreply@github.com>2022-11-20 17:35:21 +0530
commit86f9ab693dcad951271f727046214b03d91ebd69 (patch)
tree3d32ff4814b5484495b811c5fe0ebea4805f4e55 /src/helpers
parent6.2.1-nightly.47 [skip ci] (diff)
downloadferdium-app-86f9ab693dcad951271f727046214b03d91ebd69.tar.gz
ferdium-app-86f9ab693dcad951271f727046214b03d91ebd69.tar.zst
ferdium-app-86f9ab693dcad951271f727046214b03d91ebd69.zip
Transform Todo feature, ServiceBarTargetUrl, ServiceIcon, TeamDashboard, Slider, Loader & WorkspaceSwitchningIndicator into ts (#782)
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/url-helpers.ts13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/helpers/url-helpers.ts b/src/helpers/url-helpers.ts
index 69a2cc4dc..9c5cf7752 100644
--- a/src/helpers/url-helpers.ts
+++ b/src/helpers/url-helpers.ts
@@ -1,14 +1,12 @@
1// This is taken from: https://benjamin-altpeter.de/shell-openexternal-dangers/ 1// This is taken from: https://benjamin-altpeter.de/shell-openexternal-dangers/
2
3import { URL } from 'url'; 2import { URL } from 'url';
4import { ensureDirSync, existsSync } from 'fs-extra'; 3import { ensureDirSync, existsSync } from 'fs-extra';
5import { shell } from 'electron'; 4import { shell } from 'electron';
6
7import { ALLOWED_PROTOCOLS } from '../config'; 5import { ALLOWED_PROTOCOLS } from '../config';
8 6
9const debug = require('../preload-safe-debug')('Ferdium:Helpers:url'); 7const debug = require('../preload-safe-debug')('Ferdium:Helpers:url');
10 8
11export function isValidExternalURL(url: string | URL) { 9export function isValidExternalURL(url: string | URL): boolean {
12 let parsedUrl: URL; 10 let parsedUrl: URL;
13 try { 11 try {
14 parsedUrl = new URL(url.toString()); 12 parsedUrl = new URL(url.toString());
@@ -17,13 +15,12 @@ export function isValidExternalURL(url: string | URL) {
17 } 15 }
18 16
19 const isAllowed = ALLOWED_PROTOCOLS.includes(parsedUrl.protocol); 17 const isAllowed = ALLOWED_PROTOCOLS.includes(parsedUrl.protocol);
20
21 debug('protocol check is', isAllowed, 'for:', url); 18 debug('protocol check is', isAllowed, 'for:', url);
22 19
23 return isAllowed; 20 return isAllowed;
24} 21}
25 22
26export function fixUrl(url: string | URL) { 23export function fixUrl(url: string | URL): string {
27 return url 24 return url
28 .toString() 25 .toString()
29 .replaceAll('//', '/') 26 .replaceAll('//', '/')
@@ -32,11 +29,11 @@ export function fixUrl(url: string | URL) {
32 .replaceAll('file:/', 'file://'); 29 .replaceAll('file:/', 'file://');
33} 30}
34 31
35export function isValidFileUrl(path: string) { 32export function isValidFileUrl(path: string): boolean {
36 return path.startsWith('file') && existsSync(new URL(path)); 33 return path.startsWith('file') && existsSync(new URL(path));
37} 34}
38 35
39export async function openPath(folderName: string) { 36export async function openPath(folderName: string): Promise<void> {
40 ensureDirSync(folderName); 37 ensureDirSync(folderName);
41 shell.openPath(folderName); 38 shell.openPath(folderName);
42} 39}
@@ -45,7 +42,7 @@ export async function openPath(folderName: string) {
45export function openExternalUrl( 42export function openExternalUrl(
46 url: string | URL, 43 url: string | URL,
47 skipValidityCheck: boolean = false, 44 skipValidityCheck: boolean = false,
48) { 45): void {
49 const fixedUrl = fixUrl(url.toString()); 46 const fixedUrl = fixUrl(url.toString());
50 debug('Open url:', fixedUrl, 'with skipValidityCheck:', skipValidityCheck); 47 debug('Open url:', fixedUrl, 'with skipValidityCheck:', skipValidityCheck);
51 if (skipValidityCheck || isValidExternalURL(fixedUrl)) { 48 if (skipValidityCheck || isValidExternalURL(fixedUrl)) {