mirror of
https://github.com/Xevion/dynamic-preauth.git
synced 2025-12-06 15:14:59 -06:00
toHex, basic deleteDownload func, fix badge display token
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import Badge from "@/components/Badge";
|
import Badge from "@/components/Badge";
|
||||||
import Emboldened from "@/components/Emboldened";
|
import Emboldened from "@/components/Emboldened";
|
||||||
import useSocket from "@/components/useSocket";
|
import useSocket from "@/components/useSocket";
|
||||||
import { cn, plural, type ClassValue } from "@/util";
|
import { cn, plural, toHex, type ClassValue } from "@/util";
|
||||||
import { useRef, useState } from "preact/hooks";
|
import { useRef, useState } from "preact/hooks";
|
||||||
|
|
||||||
type DemoProps = {
|
type DemoProps = {
|
||||||
@@ -42,7 +42,7 @@ const Demo = ({ class: className }: DemoProps) => {
|
|||||||
<br />
|
<br />
|
||||||
Your session is{" "}
|
Your session is{" "}
|
||||||
<Emboldened skeletonWidth="0x1234567890ABCDEF" copyable={true}>
|
<Emboldened skeletonWidth="0x1234567890ABCDEF" copyable={true}>
|
||||||
{id != null ? "0x" + id?.toString(16).toUpperCase() : null}
|
{id != null ? toHex(id) : null}
|
||||||
</Emboldened>
|
</Emboldened>
|
||||||
. You have{" "}
|
. You have{" "}
|
||||||
<Emboldened className="text-teal-400 font-inter">
|
<Emboldened className="text-teal-400 font-inter">
|
||||||
@@ -66,7 +66,7 @@ const Demo = ({ class: className }: DemoProps) => {
|
|||||||
audio.play();
|
audio.play();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{download}
|
{toHex(download.token)}
|
||||||
</Badge>
|
</Badge>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useState } from "preact/hooks";
|
import { useEffect, useRef, useState } from "preact/hooks";
|
||||||
|
|
||||||
interface Download {
|
interface Download {
|
||||||
token: number;
|
token: number;
|
||||||
@@ -24,8 +24,23 @@ function useSocket(): UseSocketResult {
|
|||||||
const [id, setId] = useState<number | null>(null);
|
const [id, setId] = useState<number | null>(null);
|
||||||
const [downloads, setDownloads] = useState<Download[] | null>(null);
|
const [downloads, setDownloads] = useState<Download[] | null>(null);
|
||||||
const [executables, setExecutables] = useState<Executable[] | null>(null);
|
const [executables, setExecutables] = useState<Executable[] | null>(null);
|
||||||
|
const socketRef = useRef<WebSocket | null>(null);
|
||||||
|
|
||||||
function deleteDownload() {}
|
function deleteDownload(download_token: number) {
|
||||||
|
if (socketRef.current == null) {
|
||||||
|
console.error("Socket is null");
|
||||||
|
return;
|
||||||
|
} else if (socketRef.current.readyState !== WebSocket.OPEN) {
|
||||||
|
console.error("Socket is not open", socketRef.current.readyState);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
socketRef.current.send(
|
||||||
|
JSON.stringify({
|
||||||
|
type: "delete",
|
||||||
|
token: download_token,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const socket = new WebSocket(
|
const socket = new WebSocket(
|
||||||
@@ -33,6 +48,7 @@ function useSocket(): UseSocketResult {
|
|||||||
(import.meta.env.DEV ? "localhost:5800" : window.location.host) +
|
(import.meta.env.DEV ? "localhost:5800" : window.location.host) +
|
||||||
"/ws"
|
"/ws"
|
||||||
);
|
);
|
||||||
|
socketRef.current = socket;
|
||||||
|
|
||||||
socket.onmessage = (event) => {
|
socket.onmessage = (event) => {
|
||||||
const data = JSON.parse(event.data);
|
const data = JSON.parse(event.data);
|
||||||
@@ -42,7 +58,7 @@ function useSocket(): UseSocketResult {
|
|||||||
|
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case "state":
|
case "state":
|
||||||
setId(data.id as number);
|
setId(data.session.id as number);
|
||||||
setDownloads(data.session.downloads as Download[]);
|
setDownloads(data.session.downloads as Download[]);
|
||||||
break;
|
break;
|
||||||
case "executables":
|
case "executables":
|
||||||
|
|||||||
@@ -18,3 +18,7 @@ export function os(): Platform | "other" {
|
|||||||
else if (navigator.userAgent.includes("linux")) return "linux";
|
else if (navigator.userAgent.includes("linux")) return "linux";
|
||||||
return "other";
|
return "other";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toHex(value: number): string {
|
||||||
|
return "0x" + value.toString(16).toUpperCase();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user