fix2 tokens
This commit is contained in:
@@ -9,40 +9,6 @@
|
||||
|
||||
const VIEWS = new Set(["edit", "split", "preview"]);
|
||||
const MODES = new Set(["markdown", "text"]);
|
||||
const APP_URL_BASE = globalThis.location?.origin || "https://rustpad.invalid";
|
||||
|
||||
function appUrl(path) {
|
||||
try {
|
||||
const url = new URL(path, APP_URL_BASE);
|
||||
return url.origin === APP_URL_BASE ? url : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function relativeUrl(url) {
|
||||
return `${url.pathname}${url.search}${url.hash}`;
|
||||
}
|
||||
|
||||
export function withShareToken(path, shareToken) {
|
||||
const url = appUrl(path);
|
||||
if (!url) return "/";
|
||||
const token = typeof shareToken === "string" ? shareToken.trim() : "";
|
||||
if (token) url.searchParams.set("share", token);
|
||||
else url.searchParams.delete("share");
|
||||
return relativeUrl(url);
|
||||
}
|
||||
|
||||
export function editorResourceUrl(path, { shareToken = "", view = "split", mode = "markdown" } = {}) {
|
||||
const url = appUrl(path);
|
||||
if (!url) return "/";
|
||||
if (VIEWS.has(view)) url.searchParams.set("view", view);
|
||||
if (MODES.has(mode)) url.searchParams.set("mode", mode);
|
||||
const token = typeof shareToken === "string" ? shareToken.trim() : "";
|
||||
if (token) url.searchParams.set("share", token);
|
||||
else url.searchParams.delete("share");
|
||||
return relativeUrl(url);
|
||||
}
|
||||
|
||||
export function readEditorState() {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
|
||||
Reference in New Issue
Block a user