feat(pwa): add base
All checks were successful
/ build-web (push) Successful in 5m35s
/ build-desktop (linux) (push) Successful in 9m41s
/ build-mobile (push) Successful in 20m12s
/ release (push) Successful in 1m51s
Dependency builds / Build web (pull_request) Has been skipped
Dependency builds / Build desktop (pull_request) Has been skipped
Dependency builds / Build mobile (pull_request) Has been skipped
All checks were successful
/ build-web (push) Successful in 5m35s
/ build-desktop (linux) (push) Successful in 9m41s
/ build-mobile (push) Successful in 20m12s
/ release (push) Successful in 1m51s
Dependency builds / Build web (pull_request) Has been skipped
Dependency builds / Build desktop (pull_request) Has been skipped
Dependency builds / Build mobile (pull_request) Has been skipped
This commit is contained in:
parent
6e977bca7e
commit
7b36218ffa
40 changed files with 4014 additions and 922 deletions
68
packages/storage/src/credentials.ts
Normal file
68
packages/storage/src/credentials.ts
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
import { invoke, isTauri } from "@tauri-apps/api/core";
|
||||
|
||||
import type { StorageContextValue } from "./context";
|
||||
|
||||
export function parseTuFileContent(rawFileContent: string): {
|
||||
userId: number;
|
||||
privateKey: string;
|
||||
domain: string | null;
|
||||
} {
|
||||
const content = rawFileContent.trim();
|
||||
const separator = content.indexOf("::");
|
||||
if (separator <= 0 || separator !== content.lastIndexOf("::")) {
|
||||
throw new Error("Invalid file");
|
||||
}
|
||||
|
||||
const identity = content.slice(0, separator);
|
||||
const privateKey = content.slice(separator + 2).trim();
|
||||
const [userIdValue, domain, ...extraDomainParts] = identity.split("@");
|
||||
const userId = Number(userIdValue);
|
||||
if (
|
||||
!Number.isSafeInteger(userId) ||
|
||||
userId <= 0 ||
|
||||
!privateKey ||
|
||||
extraDomainParts.length > 0 ||
|
||||
(identity.includes("@") && !domain)
|
||||
) {
|
||||
throw new Error("Invalid file");
|
||||
}
|
||||
|
||||
return { userId, privateKey, domain: domain ?? null };
|
||||
}
|
||||
|
||||
export async function persistMtpCredentials({
|
||||
storage,
|
||||
userId,
|
||||
keyring,
|
||||
domain,
|
||||
}: {
|
||||
storage: Pick<StorageContextValue, "load" | "save">;
|
||||
userId: number;
|
||||
keyring: string;
|
||||
domain?: string | null;
|
||||
}) {
|
||||
const omegaUrl = domain
|
||||
? `https://${domain}/`
|
||||
: await storage.load("omega_url");
|
||||
if (domain) await storage.save("omega_url", omegaUrl);
|
||||
|
||||
if (isTauri()) {
|
||||
const [forcedOmikronUrl, forcedOmikronPublicKey] = await Promise.all([
|
||||
storage.load("forced_omikron_url"),
|
||||
storage.load("forced_omikron_public_key"),
|
||||
]);
|
||||
await invoke("mtp_store_credentials", {
|
||||
config: {
|
||||
userId,
|
||||
keyring,
|
||||
omegaUrl,
|
||||
forcedOmikronUrl,
|
||||
forcedOmikronPublicKey,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
await storage.save("mtp_keyring", keyring, { secure: true });
|
||||
await storage.save("session_id", Date.now());
|
||||
await storage.save("user_id", userId);
|
||||
}
|
||||
Loading…
Reference in a new issue