(qol): update todo
This commit is contained in:
parent
30722b6168
commit
3225b4e652
5 changed files with 82 additions and 21 deletions
|
|
@ -23,7 +23,7 @@ const fetchedUser = z.object({
|
||||||
});
|
});
|
||||||
|
|
||||||
const formSchema = z.object({
|
const formSchema = z.object({
|
||||||
username: z.string().min(1).max(15),
|
username: z.string().min(1).max(255),
|
||||||
private_key: z.string().min(1).max(92),
|
private_key: z.string().min(1).max(92),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -35,6 +35,7 @@ const formSchema = z.object({
|
||||||
function parseTuFileContent(rawFileContent: string): {
|
function parseTuFileContent(rawFileContent: string): {
|
||||||
userId: number;
|
userId: number;
|
||||||
privateKey: string;
|
privateKey: string;
|
||||||
|
domain: string | null;
|
||||||
} {
|
} {
|
||||||
if (rawFileContent.trim().length === 0) {
|
if (rawFileContent.trim().length === 0) {
|
||||||
throw new Error("File is empty");
|
throw new Error("File is empty");
|
||||||
|
|
@ -42,21 +43,40 @@ function parseTuFileContent(rawFileContent: string): {
|
||||||
throw new Error("Invalid file");
|
throw new Error("Invalid file");
|
||||||
} else if (rawFileContent.split("::").length !== 2) {
|
} else if (rawFileContent.split("::").length !== 2) {
|
||||||
throw new Error("Invalid file");
|
throw new Error("Invalid file");
|
||||||
} else if (rawFileContent.split("::")[0].length === 0) {
|
}
|
||||||
|
|
||||||
|
const left = rawFileContent.split("::")[0];
|
||||||
|
const right = rawFileContent.split("::")[1];
|
||||||
|
|
||||||
|
if (left.length === 0) {
|
||||||
throw new Error("Invalid file");
|
throw new Error("Invalid file");
|
||||||
} else if (rawFileContent.split("::")[1].length === 0) {
|
} else if (right.length === 0) {
|
||||||
throw new Error("Invalid file");
|
throw new Error("Invalid file");
|
||||||
} else if (isNaN(Number(rawFileContent.split("::")[0]))) {
|
} else if (isNaN(Number(left)) && !left.includes("@")) {
|
||||||
throw new Error("Invalid file");
|
throw new Error("Invalid file");
|
||||||
}
|
}
|
||||||
|
|
||||||
const [userIdString, privateKey] = rawFileContent.split("::");
|
const [userIdString, privateKey] = rawFileContent.split("::");
|
||||||
const userId = Number(userIdString);
|
const userId = isNaN(Number(userIdString))
|
||||||
|
? Number(userIdString.split("@")[0])
|
||||||
|
: Number(userIdString);
|
||||||
|
|
||||||
|
const rawDomain = userIdString.includes("@")
|
||||||
|
? userIdString.split("@")[1]
|
||||||
|
: null;
|
||||||
|
const domain = rawDomain ? (rawDomain.includes(":") ? rawDomain : rawDomain + ":1984") : null;
|
||||||
|
|
||||||
if (!userId || !privateKey) {
|
if (!userId || !privateKey) {
|
||||||
throw new Error("Invalid file");
|
throw new Error("Invalid file");
|
||||||
}
|
}
|
||||||
|
|
||||||
return { userId, privateKey };
|
console.log({
|
||||||
|
domain,
|
||||||
|
rawDomain,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
|
||||||
|
return { userId, privateKey, domain };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -86,6 +106,9 @@ export default function Form() {
|
||||||
await save("session_id", Date.now());
|
await save("session_id", Date.now());
|
||||||
await save("user_id", parsed.userId);
|
await save("user_id", parsed.userId);
|
||||||
await save("private_key", parsed.privateKey);
|
await save("private_key", parsed.privateKey);
|
||||||
|
if (parsed.domain) {
|
||||||
|
await save("ttp_url", `https://${parsed.domain}/`);
|
||||||
|
}
|
||||||
|
|
||||||
location.href = "/";
|
location.href = "/";
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -114,9 +137,14 @@ export default function Form() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const inputUsername = inputParse.data.username;
|
||||||
|
const actualUsername = inputUsername.includes("@") ? inputUsername.split("@")[0] : inputUsername;
|
||||||
|
const rawDomain = inputUsername.includes("@") ? inputUsername.split("@")[1] : null;
|
||||||
|
const domain = rawDomain ? (rawDomain.includes(":") ? rawDomain : rawDomain + ":1984") : null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`https://omega.tensamin.net/api/get/id/${inputParse.data.username}`,
|
`https://omega.tensamin.net/api/get/id/${actualUsername}`,
|
||||||
);
|
);
|
||||||
const rawData = await response.arrayBuffer();
|
const rawData = await response.arrayBuffer();
|
||||||
|
|
||||||
|
|
@ -137,6 +165,9 @@ export default function Form() {
|
||||||
await save("session_id", Date.now());
|
await save("session_id", Date.now());
|
||||||
await save("user_id", user.user_id);
|
await save("user_id", user.user_id);
|
||||||
await save("private_key", inputParse.data.private_key);
|
await save("private_key", inputParse.data.private_key);
|
||||||
|
if (domain) {
|
||||||
|
await save("ttp_url", `https://${domain}/`);
|
||||||
|
}
|
||||||
|
|
||||||
location.href = "/";
|
location.href = "/";
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -154,7 +185,7 @@ export default function Form() {
|
||||||
{isTauriEnv ? (
|
{isTauriEnv ? (
|
||||||
<>
|
<>
|
||||||
<QrCodeScanner
|
<QrCodeScanner
|
||||||
onData={(data) => {
|
onData={async (data) => {
|
||||||
if (!data.startsWith("tensamin://tu::")) {
|
if (!data.startsWith("tensamin://tu::")) {
|
||||||
toast("error", "Invalid QR code");
|
toast("error", "Invalid QR code");
|
||||||
return;
|
return;
|
||||||
|
|
@ -162,10 +193,14 @@ export default function Form() {
|
||||||
const decoded = data.replace("tensamin://tu::", "");
|
const decoded = data.replace("tensamin://tu::", "");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { userId, privateKey } = parseTuFileContent(decoded);
|
const { userId, privateKey, domain } =
|
||||||
save("session_id", Date.now());
|
parseTuFileContent(decoded);
|
||||||
save("user_id", userId);
|
await save("session_id", Date.now());
|
||||||
save("private_key", privateKey);
|
await save("user_id", userId);
|
||||||
|
await save("private_key", privateKey);
|
||||||
|
if (domain) {
|
||||||
|
await save("ttp_url", `https://${domain}/`);
|
||||||
|
}
|
||||||
location.href = "/";
|
location.href = "/";
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log(0, "login", "red", error);
|
log(0, "login", "red", error);
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
- Make the sidebar use <Activity /> to make it feel less slow on mobile
|
- Make the sidebar use <Activity /> to make it feel less slow on mobile
|
||||||
|
- Add logout button
|
||||||
|
|
|
||||||
|
|
@ -244,6 +244,7 @@ export interface Storage extends SettingsStorageDefaults {
|
||||||
legal_docs: z.infer<typeof legalDocsSchema>;
|
legal_docs: z.infer<typeof legalDocsSchema>;
|
||||||
cached_contacts: Contacts;
|
cached_contacts: Contacts;
|
||||||
cached_communities: Communities;
|
cached_communities: Communities;
|
||||||
|
ttp_url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const storageDefaults: Storage = {
|
export const storageDefaults: Storage = {
|
||||||
|
|
@ -276,4 +277,5 @@ export const storageDefaults: Storage = {
|
||||||
},
|
},
|
||||||
cached_contacts: [],
|
cached_contacts: [],
|
||||||
cached_communities: [],
|
cached_communities: [],
|
||||||
|
ttp_url: "https://tensamin.net:959",
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ import {
|
||||||
RECONNECT_RESET,
|
RECONNECT_RESET,
|
||||||
RECONNECT_TRIES,
|
RECONNECT_TRIES,
|
||||||
RETRY_INTERVAL,
|
RETRY_INTERVAL,
|
||||||
TRANSPORT_URL,
|
|
||||||
} from "./values";
|
} from "./values";
|
||||||
import {
|
import {
|
||||||
type Calls,
|
type Calls,
|
||||||
|
|
@ -193,6 +192,14 @@ export function Provider(props: {
|
||||||
> | null>(null);
|
> | null>(null);
|
||||||
const identificationStartedRef = useRef(false);
|
const identificationStartedRef = useRef(false);
|
||||||
|
|
||||||
|
// Load ttp url
|
||||||
|
const [ttpUrl, setTtpUrl] = useState<string | null>(null);
|
||||||
|
useEffect(() => {
|
||||||
|
load("ttp_url").then((url) => {
|
||||||
|
setTtpUrl(url);
|
||||||
|
});
|
||||||
|
}, [load]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends typed protocol messages through the active transport client.
|
* Sends typed protocol messages through the active transport client.
|
||||||
* @param type Protocol message type.
|
* @param type Protocol message type.
|
||||||
|
|
@ -266,6 +273,10 @@ export function Provider(props: {
|
||||||
}, [connected, identified, send]);
|
}, [connected, identified, send]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!ttpUrl) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let attempts = 0;
|
let attempts = 0;
|
||||||
let reconnectTimer: ReturnType<typeof setTimeout> | null = null;
|
let reconnectTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
let reconnectResetTimer: ReturnType<typeof setTimeout> | null = null;
|
let reconnectResetTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
|
@ -343,7 +354,7 @@ export function Provider(props: {
|
||||||
|
|
||||||
const transportClient = !props.blockConnection
|
const transportClient = !props.blockConnection
|
||||||
? createTransportClient(schemas, {
|
? createTransportClient(schemas, {
|
||||||
url: TRANSPORT_URL,
|
url: ttpUrl,
|
||||||
onReadyStateChange: (state) => {
|
onReadyStateChange: (state) => {
|
||||||
currentReadyState = state;
|
currentReadyState = state;
|
||||||
setReadyState(state);
|
setReadyState(state);
|
||||||
|
|
@ -392,8 +403,12 @@ export function Provider(props: {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ttpUrl) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await transportClient?.connect(TRANSPORT_URL);
|
await transportClient?.connect(ttpUrl);
|
||||||
} catch (connectError) {
|
} catch (connectError) {
|
||||||
if (disposed) {
|
if (disposed) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -460,7 +475,7 @@ export function Provider(props: {
|
||||||
setIdentifying(false);
|
setIdentifying(false);
|
||||||
identificationStartedRef.current = false;
|
identificationStartedRef.current = false;
|
||||||
};
|
};
|
||||||
}, [props.blockConnection]);
|
}, [props.blockConnection, ttpUrl]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
|
|
@ -603,14 +618,19 @@ export function Provider(props: {
|
||||||
}, [connected, decrypt, getSharedSecret, load, send]);
|
}, [connected, decrypt, getSharedSecret, load, send]);
|
||||||
|
|
||||||
const progress = useMemo(() => {
|
const progress = useMemo(() => {
|
||||||
|
if (!ttpUrl) return 10;
|
||||||
if (readyState === READY_STATE.CONNECTING) return 30;
|
if (readyState === READY_STATE.CONNECTING) return 30;
|
||||||
if (!connected) return 45;
|
if (!connected) return 45;
|
||||||
if (identifying) return 75;
|
if (identifying) return 75;
|
||||||
if (!identified) return 90;
|
if (!identified) return 90;
|
||||||
return 100;
|
return 100;
|
||||||
}, [connected, identified, identifying, readyState]);
|
}, [connected, identified, identifying, readyState, ttpUrl]);
|
||||||
|
|
||||||
const loadingTitle = useMemo(() => {
|
const loadingTitle = useMemo(() => {
|
||||||
|
if (!ttpUrl) {
|
||||||
|
return "Looking up configuration";
|
||||||
|
}
|
||||||
|
|
||||||
if (readyState === READY_STATE.CONNECTING || !connected) {
|
if (readyState === READY_STATE.CONNECTING || !connected) {
|
||||||
return "Connecting to Tensamin";
|
return "Connecting to Tensamin";
|
||||||
}
|
}
|
||||||
|
|
@ -620,9 +640,13 @@ export function Provider(props: {
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Loading";
|
return "Loading";
|
||||||
}, [connected, identified, identifying, readyState]);
|
}, [connected, identified, identifying, readyState, ttpUrl]);
|
||||||
|
|
||||||
const loadingDescription = useMemo(() => {
|
const loadingDescription = useMemo(() => {
|
||||||
|
if (!ttpUrl) {
|
||||||
|
return "Loading connection details";
|
||||||
|
}
|
||||||
|
|
||||||
if (readyState === READY_STATE.CONNECTING || !connected) {
|
if (readyState === READY_STATE.CONNECTING || !connected) {
|
||||||
return "Establishing transport channel";
|
return "Establishing transport channel";
|
||||||
}
|
}
|
||||||
|
|
@ -632,13 +656,13 @@ export function Provider(props: {
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}, [connected, identified, identifying, readyState]);
|
}, [connected, identified, identifying, readyState, ttpUrl]);
|
||||||
|
|
||||||
if (error !== "" && errorDescription !== "") {
|
if (error !== "" && errorDescription !== "") {
|
||||||
return <ErrorScreen error={error} description={errorDescription} />;
|
return <ErrorScreen error={error} description={errorDescription} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!connected || !identified) {
|
if (!connected || !identified || !ttpUrl) {
|
||||||
return (
|
return (
|
||||||
<Loading
|
<Loading
|
||||||
progress={progress}
|
progress={progress}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,5 @@ export const RESPONSE_TIMEOUT = 15_000;
|
||||||
export const RETRY_COUNT = 10;
|
export const RETRY_COUNT = 10;
|
||||||
export const RETRY_INTERVAL = 3_000;
|
export const RETRY_INTERVAL = 3_000;
|
||||||
export const PING_INTERVAL = 3_000;
|
export const PING_INTERVAL = 3_000;
|
||||||
export const TRANSPORT_URL = "https://tensamin.net:959";
|
|
||||||
export const RECONNECT_TRIES = 3;
|
export const RECONNECT_TRIES = 3;
|
||||||
export const RECONNECT_RESET = 6;
|
export const RECONNECT_RESET = 6;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue