mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-22 23:31:12 +02:00
Fixed URL formatting logic
This commit is contained in:
parent
de0c33e7ff
commit
bf0f4e3e68
1 changed files with 10 additions and 0 deletions
|
|
@ -8,6 +8,9 @@ const ENDPOINTS_CONFIG = {
|
||||||
'api/v1/searchspaces': true
|
'api/v1/searchspaces': true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function isDetailEndpoint(url: string): boolean {
|
||||||
|
return /\/\d+$/.test(url) || /\/[a-f0-9-]{8,}$/.test(url);
|
||||||
|
}
|
||||||
|
|
||||||
function formatUrlPath(url: string): string {
|
function formatUrlPath(url: string): string {
|
||||||
let basePath = url;
|
let basePath = url;
|
||||||
|
|
@ -18,6 +21,13 @@ function formatUrlPath(url: string): string {
|
||||||
queryParams = `?${queryParams}`;
|
queryParams = `?${queryParams}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isDetailEndpoint(basePath)) {
|
||||||
|
if (basePath.endsWith('/')) {
|
||||||
|
basePath = basePath.slice(0, -1);
|
||||||
|
}
|
||||||
|
return basePath + queryParams;
|
||||||
|
}
|
||||||
|
|
||||||
let needsTrailingSlash = true;
|
let needsTrailingSlash = true;
|
||||||
|
|
||||||
for (const [endpoint, shouldHaveSlash] of Object.entries(ENDPOINTS_CONFIG)) {
|
for (const [endpoint, shouldHaveSlash] of Object.entries(ENDPOINTS_CONFIG)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue