init
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
import { getNodeBySlug, getUserLifecycleState } from "@/lib/store";
|
||||
|
||||
export function parseHy2Userpass(auth: string) {
|
||||
const separator = auth.indexOf(":");
|
||||
if (separator <= 0 || separator === auth.length - 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
username: auth.slice(0, separator),
|
||||
password: auth.slice(separator + 1),
|
||||
};
|
||||
}
|
||||
|
||||
export async function verifyNodeToken(slug: string, token: string | null) {
|
||||
const node = await getNodeBySlug(slug);
|
||||
if (!node) {
|
||||
return { ok: false, reason: "node_not_found" as const, node: null };
|
||||
}
|
||||
|
||||
if (!node.enabled) {
|
||||
return { ok: false, reason: "node_disabled" as const, node };
|
||||
}
|
||||
|
||||
if (!token || token !== node.auth_token) {
|
||||
return { ok: false, reason: "node_token_invalid" as const, node };
|
||||
}
|
||||
|
||||
return { ok: true, reason: "ok" as const, node };
|
||||
}
|
||||
|
||||
export function evaluateUserForAuth(user: {
|
||||
enabled: number;
|
||||
expires_at: string | null;
|
||||
traffic_limit_bytes: number | null;
|
||||
used_tx_bytes: number;
|
||||
used_rx_bytes: number;
|
||||
}) {
|
||||
return getUserLifecycleState(user);
|
||||
}
|
||||
Reference in New Issue
Block a user