share funxtions
This commit is contained in:
+10
-3
@@ -3,13 +3,15 @@ installGlobalDiagnostics();
|
||||
|
||||
import { api } from "@rustpad/api";
|
||||
import { copyText } from "@rustpad/clipboard";
|
||||
import { getNickname, getAccessToken, setAccessToken } from "@rustpad/session";
|
||||
import { getNickname, getAccessToken, getAuthToken, setAccessToken } from "@rustpad/session";
|
||||
import { askConfirm } from "./modal.js";
|
||||
|
||||
const parts = location.pathname.split("/").filter(Boolean);
|
||||
const slug = parts[1];
|
||||
let info;
|
||||
let accessToken = getAccessToken("workspace", slug);
|
||||
const shareToken=new URLSearchParams(location.search).get("share");
|
||||
let accessToken=shareToken||getAuthToken()||getAccessToken("workspace",slug);
|
||||
if(shareToken)setAccessToken("workspace",slug,shareToken);
|
||||
const dialog = document.querySelector("#password-dialog");
|
||||
const notesList = document.querySelector("#notes-list");
|
||||
const notesViewKey = `rustpad:workspace:${slug}:notes-view`;
|
||||
@@ -89,6 +91,8 @@ async function openWorkspace() {
|
||||
if (info?.protected || e.message.toLowerCase().includes("password")) {
|
||||
document.querySelector("#password-error").textContent = e.message;
|
||||
if (!dialog.open) dialog.showModal();
|
||||
} else if (e.status === 403) {
|
||||
location.replace("/errors/private-workspace");
|
||||
} else document.querySelector("#workspace-error").textContent = e.message;
|
||||
}
|
||||
}
|
||||
@@ -98,7 +102,10 @@ async function init() {
|
||||
document.querySelector("#workspace-title").textContent = info.title;
|
||||
document.querySelector("#workspace-url").textContent = location.pathname;
|
||||
if (info.protected && !accessToken) dialog.showModal(); else openWorkspace();
|
||||
} catch (e) { document.querySelector("#workspace-error").textContent = e.message; }
|
||||
} catch (e) {
|
||||
if (e.status === 403) location.replace("/errors/private-workspace");
|
||||
else document.querySelector("#workspace-error").textContent = e.message;
|
||||
}
|
||||
}
|
||||
document.querySelector("#password-form").addEventListener("submit", async e => {
|
||||
e.preventDefault();
|
||||
|
||||
Reference in New Issue
Block a user