Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ export const isLoadingLocalReplit = baseUrl.includes('localhost');
export const isLoadingStagingReplit = baseUrl.includes('staging');
export const isLoadingProdReplit = baseUrl === defaultBaseUrl;

export const workspaceUrlRegex = /^\/@\S+\/\S+/;
// Generated using path-to-regexp, the same package express uses to parse routes.
// See: https://github.com/pillarjs/path-to-regexp
// Matches /@:username/:slug
export const personalReplUrlRegex = /^\/@([^/#?]+?)(?:\/([^/#?]+?))[/#?]?$/i;
// Matches /t/:orgSlug/:orgId/repls/:replSlug
export const teamReplUrlRegex =
/^\/t(?:\/([^/#?]+?))(?:\/([^/#?]+?))\/repls(?:\/([^/#?]+?))[/#?]?$/i;

export const homePage = '/desktopApp/home';
export const authPage = '/desktopApp/auth';
Expand Down
8 changes: 6 additions & 2 deletions src/createWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
appName as title,
baseUrl,
preloadScript as preload,
workspaceUrlRegex,
teamReplUrlRegex,
personalReplUrlRegex,
homePage,
isProduction,
} from './constants';
Expand Down Expand Up @@ -54,7 +55,10 @@ function setLastOpenRepl(url: string, lastOpenRepl: string | null) {
return;
}

if (!workspaceUrlRegex.test(u.pathname)) {
if (
!personalReplUrlRegex.test(u.pathname) &&
!teamReplUrlRegex.test(u.pathname)
) {
return;
}

Expand Down
7 changes: 4 additions & 3 deletions src/deeplink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { isWindows, isLinux } from './platform';
import {
baseUrl,
protocol,
workspaceUrlRegex,
personalReplUrlRegex,
teamReplUrlRegex,
semverRegex,
authPage,
homePage,
Expand Down Expand Up @@ -127,8 +128,8 @@ function handleNew(language: string) {
}

function handleRepl(url: string) {
if (!workspaceUrlRegex.test(url)) {
log.error('Expected URL of the format /@username/slug');
if (!personalReplUrlRegex.test(url) && !teamReplUrlRegex.test(url)) {
log.error('Expected valid workspace URL');

return;
}
Expand Down
9 changes: 7 additions & 2 deletions src/isSupportedPage.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { desktopAppPrefix, workspaceUrlRegex } from './constants';
import {
desktopAppPrefix,
personalReplUrlRegex,
teamReplUrlRegex,
} from './constants';

const supportedNonDesktopAppPages = ['logout'];

export default function isSupportedPage(page: string): boolean {
return (
page.startsWith(desktopAppPrefix) ||
workspaceUrlRegex.test(page) ||
personalReplUrlRegex.test(page) ||
teamReplUrlRegex.test(page) ||
supportedNonDesktopAppPages.includes(page)
);
}