refactor /:route param

This commit is contained in:
Caleb Roseland 2023-11-24 16:43:19 -06:00
parent 89fc14bb43
commit 4a422af3d6
2 changed files with 12 additions and 10 deletions

View file

@ -169,16 +169,10 @@ export function parseDeepLink(deepLinkUrl: string): DeepLinkWithData {
return {type: DeepLink.Permalink, url: deepLinkUrl, data: {serverUrl, teamName, postId}};
}
const pluginMatch = match<{serverUrl: string; id: string; route?: string[]}>(`:serverUrl(.*)/plugins/:id(${PLUGIN_ID_PATH_PATTERN})/:route+`)(url);
const pluginMatch = match<{serverUrl: string; id: string; route?: string}>(`:serverUrl(.*)/plugins/:id(${PLUGIN_ID_PATH_PATTERN})/:route(.*)?`)(url);
if (pluginMatch) {
const {params: {serverUrl, id, route}} = pluginMatch;
const data: DeepLinkWithData['data'] = {serverUrl, teamName: '', id};
if (route) {
data.route = route.join('/');
}
return {type: DeepLink.Plugin, url: deepLinkUrl, data};
return {type: DeepLink.Plugin, url: deepLinkUrl, data: {serverUrl, teamName: '', id, route}};
}
} catch (err) {
// do nothing just return invalid deeplink

View file

@ -456,13 +456,21 @@ describe('UrlUtils', () => {
expected: null,
},
{
name: 'should not match plugin path without a route',
name: 'should match plugin path without a route',
input: {
url: DEEPLINK_URL_ROOT + '/subpath/deepsubpath/plugins/abc',
serverURL: SERVER_WITH_SUBPATH,
siteURL: SERVER_WITH_SUBPATH,
},
expected: null,
expected: {
data: {
id: 'abc',
route: undefined,
serverUrl: URL_PATH_NO_PROTOCOL,
teamName: '',
},
type: DeepLinkType.Plugin,
},
},
];