From 86f9ab693dcad951271f727046214b03d91ebd69 Mon Sep 17 00:00:00 2001 From: muhamedsalih-tw <104364298+muhamedsalih-tw@users.noreply.github.com> Date: Sun, 20 Nov 2022 17:35:21 +0530 Subject: Transform Todo feature, ServiceBarTargetUrl, ServiceIcon, TeamDashboard, Slider, Loader & WorkspaceSwitchningIndicator into ts (#782) --- src/helpers/url-helpers.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/helpers') 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 @@ // This is taken from: https://benjamin-altpeter.de/shell-openexternal-dangers/ - import { URL } from 'url'; import { ensureDirSync, existsSync } from 'fs-extra'; import { shell } from 'electron'; - import { ALLOWED_PROTOCOLS } from '../config'; const debug = require('../preload-safe-debug')('Ferdium:Helpers:url'); -export function isValidExternalURL(url: string | URL) { +export function isValidExternalURL(url: string | URL): boolean { let parsedUrl: URL; try { parsedUrl = new URL(url.toString()); @@ -17,13 +15,12 @@ export function isValidExternalURL(url: string | URL) { } const isAllowed = ALLOWED_PROTOCOLS.includes(parsedUrl.protocol); - debug('protocol check is', isAllowed, 'for:', url); return isAllowed; } -export function fixUrl(url: string | URL) { +export function fixUrl(url: string | URL): string { return url .toString() .replaceAll('//', '/') @@ -32,11 +29,11 @@ export function fixUrl(url: string | URL) { .replaceAll('file:/', 'file://'); } -export function isValidFileUrl(path: string) { +export function isValidFileUrl(path: string): boolean { return path.startsWith('file') && existsSync(new URL(path)); } -export async function openPath(folderName: string) { +export async function openPath(folderName: string): Promise { ensureDirSync(folderName); shell.openPath(folderName); } @@ -45,7 +42,7 @@ export async function openPath(folderName: string) { export function openExternalUrl( url: string | URL, skipValidityCheck: boolean = false, -) { +): void { const fixedUrl = fixUrl(url.toString()); debug('Open url:', fixedUrl, 'with skipValidityCheck:', skipValidityCheck); if (skipValidityCheck || isValidExternalURL(fixedUrl)) { -- cgit v1.2.3-54-g00ecf