🩹 back: tolerate extraneous /s in env vars
This commit is contained in:
committed by
Anton Shepilov
parent
00f819fb6d
commit
dcadfa4231
@@ -16,6 +16,7 @@ import path from "path";
|
|||||||
import { existsSync } from "fs";
|
import { existsSync } from "fs";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import short, { Translator } from "short-uuid";
|
import short, { Translator } from "short-uuid";
|
||||||
|
import { joinURL } from "../../../../utils/urls";
|
||||||
|
|
||||||
export default class EmailPusherClass
|
export default class EmailPusherClass
|
||||||
extends TdriveService<EmailPusherAPI>
|
extends TdriveService<EmailPusherAPI>
|
||||||
@@ -86,7 +87,14 @@ export default class EmailPusherClass
|
|||||||
const encodedCompanyId = translator.fromUUID(data.notifications[0].item.company_id);
|
const encodedCompanyId = translator.fromUUID(data.notifications[0].item.company_id);
|
||||||
const encodedItemId = translator.fromUUID(data.notifications[0].item.id);
|
const encodedItemId = translator.fromUUID(data.notifications[0].item.id);
|
||||||
const previewType = data.notifications[0].item.is_directory ? "d" : "preview";
|
const previewType = data.notifications[0].item.is_directory ? "d" : "preview";
|
||||||
const encodedUrl = `${this.platformUrl}/client/${encodedCompanyId}/v/shared_with_me/${previewType}/${encodedItemId}`;
|
const encodedUrl = joinURL([
|
||||||
|
this.platformUrl,
|
||||||
|
"client",
|
||||||
|
encodedCompanyId,
|
||||||
|
"v/shared_with_me",
|
||||||
|
previewType,
|
||||||
|
encodedItemId,
|
||||||
|
]);
|
||||||
|
|
||||||
if (!existsSync(templatePath)) {
|
if (!existsSync(templatePath)) {
|
||||||
throw Error(`template not found: ${templatePath}`);
|
throw Error(`template not found: ${templatePath}`);
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/** Suitable type for query arguments */
|
||||||
|
export type QueryParams = { [key: string]: string | number };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compose a URL removing and adding slashes and query parameters as warranted.
|
||||||
|
* Does not encode paths.
|
||||||
|
*/
|
||||||
|
export function joinURL(path: string[], params?: QueryParams) {
|
||||||
|
let joinedPath = path.map(x => x.replace(/(?:^\/+)|(?:\/+$)/g, "")).join("/");
|
||||||
|
if (path[path.length - 1].endsWith("/")) joinedPath += "/";
|
||||||
|
const paramEntries = Object.entries(params || {}).filter(
|
||||||
|
([, value]) => value !== undefined && value !== null,
|
||||||
|
);
|
||||||
|
if (paramEntries.length === 0) return joinedPath;
|
||||||
|
const query = paramEntries.map(p => p.map(encodeURIComponent).join("=")).join("&");
|
||||||
|
return joinedPath + (joinedPath.indexOf("?") > -1 ? "&" : "?") + query;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user