1 | import * as cidLog from "./common/cid-log.js";
|
2 | import * as common from "./common/index.js";
|
3 | import * as base64 from "./common/base64.js";
|
4 | import * as did from "./did/index.js";
|
5 | import * as path from "./path.js";
|
6 | import * as crypto from "./crypto/index.js";
|
7 | import * as storage from "./storage/index.js";
|
8 | import * as ucan from "./ucan/store.js";
|
9 | import { USERNAME_STORAGE_KEY, VERSION } from "./common/index.js";
|
10 | import { setup } from "./setup/internal.js";
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export async function authenticatedUsername() {
|
16 | return common.authenticatedUsername();
|
17 | }
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | export async function leave({ withoutRedirect } = {}) {
|
24 | await storage.removeItem(USERNAME_STORAGE_KEY);
|
25 | await ucan.clearStorage();
|
26 | await cidLog.clear();
|
27 | await crypto.keystore.clear();
|
28 | (globalThis.filesystems || []).forEach((f) => f.deactivate());
|
29 | if (!withoutRedirect && globalThis.location) {
|
30 | globalThis.location.href = setup.endpoints.lobby;
|
31 | }
|
32 | }
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | export async function redirectToLobby(permissions, redirectTo) {
|
44 | const app = permissions?.app;
|
45 | const fs = permissions?.fs;
|
46 | const platform = permissions?.platform;
|
47 | const raw = permissions?.raw;
|
48 | const exchangeDid = await did.exchange();
|
49 | const writeDid = await did.write();
|
50 | const sharedRepo = !!document.body.querySelector("iframe#webnative-ipfs") && typeof SharedWorker === "function";
|
51 | redirectTo = redirectTo || window.location.href;
|
52 |
|
53 | const params = [
|
54 | ["didExchange", exchangeDid],
|
55 | ["didWrite", writeDid],
|
56 | ["redirectTo", redirectTo],
|
57 | ["sdk", VERSION.toString()],
|
58 | ["sharedRepo", sharedRepo ? "t" : "f"]
|
59 | ].concat(app ? [["appFolder", `${app.creator}/${app.name}`]] : [], fs?.private ? fs.private.map(p => ["privatePath", path.toPosix(p, { absolute: true })]) : [], fs?.public ? fs.public.map(p => ["publicPath", path.toPosix(p, { absolute: true })]) : [], raw ? [["raw", base64.urlEncode(JSON.stringify(raw))]] : []).concat((() => {
|
60 | const apps = platform?.apps;
|
61 | switch (typeof apps) {
|
62 | case "string": return [["app", apps]];
|
63 | case "object": return apps.map(a => ["app", a]);
|
64 | default: return [];
|
65 | }
|
66 | })());
|
67 |
|
68 | window.location.href = setup.endpoints.lobby + "?" +
|
69 | params
|
70 | .map(([k, v]) => encodeURIComponent(k) + "=" + encodeURIComponent(v))
|
71 | .join("&");
|
72 | }
|
73 |
|
\ | No newline at end of file |