dx4 v2
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
// CHANGE TO YOUR API DESTINATION
|
||||
export const API_BASE_URL = "http://localhost:8321/admin_api.php";
|
||||
// export const API_BASE_URL = "http://192.168.3.10:8321/admin_api.php";
|
||||
// export const API_BASE_URL = "http://x90620bx.beget.tech/dx4back/admin_api.php"
|
||||
|
||||
// TYPE: url/dx4/
|
||||
export const CLIENT_FRONTEND_URL = "http://localhost:5173/dx4/";
|
||||
// export const CLIENT_FRONTEND_URL = "http://x90620bx.beget.tech/dx4/";
|
||||
|
||||
import { atom, useAtom } from "jotai";
|
||||
import { atomWithStorage } from "jotai/utils";
|
||||
import { useEffect } from "react";
|
||||
import LoginPage from "./pages/LoginPage";
|
||||
import DashPage from "./pages/DashPage";
|
||||
import ClassProfilePage from "./pages/ClassProfile";
|
||||
const passAtom = atomWithStorage("DX4DASH_pass", "");
|
||||
|
||||
// KATAMAZ DENGI ROUTER 4 PRO MAX ULTIMATE (from dx4, yeah, oh now in typescript)
|
||||
// 💀💀
|
||||
// PROS - vrode raboatat,
|
||||
// too simple, lightweight, stupidly fast
|
||||
// (beacause you basicly download entire site, lol)
|
||||
// CONS - shit
|
||||
function firstPathSegment(path: string) {
|
||||
const m = path.match(/^\/?([^/]+)/);
|
||||
return m ? m[1] : "";
|
||||
}
|
||||
const secondPathSegment = (p: string) =>
|
||||
p.replace(/^\/?[^/]+/, "").replace(/^\/+/, "");
|
||||
|
||||
const routeAtom = atom("/");
|
||||
const basePageProps = {
|
||||
// atoms
|
||||
passAtom,
|
||||
routeAtom,
|
||||
|
||||
// fucntions
|
||||
setsetRoute,
|
||||
secondPathSegment,
|
||||
|
||||
// constants
|
||||
API_BASE_URL,
|
||||
};
|
||||
|
||||
const pages = {
|
||||
"/": <LoginPage {...basePageProps} />,
|
||||
"/dash": <DashPage {...basePageProps} />,
|
||||
"/class": <ClassProfilePage {...basePageProps} />,
|
||||
};
|
||||
|
||||
let changeAnchor = true;
|
||||
const defaultAnchor = document.location.hash.substring(1);
|
||||
|
||||
// lol 💀
|
||||
function setsetRoute(setRoute: (s: string) => void, path: string) {
|
||||
changeAnchor = true;
|
||||
setRoute(path);
|
||||
document.location.hash = path;
|
||||
}
|
||||
|
||||
export default function DX4() {
|
||||
const [route, _setRoute] = useAtom(routeAtom);
|
||||
useEffect(() => {
|
||||
if (
|
||||
document.location.hash &&
|
||||
document.location.hash.substring(1) !== route
|
||||
) {
|
||||
_setRoute(document.location.hash.substring(1));
|
||||
}
|
||||
window.addEventListener("load", () => {
|
||||
if (defaultAnchor == "" || defaultAnchor == "/") {
|
||||
document.location.hash = defaultAnchor;
|
||||
}
|
||||
});
|
||||
}, [route, _setRoute]);
|
||||
window.addEventListener("hashchange", () => {
|
||||
if (document.location.hash == "") {
|
||||
document.location.hash = "/";
|
||||
}
|
||||
if (changeAnchor) {
|
||||
changeAnchor = false;
|
||||
return;
|
||||
}
|
||||
_setRoute(document.location.hash.substring(1));
|
||||
});
|
||||
const page = Object.entries(pages).find(
|
||||
([key]) => firstPathSegment(key) == firstPathSegment(route)
|
||||
);
|
||||
return (
|
||||
(page ? page[1] : false) || <ERROR404 /> || <div>some shit happened</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function ERROR404() {
|
||||
const route = useAtom(routeAtom)[0];
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-screen flex-col gap-10">
|
||||
<div className="text-6xl font-black bg-linear-to-r from-red-400 to-pink-300 bg-clip-text text-transparent">
|
||||
404((((
|
||||
</div>
|
||||
<div>{route}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g clip-path="url(#clip0_2026_10)">
|
||||
<g filter="url(#filter0_d_2026_10)">
|
||||
<mask id="mask0_2026_10" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="89" y="110" width="325" height="281">
|
||||
<path d="M229.595 373.25L321.333 295.083L229.595 214.853V373.25Z" fill="white"/>
|
||||
<path d="M321.333 295.083L229.595 373.25M321.333 295.083L229.595 214.853M321.333 295.083L402.292 214.853M321.333 295.083L402.292 378.833M229.595 373.25V214.853M229.595 373.25H104.393C101.851 373.25 100.461 370.288 102.085 368.333L229.595 214.853M229.595 214.853V122" stroke="white" stroke-width="23" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</mask>
|
||||
<g mask="url(#mask0_2026_10)">
|
||||
<rect width="350" height="287" transform="matrix(1 0 0 -1 76 395)" fill="url(#paint0_linear_2026_10)"/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
<defs>
|
||||
<filter id="filter0_d_2026_10" x="34.365" y="55" width="434.927" height="390.833" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
|
||||
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
|
||||
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
|
||||
<feOffset/>
|
||||
<feGaussianBlur stdDeviation="27.75"/>
|
||||
<feComposite in2="hardAlpha" operator="out"/>
|
||||
<feColorMatrix type="matrix" values="0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.34 0"/>
|
||||
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_2026_10"/>
|
||||
<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow_2026_10" result="shape"/>
|
||||
</filter>
|
||||
<linearGradient id="paint0_linear_2026_10" x1="-73.3091" y1="366.596" x2="487.371" y2="-46.6548" gradientUnits="userSpaceOnUse">
|
||||
<stop stop-color="white"/>
|
||||
<stop offset="0.528846" stop-color="#a19597ff"/>
|
||||
<stop offset="1" stop-color="#6b2c3cff"/>
|
||||
</linearGradient>
|
||||
<clipPath id="clip0_2026_10">
|
||||
<rect width="500" height="500" fill="white"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.9 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
@@ -0,0 +1,31 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
:root {
|
||||
font-family: "Jost","Segoe UI", sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: dark;
|
||||
color: #ffffffde;
|
||||
background-color: #141414;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
/* ensure selectable elements still selectable */
|
||||
.selectable,
|
||||
.selectable::after,
|
||||
.selectable::before,
|
||||
.selectable *,
|
||||
.selectable *::before,
|
||||
.selectable *::after,
|
||||
input {
|
||||
user-select: text;
|
||||
}
|
||||
|
||||
.bg-grain {
|
||||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Cfilter id='noise' x='0' y='0'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.8 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.45'/%3E%3C/svg%3E");
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
||||
@@ -0,0 +1,556 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { useAtom } from "jotai";
|
||||
import type { ssroutetype } from "../types";
|
||||
import { CoolBg, CopyClassLink, Header } from "./DashPage";
|
||||
import {
|
||||
AvailableAdminSymbols,
|
||||
copyDXLink,
|
||||
randomString,
|
||||
secondPathSegment,
|
||||
} from "../stilltrash/trash";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import {
|
||||
DengiButton,
|
||||
DengiEditable,
|
||||
DengiYesOrNoDialog,
|
||||
LoadingSpinner,
|
||||
TextPreloader,
|
||||
} from "../stilltrash/dengi_components";
|
||||
import {
|
||||
AdminCreateReq,
|
||||
AdminRemoveReq,
|
||||
AdminUpdateReq,
|
||||
ClassReq,
|
||||
ClassUpdateNameReq,
|
||||
DELETEClassRequest,
|
||||
} from "../stilltrash/req_mgr";
|
||||
import {
|
||||
BiCheckCircle,
|
||||
BiLink,
|
||||
BiPlus,
|
||||
BiPlusCircle,
|
||||
BiTrash,
|
||||
BiX,
|
||||
} from "react-icons/bi";
|
||||
|
||||
export default function ClassProfilePage({
|
||||
passAtom,
|
||||
routeAtom,
|
||||
setsetRoute,
|
||||
}: {
|
||||
passAtom: any;
|
||||
routeAtom: any;
|
||||
setsetRoute: ssroutetype;
|
||||
}) {
|
||||
const [route, setRoute] = useAtom(routeAtom);
|
||||
const [pass, _setPass] = useAtom(passAtom);
|
||||
const classId = secondPathSegment(route as string);
|
||||
if (classId == "") setRoute("/dash/");
|
||||
return (
|
||||
<>
|
||||
<div className="w-full h-screen flex flex-col items-center justify-center gap-5 overflow-x-hidden z-2">
|
||||
<div className="w-screen h-screen flex flex-col sm:max-w-125 sm:max-h-[90vh] gap-3">
|
||||
<Header {...{ setsetRoute, setRoute }} back />
|
||||
<div className="bg-grain bg-zinc-800/50 p-5 items-center rounded-2xl not-md:w-[90%] flex flex-col gap-3">
|
||||
<ClassProfileEditor
|
||||
{...{ classId }}
|
||||
pass={pass as string}
|
||||
setRoute={(r) => setsetRoute(setRoute, r)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<CoolBg />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ClassProfileEditor({
|
||||
pass,
|
||||
classId,
|
||||
setRoute,
|
||||
}: {
|
||||
pass: string;
|
||||
classId: string;
|
||||
setRoute: (r: string) => void;
|
||||
}) {
|
||||
const [classData, setClassData] = useState<Record<string, string> | false>(
|
||||
false
|
||||
);
|
||||
const [adminsData, setAdminsData] = useState<
|
||||
Record<string, string>[] | false
|
||||
>(false);
|
||||
const [dataI, setDataI] = useState(0);
|
||||
useEffect(() => {
|
||||
ClassReq(pass, classId).then((i) => {
|
||||
if (i[0]) {
|
||||
setClassData(i[1]["class"]);
|
||||
setAdminsData(i[1]["admins"]);
|
||||
}
|
||||
});
|
||||
}, [classId, dataI]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1 className="flex gap-3 text-2xl items-center">
|
||||
управление классом <b>{classId}</b>{" "}
|
||||
{classData ? <b>({classData.userclassname})</b> : <TextPreloader />}
|
||||
</h1>
|
||||
<table className="max-w-80">
|
||||
<tbody className="*:*:min-w-20 *:*:h-10">
|
||||
<tr>
|
||||
<td className="">classId</td>
|
||||
<td className="font-mono text-center select-all selectable">
|
||||
{classId}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td className="">название</td>
|
||||
<td className="w-40">
|
||||
<DengiEditable
|
||||
value={classData ? classData.userclassname : false}
|
||||
onSubmit={async (v, idle) => {
|
||||
idle(true);
|
||||
const r = await ClassUpdateNameReq(
|
||||
pass,
|
||||
classId,
|
||||
v as string
|
||||
);
|
||||
if (r[1] === true) {
|
||||
setClassData((prev) => ({
|
||||
...prev,
|
||||
userclassname: v as string,
|
||||
}));
|
||||
}
|
||||
idle(false);
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div className="w-50 mt-5 flex gap-2 items-center justify-center">
|
||||
<CopyClassLink {...{ classId }} />
|
||||
{classData && (
|
||||
<RemoveClassButton
|
||||
{...{ classId, pass, setRoute, className: classData.userclassname }}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<span className="h-px w-[80%] bg-zinc-700 block my-5 "></span>
|
||||
<span className="text-xl font-bold block">админы</span>
|
||||
<table className="w-full">
|
||||
<thead>
|
||||
<tr className="*:px-2">
|
||||
<th>имя</th>
|
||||
<th>id</th>
|
||||
<th>уров.</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{adminsData &&
|
||||
adminsData.map((i) => (
|
||||
<AdminProfileRow
|
||||
key={i.adminId}
|
||||
{...{
|
||||
adminId: i.adminId,
|
||||
pass: pass as string,
|
||||
adminName: i.adminName,
|
||||
adminLevel: i.adminPrems.toString(),
|
||||
classId,
|
||||
update: () => {
|
||||
setDataI(dataI + 1);
|
||||
},
|
||||
setAdminFrId: (v: string) => {
|
||||
setAdminsData(
|
||||
(prev) =>
|
||||
prev &&
|
||||
prev.map((a: any) =>
|
||||
a.adminId === i.adminId ? { ...a, adminName: v } : a
|
||||
)
|
||||
);
|
||||
},
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
{!adminsData && (
|
||||
<tr>
|
||||
<td>
|
||||
<span className="flex w-full justify-center">
|
||||
<TextPreloader />
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<span className="flex w-full justify-center">
|
||||
<TextPreloader />
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<span className="flex w-full justify-center">
|
||||
<TextPreloader />
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<LoadingSpinner size={20} />
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
{adminsData && (
|
||||
<CreateAdmin
|
||||
{...{
|
||||
update: () => {
|
||||
setDataI(dataI + 1);
|
||||
},
|
||||
classId,
|
||||
pass,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function AdminProfileRow({
|
||||
adminId,
|
||||
pass,
|
||||
adminName,
|
||||
classId,
|
||||
setAdminFrId,
|
||||
adminLevel,
|
||||
update,
|
||||
}: {
|
||||
adminId: string;
|
||||
pass: string;
|
||||
adminName: string;
|
||||
classId: string;
|
||||
setAdminFrId: (v: string) => void;
|
||||
adminLevel: string;
|
||||
update: () => void;
|
||||
}) {
|
||||
return (
|
||||
<tr className="h-12">
|
||||
<td className="px-2">
|
||||
<DengiEditable
|
||||
value={adminName}
|
||||
onSubmit={async (v, i) => {
|
||||
i(true);
|
||||
const r = await AdminUpdateReq(pass, adminId, "name", v as string);
|
||||
if (r[1] === true) {
|
||||
setAdminFrId(v as string);
|
||||
}
|
||||
i(false);
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
<td className="px-2">
|
||||
<DengiEditable value={adminId} password={true} disabled />
|
||||
</td>
|
||||
<td className="text-center">
|
||||
<AdminLevelPicker
|
||||
{...{
|
||||
value: adminLevel,
|
||||
pass,
|
||||
adminId,
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
<td className="inline-flex gap-1 items-center justify-center">
|
||||
<CopyAdminLink {...{ classId, adminId }} />
|
||||
<RemoveAdminButton {...{ adminId, pass, adminName, update }} />
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
|
||||
const AdminLevelPicker = ({
|
||||
adminId,
|
||||
pass,
|
||||
value,
|
||||
}: {
|
||||
adminId: string;
|
||||
pass: string;
|
||||
value: string;
|
||||
}) => {
|
||||
const [val, setVal] = useState(value);
|
||||
const [idle, setIdle] = useState(false);
|
||||
return (
|
||||
<form className="flex items-center justify-center">
|
||||
{!idle ? (
|
||||
<select
|
||||
className="bg-zinc-800 p-1.5 rounded-xl text-center"
|
||||
value={val}
|
||||
onChange={async (e) => {
|
||||
setIdle(true);
|
||||
const v = (e.target as HTMLSelectElement).value;
|
||||
const r = await AdminUpdateReq(pass, adminId, "level", v);
|
||||
if (r[1] === true) {
|
||||
setVal(v);
|
||||
}
|
||||
setIdle(false);
|
||||
}}
|
||||
>
|
||||
<option value="-1">-1</option>
|
||||
<option value="1">1</option>
|
||||
<option value="2">2</option>
|
||||
</select>
|
||||
) : (
|
||||
<LoadingSpinner size={20} />
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
const RemoveAdminButton = ({
|
||||
adminId,
|
||||
pass,
|
||||
adminName,
|
||||
update,
|
||||
}: {
|
||||
adminId: string;
|
||||
pass: string;
|
||||
adminName: string;
|
||||
update: () => void;
|
||||
}) => {
|
||||
const [showDiag, setShowDiag] = useState(false);
|
||||
const [deleting, setDeleting] = useState(false);
|
||||
|
||||
return (
|
||||
<>
|
||||
<DengiYesOrNoDialog
|
||||
show={showDiag}
|
||||
content={{
|
||||
//@ts-ignore
|
||||
message: (
|
||||
<p>
|
||||
вы точно хотите удалить админа <b>{adminName}</b>?
|
||||
</p>
|
||||
),
|
||||
yesBtn: "да",
|
||||
noBtn: "нет",
|
||||
yesIcon: <BiTrash />,
|
||||
noIcon: <BiX size={20} />,
|
||||
bgDissmis: true,
|
||||
yesBtnStyle: "bg-red-500! text-white! md:hover:bg-red-600!",
|
||||
}}
|
||||
onAnswer={async (answ: boolean) => {
|
||||
setShowDiag(false);
|
||||
if (answ) {
|
||||
setDeleting(true);
|
||||
const r = await AdminRemoveReq(pass, adminId);
|
||||
if (r[1] === true) {
|
||||
update();
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<DengiButton
|
||||
onClick={() => {
|
||||
if (deleting) return;
|
||||
setShowDiag(true);
|
||||
}}
|
||||
>
|
||||
{deleting ? <LoadingSpinner size={20} /> : <BiTrash />}
|
||||
</DengiButton>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const RemoveClassButton = ({
|
||||
pass,
|
||||
classId,
|
||||
setRoute,
|
||||
className,
|
||||
}: {
|
||||
pass: string;
|
||||
classId: string;
|
||||
setRoute: (r: string) => void;
|
||||
className: string;
|
||||
}) => {
|
||||
const [showDiag, setShowDiag] = useState(false);
|
||||
const [deleting, setDeleting] = useState(false);
|
||||
|
||||
return (
|
||||
<>
|
||||
<DengiYesOrNoDialog
|
||||
show={showDiag}
|
||||
content={{
|
||||
//@ts-ignore
|
||||
message: (
|
||||
<p>
|
||||
вы точно хотите удалить класс{" "}
|
||||
<b>
|
||||
{classId} ({className})
|
||||
</b>
|
||||
?
|
||||
</p>
|
||||
),
|
||||
yesBtn: "да",
|
||||
noBtn: "нет",
|
||||
yesIcon: <BiTrash />,
|
||||
noIcon: <BiX size={20} />,
|
||||
bgDissmis: true,
|
||||
yesBtnStyle: "bg-red-500! text-white! md:hover:bg-red-600!",
|
||||
}}
|
||||
onAnswer={async (answ: boolean) => {
|
||||
setShowDiag(false);
|
||||
if (answ) {
|
||||
setDeleting(true);
|
||||
const r = await DELETEClassRequest(pass, classId);
|
||||
if (r[1] === true) {
|
||||
setRoute("/dash/class");
|
||||
}
|
||||
setDeleting(false);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<DengiButton
|
||||
onClick={() => {
|
||||
if (deleting) return;
|
||||
setShowDiag(true);
|
||||
}}
|
||||
>
|
||||
{deleting ? <LoadingSpinner size={20} /> : <BiTrash />}
|
||||
</DengiButton>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const CopyAdminLink = ({
|
||||
classId,
|
||||
adminId,
|
||||
}: {
|
||||
classId: string;
|
||||
adminId: string;
|
||||
}) => {
|
||||
const [linkCopied, setLinkCopied] = useState(false);
|
||||
const copy = () => {
|
||||
copyDXLink(classId, adminId).then((a) => {
|
||||
if (a) {
|
||||
setLinkCopied(true);
|
||||
setTimeout(() => {
|
||||
setLinkCopied(false);
|
||||
}, 2000);
|
||||
}
|
||||
});
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<DengiButton onClick={() => copy()}>
|
||||
{linkCopied ? <BiCheckCircle /> : <BiLink />}
|
||||
</DengiButton>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
function CreateAdmin({
|
||||
pass,
|
||||
classId,
|
||||
update,
|
||||
}: {
|
||||
pass: string;
|
||||
update: () => void;
|
||||
classId: string;
|
||||
}) {
|
||||
const [creating, setCreating] = useState(false);
|
||||
const [adminId, setAdminId] = useState("");
|
||||
const [adminName, setAdminName] = useState("");
|
||||
const [levelVal, setLevelVal] = useState("1");
|
||||
const [locked, setLocked] = useState(false);
|
||||
const form = useRef(null);
|
||||
return (
|
||||
<>
|
||||
<div className="flex w-full gap-1">
|
||||
<span className="w-full" />
|
||||
{creating && (
|
||||
<form
|
||||
className="flex gap-2 max-w-100"
|
||||
ref={form}
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
if (locked || adminId.length < 5) return;
|
||||
setLocked(true);
|
||||
const c = await AdminCreateReq(
|
||||
pass,
|
||||
classId,
|
||||
adminId,
|
||||
adminName,
|
||||
levelVal
|
||||
);
|
||||
if (c[1] == true) {
|
||||
update();
|
||||
setCreating(false);
|
||||
}
|
||||
setLocked(false);
|
||||
}}
|
||||
>
|
||||
<input
|
||||
className="bg-zinc-900 rounded-2xl border border-zinc-500/50 px-2 max-w-35"
|
||||
placeholder="имя"
|
||||
required
|
||||
value={adminName}
|
||||
disabled={locked}
|
||||
maxLength={50}
|
||||
onInput={(e) =>
|
||||
setAdminName((e.target as HTMLInputElement).value.trimStart())
|
||||
}
|
||||
/>
|
||||
<input
|
||||
className="bg-zinc-900 rounded-2xl border border-zinc-500/50 px-2 max-w-35"
|
||||
placeholder="adminId"
|
||||
value={adminId}
|
||||
required
|
||||
disabled={locked}
|
||||
maxLength={20}
|
||||
minLength={5}
|
||||
min={5}
|
||||
onInput={(e) => {
|
||||
let val = (e.target as HTMLInputElement).value;
|
||||
let nval = "";
|
||||
val.split("").forEach((i) => {
|
||||
if (AvailableAdminSymbols.includes(i)) {
|
||||
nval = nval + i;
|
||||
}
|
||||
});
|
||||
(e.target as HTMLInputElement).value = nval;
|
||||
setAdminId(nval);
|
||||
}}
|
||||
/>
|
||||
<select
|
||||
className="bg-zinc-800 p-1.5 rounded-xl text-center"
|
||||
value={levelVal}
|
||||
required
|
||||
onChange={async (e) => {
|
||||
const v = (e.target as HTMLSelectElement).value;
|
||||
setLevelVal(v);
|
||||
}}
|
||||
>
|
||||
<option value="-1">-1</option>
|
||||
<option value="1">1</option>
|
||||
<option value="2">2</option>
|
||||
</select>
|
||||
<button>
|
||||
<DengiButton>
|
||||
{locked ? <LoadingSpinner size={20} /> : <BiPlus />}
|
||||
</DengiButton>
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
<DengiButton
|
||||
disabled={locked}
|
||||
onClick={() => {
|
||||
setCreating(!creating);
|
||||
setAdminName("");
|
||||
setAdminId(randomString(8, AvailableAdminSymbols));
|
||||
}}
|
||||
>
|
||||
<span className={`${creating ? "rotate-45" : ""} transition`}>
|
||||
<BiPlusCircle />
|
||||
</span>
|
||||
</DengiButton>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,548 @@
|
||||
import { useAtom } from "jotai";
|
||||
import {
|
||||
BiCheckCircle,
|
||||
BiEdit,
|
||||
BiExit,
|
||||
BiLeftArrow,
|
||||
BiLink,
|
||||
BiPlus,
|
||||
BiPlusCircle,
|
||||
} from "react-icons/bi";
|
||||
import Logo from "../assets/logo.svg";
|
||||
import type { ssroutetype } from "../types";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import {
|
||||
AvailableSymbols,
|
||||
copyDXLink,
|
||||
randomString,
|
||||
secondPathSegment,
|
||||
} from "../stilltrash/trash";
|
||||
import { API_BASE_URL, CLIENT_FRONTEND_URL } from "../App";
|
||||
import {
|
||||
DengiButton,
|
||||
DengiEditable,
|
||||
Link,
|
||||
LoadingSpinner,
|
||||
Switch,
|
||||
TextPreloader,
|
||||
} from "../stilltrash/dengi_components";
|
||||
import {
|
||||
ClassesReq,
|
||||
CreateClassReq,
|
||||
ServerBlockReq,
|
||||
ServerMsgBlockReq,
|
||||
ServerReq,
|
||||
} from "../stilltrash/req_mgr";
|
||||
|
||||
export default function DashPage({
|
||||
passAtom,
|
||||
routeAtom,
|
||||
setsetRoute,
|
||||
}: {
|
||||
passAtom: any;
|
||||
routeAtom: any;
|
||||
setsetRoute: ssroutetype;
|
||||
}) {
|
||||
const [route, setRoute] = useAtom(routeAtom);
|
||||
const [pass, _setPass] = useAtom(passAtom);
|
||||
|
||||
const tabs: Record<string, string> = {
|
||||
class: "классы",
|
||||
admin: "админы",
|
||||
server: "сервер",
|
||||
};
|
||||
|
||||
let tab = secondPathSegment(route as string);
|
||||
if (!tab || tab == "") tab = Object.keys(tabs)[0];
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="w-full h-screen flex flex-col items-center justify-center gap-5 overflow-x-hidden z-2">
|
||||
<div className="w-screen h-screen flex items-center flex-col sm:max-w-125 sm:max-h-[90vh] gap-3">
|
||||
<Header {...{ setsetRoute, setRoute }} />
|
||||
<div className="bg-zinc-800/50 items-center justify-center rounded-2xl flex gap-2 w-full">
|
||||
{Object.keys(tabs).map((i, idx) => (
|
||||
<span
|
||||
className={
|
||||
"p-2 px-3 select-none hover:bg-zinc-200/50 rounded-2xl my-2 cursor-pointer border transition-colors " +
|
||||
(tab == i ? "border-zinc-100/50" : "border-transparent")
|
||||
}
|
||||
key={idx}
|
||||
onClick={() => setsetRoute(setRoute, "/dash/" + i)}
|
||||
>
|
||||
{tabs[i]}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
{/* {tab} */}
|
||||
<div className="bg-grain w-full bg-zinc-800/50 p-5 rounded-2xl not-md:w-[90%] flex flex-col gap-3">
|
||||
{(() => {
|
||||
switch (tab) {
|
||||
case "class":
|
||||
return (
|
||||
<ClassesMainEditor
|
||||
pass={pass as string}
|
||||
setRoute={(p: string) => setsetRoute(setRoute, p)}
|
||||
/>
|
||||
);
|
||||
case "admin":
|
||||
return <AdminsMainEditor pass={pass as string} />;
|
||||
case "server":
|
||||
return <ServerEditor pass={pass as string} />;
|
||||
}
|
||||
})()}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<CoolBg />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ClassesMainEditor({
|
||||
pass,
|
||||
setRoute,
|
||||
}: {
|
||||
pass: string;
|
||||
setRoute: (s: string) => void;
|
||||
}) {
|
||||
const [classesData, setClassesData] = useState<
|
||||
Record<string, string>[] | false
|
||||
>(false);
|
||||
const [updateId, setUpdateId] = useState(0);
|
||||
useEffect(() => {
|
||||
ClassesReq(pass).then((i) => {
|
||||
if (i[1]["ok"] == "da") {
|
||||
setClassesData(i[1]["data"]);
|
||||
}
|
||||
});
|
||||
}, [updateId]);
|
||||
return (
|
||||
<div className="flex flex-col w-full">
|
||||
{classesData ? (
|
||||
<>
|
||||
{classesData.map((i, idx) => (
|
||||
<div
|
||||
className="flex w-full items-center hover:bg-zinc-300/30 transition-colors rounded-xl py-3 px-2"
|
||||
key={idx}
|
||||
>
|
||||
<span className="w-full block text-center">{i.classid}</span>
|
||||
<span className="w-full block text-center">
|
||||
{i.userclassname}
|
||||
</span>
|
||||
<span className="flex gap-2">
|
||||
<CopyClassLink classId={i.classid} compact />
|
||||
<DengiButton onClick={() => setRoute("/class/" + i.classid)}>
|
||||
<BiEdit />
|
||||
</DengiButton>
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
<div className="mt-5">
|
||||
<CreateClass pass={pass} update={() => setUpdateId(updateId + 1)} />
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<LoadingSpinner size={20} />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export const CopyClassLink = ({
|
||||
classId,
|
||||
compact = false,
|
||||
}: {
|
||||
classId: string;
|
||||
compact?: boolean;
|
||||
}) => {
|
||||
const [linkCopied, setLinkCopied] = useState(false);
|
||||
|
||||
return (
|
||||
<DengiButton
|
||||
onClick={() => {
|
||||
copyDXLink(classId).then((a) => {
|
||||
if (a) {
|
||||
setLinkCopied(true);
|
||||
setTimeout(() => {
|
||||
setLinkCopied(false);
|
||||
}, 2000);
|
||||
}
|
||||
});
|
||||
}}
|
||||
>
|
||||
{compact ? (
|
||||
<>{linkCopied ? <BiCheckCircle /> : <BiLink />}</>
|
||||
) : (
|
||||
<>
|
||||
<BiLink />
|
||||
<span>{linkCopied ? "скопировано" : "коп ссылку"}</span>
|
||||
</>
|
||||
)}
|
||||
</DengiButton>
|
||||
);
|
||||
};
|
||||
function AdminsMainEditor({ pass }: { pass: string }) {
|
||||
return (
|
||||
<div className="block">
|
||||
<img src="https://od.lk/s/MTBfMzQ0MTQ0Njg5Xw/admin1.webp" alt="" className="w-30 h-auto" draggable={false} onContextMenu={e=>e.preventDefault()} />
|
||||
{/* <img src="https://od.lk/s/MTBfMzQ0MTQ0NjkyXw/admin2.webp" alt="" className="w-30 h-auto" draggable={false} onContextMenu={e=>e.preventDefault()}/> */}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
function ServerEditor({ pass }: { pass: string }) {
|
||||
const [serverData, setServerData] = useState<Record<string, string> | false>(
|
||||
false
|
||||
);
|
||||
const [idle, setIdle] = useState(false);
|
||||
const [showL, setShowL] = useState(false);
|
||||
const [blockChecked, setBlockChecked] = useState(false);
|
||||
let update = 0;
|
||||
useEffect(() => {
|
||||
ServerReq(pass).then(async (i) => {
|
||||
if (i[0]) {
|
||||
setServerData(i[1]);
|
||||
setBlockChecked(!i[1]["STATUS"] as boolean);
|
||||
}
|
||||
});
|
||||
}, [update]);
|
||||
return (
|
||||
<>
|
||||
<h1 className="text-2xl py-5 block">настройки api сервера</h1>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th className="w-35">admin_api_path</th>
|
||||
<td>
|
||||
<Link className="underline" target="_blank">
|
||||
{API_BASE_URL}
|
||||
</Link>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th className="w-35">client_api_path</th>
|
||||
<td>
|
||||
{serverData ? (
|
||||
<Link className="underline" target="_blank">
|
||||
{serverData["CLIENT_API"]}
|
||||
</Link>
|
||||
) : (
|
||||
<TextPreloader />
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th className="w-35">client_frontend</th>
|
||||
<td>
|
||||
<Link className="underline" target="_blank">
|
||||
{CLIENT_FRONTEND_URL}
|
||||
</Link>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<a
|
||||
href={API_BASE_URL + "?phpliteadmin"}
|
||||
target="_blank"
|
||||
className="flex p-2 w-50 items-center justify-center rounded hover:bg-zinc-700/50 transition-colors border border-zinc-500"
|
||||
>
|
||||
<img
|
||||
src="https://bitbucket.org/phpliteadmin/public/raw/3fa9fedad19dc407a1786f97ba2b18a3c7b803bc/icon/phpLiteAdmin_small.png"
|
||||
alt=""
|
||||
width={32}
|
||||
className="invert"
|
||||
/>
|
||||
open phpliteadmin
|
||||
</a>
|
||||
|
||||
<div className="flex flex-col gap-3 justify-center">
|
||||
<h4>блокировка api</h4>
|
||||
<div className="flex gap-2 items-center">
|
||||
{serverData && (
|
||||
<>
|
||||
<DengiEditable
|
||||
value={serverData ? serverData["BLOCKMSG"] : false}
|
||||
disabled={idle}
|
||||
placeholder="error block message"
|
||||
onSubmit={async (v, s) => {
|
||||
console.log(v);
|
||||
s(true);
|
||||
setIdle(true);
|
||||
const r = await ServerMsgBlockReq(pass, v as string);
|
||||
if (r[1] !== true) {
|
||||
alert(r[1]);
|
||||
} else {
|
||||
setServerData((prev) => ({
|
||||
...prev,
|
||||
BLOCKMSG: v as string,
|
||||
}));
|
||||
}
|
||||
s(false);
|
||||
setIdle(false);
|
||||
}}
|
||||
/>
|
||||
<Switch
|
||||
disabled={idle}
|
||||
checked={blockChecked}
|
||||
onChange={async (e) => {
|
||||
setBlockChecked(e);
|
||||
setIdle(true);
|
||||
setShowL(true);
|
||||
const r = await ServerBlockReq(pass, e);
|
||||
if (r[1] !== true) {
|
||||
alert(r[1]);
|
||||
setBlockChecked(!e);
|
||||
}
|
||||
setIdle(false);
|
||||
setShowL(false);
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
{(showL || !serverData) && <LoadingSpinner size={20} />}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function CreateClass({ pass, update }: { pass: string; update: () => void }) {
|
||||
const [creating, setCreating] = useState(false);
|
||||
const [classId, setClassId] = useState("");
|
||||
const [className, setClassName] = useState("");
|
||||
const [locked, setLocked] = useState(false);
|
||||
const form = useRef(null);
|
||||
return (
|
||||
<>
|
||||
<div className="flex w-full gap-1">
|
||||
<span className="w-full" />
|
||||
{creating && (
|
||||
<form
|
||||
className="flex gap-2 max-w-100"
|
||||
ref={form}
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
if (locked || classId.length < 5) return;
|
||||
setLocked(true);
|
||||
const c = await CreateClassReq(pass, classId, className);
|
||||
if (c[1] == true) {
|
||||
update();
|
||||
setCreating(false);
|
||||
}
|
||||
setLocked(false);
|
||||
}}
|
||||
>
|
||||
<input
|
||||
className="bg-zinc-900 rounded-2xl border border-zinc-500/50 px-2 max-w-35"
|
||||
placeholder="название"
|
||||
required
|
||||
value={className}
|
||||
disabled={locked}
|
||||
maxLength={50}
|
||||
onInput={(e) =>
|
||||
setClassName((e.target as HTMLInputElement).value.trimStart())
|
||||
}
|
||||
/>
|
||||
<input
|
||||
className="bg-zinc-900 rounded-2xl border border-zinc-500/50 px-2 max-w-35"
|
||||
placeholder="classId"
|
||||
value={classId}
|
||||
required
|
||||
disabled={locked}
|
||||
maxLength={10}
|
||||
minLength={5}
|
||||
min={5}
|
||||
onInput={(e) => {
|
||||
let val = (e.target as HTMLInputElement).value.toUpperCase();
|
||||
let nval = "";
|
||||
val.split("").forEach((i) => {
|
||||
if (AvailableSymbols.includes(i)) {
|
||||
nval = nval + i;
|
||||
}
|
||||
});
|
||||
(e.target as HTMLInputElement).value = nval;
|
||||
setClassId(nval);
|
||||
}}
|
||||
/>
|
||||
<button>
|
||||
<DengiButton>
|
||||
{locked ? <LoadingSpinner size={20} /> : <BiPlus />}
|
||||
</DengiButton>
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
<DengiButton
|
||||
disabled={locked}
|
||||
onClick={() => {
|
||||
setCreating(!creating);
|
||||
setClassName("");
|
||||
setClassId(randomString(8, AvailableSymbols).toUpperCase());
|
||||
}}
|
||||
>
|
||||
<span className={`${creating ? "rotate-45" : ""} transition`}>
|
||||
<BiPlusCircle />
|
||||
</span>
|
||||
</DengiButton>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// export function AdminProfileEditor({
|
||||
// adminFrId,
|
||||
// setAdminFrId,
|
||||
// adminId,
|
||||
// classId,
|
||||
// pickmeMode = false,
|
||||
// }) {
|
||||
// return (
|
||||
// <div className=" bg-grain bg-zinc-800/50 p-5 rounded-2xl not-md:w-[90%]">
|
||||
// <table className="">
|
||||
// <tbody className="*:*:w-10 *:*:h-10">
|
||||
// <tr>
|
||||
// <td className="">имя</td>
|
||||
// <td className="w-50!">
|
||||
// <DengiEditable
|
||||
// value={adminFrId}
|
||||
// pink={pickmeMode}
|
||||
// onSubmit={async (e) => {
|
||||
// e.setIdle(true);
|
||||
// const r = await AdminUpdateRequest(API_BASE_URL, adminId, {
|
||||
// action: "change_name",
|
||||
// value: e.value.trim(),
|
||||
// });
|
||||
// if (r[1] == true) setAdminFrId(e.value);
|
||||
// e.setIdle(false);
|
||||
// }}
|
||||
// />
|
||||
// </td>
|
||||
// </tr>
|
||||
// <tr>
|
||||
// <td>id</td>
|
||||
// <td>
|
||||
// <DengiEditable
|
||||
// value={adminId}
|
||||
// password={true}
|
||||
// pink={pickmeMode}
|
||||
// disabled
|
||||
// />
|
||||
// </td>
|
||||
// </tr>
|
||||
// <tr>
|
||||
// <td>class</td>
|
||||
// <td className="font-mono text-center select-all selectable">
|
||||
// {classId ? classId : <TextPreloader />}
|
||||
// </td>
|
||||
// </tr>
|
||||
// </tbody>
|
||||
// </table>
|
||||
// <CopyLink {...{ adminId, classId }} />
|
||||
// </div>
|
||||
// );
|
||||
// }
|
||||
|
||||
// const CopyLink = ({ classId, adminId }) => {
|
||||
// const [showDiag, setShowDiag] = useState(false);
|
||||
// const [seenDiag, setSeenDiag] = useState(false);
|
||||
// const [linkCopied, setLinkCopied] = useState(false);
|
||||
// const copy = () => {
|
||||
// copyDXLink(classId, adminId).then((a) => {
|
||||
// if (a) {
|
||||
// setLinkCopied(true);
|
||||
// setTimeout(() => {
|
||||
// setLinkCopied(false);
|
||||
// }, 2000);
|
||||
// }
|
||||
// });
|
||||
// };
|
||||
// return (
|
||||
// <div className="flex justify-end mt-2">
|
||||
// <DengiYesOrNoDialog
|
||||
// show={showDiag}
|
||||
// content={{
|
||||
// message: (
|
||||
// <p>
|
||||
// <b>любой</b>, кто получит ссылку,{" "}
|
||||
// <b>будет иметь доступ к админке</b>.<br /> вы желаете продолжить?
|
||||
// </p>
|
||||
// ),
|
||||
// yesBtn: "да",
|
||||
// noBtn: "нет",
|
||||
// yesIcon: <BiCopy />,
|
||||
// noIcon: <BiX size={20} />,
|
||||
// bgDissmis: true,
|
||||
// yesBtnStyle: "bg-orange-500! text-white! md:hover:bg-orange-600!",
|
||||
// }}
|
||||
// onAnswer={(answ) => {
|
||||
// if (answ) {
|
||||
// setSeenDiag(true);
|
||||
// copy();
|
||||
// }
|
||||
// setShowDiag(false);
|
||||
// }}
|
||||
// />
|
||||
// <DengiButton onClick={() => (seenDiag ? copy() : setShowDiag(true))}>
|
||||
// <BiLink /> <BiError color={"orange"} />
|
||||
// <span>{linkCopied ? "скопировано" : "коп ссылку на админку"}</span>
|
||||
// </DengiButton>
|
||||
// </div>
|
||||
// );
|
||||
// };
|
||||
|
||||
export const CoolBg = ({}) => {
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className={`fixed top-0 left-0 w-full h-full -z-5 overflow-hidden bg-linear-to-tl to-black to-50% bg-fixed
|
||||
from-red-600/20`}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const Header = ({
|
||||
setsetRoute,
|
||||
setRoute,
|
||||
back = false,
|
||||
}: {
|
||||
setsetRoute: ssroutetype;
|
||||
setRoute: any;
|
||||
back?: boolean;
|
||||
}) => {
|
||||
return (
|
||||
<div className={"flex items-center w-full justify-between px-5"}>
|
||||
<span className="flex gap-2 items-center">
|
||||
{back && (
|
||||
<BiLeftArrow
|
||||
size={35}
|
||||
onClick={() => {
|
||||
setsetRoute(setRoute, "/dash/");
|
||||
}}
|
||||
className={
|
||||
"rounded-full " +
|
||||
"lg:hover:bg-white lg:hover:fill-black" +
|
||||
" lg:hover:scale-105 transition cursor-pointer"
|
||||
}
|
||||
/>
|
||||
)}
|
||||
<img src={Logo} alt="logo" width={100} draggable={false} />
|
||||
</span>
|
||||
<BiExit
|
||||
size={35}
|
||||
onClick={() => {
|
||||
setsetRoute(setRoute, "/");
|
||||
}}
|
||||
onContextMenu={(e) => {
|
||||
e.preventDefault();
|
||||
}}
|
||||
className={
|
||||
"rounded-full " +
|
||||
"lg:hover:bg-white lg:hover:fill-black" +
|
||||
" lg:hover:scale-105 transition cursor-pointer"
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,113 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { useRef, useState } from "react";
|
||||
import Logo from "../assets/logo.svg";
|
||||
|
||||
import { BiHide, BiShow } from "react-icons/bi";
|
||||
|
||||
import { LoginReq } from "../stilltrash/req_mgr";
|
||||
import { useAtom } from "jotai";
|
||||
import type { ssroutetype } from "../types";
|
||||
export default function LoginPage({
|
||||
passAtom,
|
||||
routeAtom,
|
||||
setsetRoute,
|
||||
}: {
|
||||
passAtom: any;
|
||||
routeAtom: any;
|
||||
setsetRoute: ssroutetype;
|
||||
}) {
|
||||
const [show, setShow] = useState(false);
|
||||
const [atomPass, setAtomPass] = useAtom(passAtom);
|
||||
const [_route, setRoute] = useAtom(routeAtom);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [pass, setPass] = useState("");
|
||||
return (
|
||||
<div className="bg-linear-to-br from-red-500 to-zinc-800 w-screen min-h-screen flex items-center justify-center">
|
||||
<div className="flex flex-col rounded-2xl w-[90vw] items-center justify-center py-3 max-w-150 focus-within:border-white/10 border border-transparent transition-colors relative bg-zinc-900/30 text-zinc-100">
|
||||
{atomPass != "" && (
|
||||
<div className="flex gap-3">
|
||||
<a
|
||||
href="#/dash"
|
||||
className="bg-linear-to-r from-neutral-900 to-zinc-900 p-2 rounded-xl not-disabled:cursor-pointer transition-colors duration-200 hover:from-white hover:to-zinc-400 not-disabled:hover:text-black"
|
||||
>
|
||||
go to dash
|
||||
</a>
|
||||
<button
|
||||
onClick={() => setAtomPass("")}
|
||||
className="bg-linear-to-l from-neutral-900 to-zinc-900 p-2 rounded-xl not-disabled:cursor-pointer transition-colors duration-200 hover:from-white hover:to-zinc-400 not-disabled:hover:text-black"
|
||||
>
|
||||
logoff
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<img src={Logo} alt="logo dengi" width={200} />
|
||||
<h1 className="text-zinc-200">dashboard</h1>
|
||||
<h2 className="text-3xl font-light">вход</h2>
|
||||
<form
|
||||
action="#"
|
||||
className="mt-2 flex flex-col gap-3 *:outline-none *:border *:border-transparent *:focus:border-white"
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
const r = await LoginReq(pass);
|
||||
if (r[1]) {
|
||||
setAtomPass(pass);
|
||||
setsetRoute(setRoute, "/dash");
|
||||
}
|
||||
setLoading(false);
|
||||
}}
|
||||
>
|
||||
<span className="flex items-center">
|
||||
<input
|
||||
type={show ? "text" : "password"}
|
||||
autoComplete="off"
|
||||
className="bg-zinc-800/50 p-2 rounded-l-2xl w-full min-w-51.5"
|
||||
placeholder="password"
|
||||
minLength={3}
|
||||
maxLength={20}
|
||||
required
|
||||
value={pass}
|
||||
onInput={(e) => setPass((e.target as HTMLInputElement).value)}
|
||||
disabled={loading}
|
||||
/>
|
||||
<span
|
||||
className={"p-2 rounded-r-2xl border-l border-l-zinc-500 transition-colors" + (show ? " bg-white" : " bg-zinc-800/50")}
|
||||
onClick={() => {
|
||||
setShow(!show);
|
||||
}}
|
||||
>
|
||||
{!show ? (
|
||||
<BiShow color="#fff" size={23} />
|
||||
) : (
|
||||
<BiHide color="#000" size={23} />
|
||||
)}
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<CoolLoginButton disabled={loading} />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function CoolLoginButton({ disabled }: { disabled: boolean }) {
|
||||
const logbuttonRef = useRef(null);
|
||||
|
||||
return (
|
||||
<button
|
||||
ref={logbuttonRef}
|
||||
{...{ disabled }}
|
||||
onMouseMove={(e) => {
|
||||
const rect = (e.target as HTMLElement).getBoundingClientRect();
|
||||
(e.target as HTMLElement).style.setProperty(
|
||||
"--tw-gradient-via-position",
|
||||
`${((e.clientX - rect.left) / rect.width) * 100}%`
|
||||
);
|
||||
}}
|
||||
className="bg-linear-to-r from-neutral-900 to-zinc-900 p-2 rounded-xl not-disabled:cursor-pointer transition-colors duration-200 not-disabled:hover:via-white via-30% not-disabled:hover:text-black disabled:via-white disabled:via-0%! disabled:animate-pulse"
|
||||
>
|
||||
войти
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
import { useEffect, useState, type AnchorHTMLAttributes } from "react";
|
||||
import { BiCheck, BiHide, BiShow, BiX } from "react-icons/bi";
|
||||
|
||||
export function Link(props: AnchorHTMLAttributes<HTMLAnchorElement>) {
|
||||
let link = props.href;
|
||||
if (!link) {
|
||||
link = props.children as string;
|
||||
}
|
||||
return (
|
||||
<a {...props} href={link}>
|
||||
{link}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
export function Switch({
|
||||
checked,
|
||||
defaultChecked = false,
|
||||
onChange,
|
||||
disabled = false,
|
||||
ariaLabel,
|
||||
className = "",
|
||||
size = "md", // "sm" | "md" | "lg"
|
||||
}: {
|
||||
checked?: boolean;
|
||||
defaultChecked?: boolean;
|
||||
onChange?: (newState: boolean) => void;
|
||||
disabled?: boolean;
|
||||
ariaLabel?: string;
|
||||
className?: string;
|
||||
size?: "sm" | "md" | "lg";
|
||||
}) {
|
||||
const isControlled = checked !== undefined;
|
||||
const [internalChecked, setInternalChecked] = useState(defaultChecked);
|
||||
const current = isControlled ? checked : internalChecked;
|
||||
|
||||
useEffect(() => {
|
||||
if (!isControlled) return;
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
setInternalChecked(checked);
|
||||
}, [checked, isControlled]);
|
||||
|
||||
const sizes = {
|
||||
sm: { track: "w-9 h-5", thumb: "w-3 h-3", translate: "translate-x-4" },
|
||||
md: { track: "w-11 h-6", thumb: "w-4 h-4", translate: "translate-x-5" },
|
||||
lg: { track: "w-14 h-8", thumb: "w-6 h-6", translate: "translate-x-6" },
|
||||
};
|
||||
const s = sizes[size] || sizes.md;
|
||||
|
||||
const toggle = (next?: boolean) => {
|
||||
if (disabled) return;
|
||||
const newState = typeof next === "boolean" ? next : !current;
|
||||
if (!isControlled) setInternalChecked(newState);
|
||||
onChange?.(newState);
|
||||
};
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
role="switch"
|
||||
aria-checked={current}
|
||||
aria-label={ariaLabel}
|
||||
disabled={disabled}
|
||||
tabIndex={disabled ? -1 : 0}
|
||||
onClick={() => toggle()}
|
||||
className={[
|
||||
"inline-flex items-center p-0 focus:outline-none",
|
||||
// focus-visible: shows ring only when focused by keyboard (better UX)
|
||||
"focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-offset-0.5 focus-visible:ring-offset-transparent",
|
||||
disabled ? "opacity-60" : "cursor-pointer",
|
||||
current ? "bg-zinc-500" : "bg-gray-300/10",
|
||||
"rounded-full transition-colors duration-150",
|
||||
s.track,
|
||||
className,
|
||||
].join(" ")}
|
||||
>
|
||||
<span
|
||||
className={[
|
||||
"relative block rounded-full bg-white shadow transform transition-transform ease-out duration-150",
|
||||
s.thumb,
|
||||
current ? s.translate : "",
|
||||
size === "sm" ? "m-1" : "m-1",
|
||||
].join(" ")}
|
||||
/>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
export function LoadingSpinner({ size }: { size: number }) {
|
||||
return (
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
className="animate-spin ease-out text-zinc-600 fill-white"
|
||||
viewBox="0 0 100 101"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width={size}
|
||||
height={size}
|
||||
>
|
||||
<path
|
||||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||
fill="currentFill"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
export function DengiEditable({
|
||||
value,
|
||||
password = false,
|
||||
disWHidden = true,
|
||||
disabled = false,
|
||||
showLoading = true,
|
||||
minLenght = 1,
|
||||
placeholder,
|
||||
onSubmit = () => {},
|
||||
onInput = () => {},
|
||||
}: {
|
||||
value?: string | false;
|
||||
password?: boolean;
|
||||
disWHidden?: boolean;
|
||||
disabled?: boolean;
|
||||
placeholder?: string;
|
||||
showLoading?: boolean;
|
||||
minLenght?: number;
|
||||
onSubmit?: (
|
||||
value: string | false | undefined,
|
||||
setIdle: (v: boolean) => void
|
||||
) => void;
|
||||
onInput?: (
|
||||
value: string | false | undefined,
|
||||
setIdle: (v: boolean) => void
|
||||
) => void;
|
||||
}) {
|
||||
const [val, setVal] = useState(value);
|
||||
const [hid, setHid] = useState(true);
|
||||
const [idle, setIdle] = useState(false);
|
||||
useEffect(() => {
|
||||
setVal(value);
|
||||
}, [value]);
|
||||
return (
|
||||
<form
|
||||
action="#"
|
||||
className="flex rounded-xl overflow-hidden max-w-50 h-8 relative"
|
||||
onSubmit={(e) => {
|
||||
if (idle) return;
|
||||
e.preventDefault();
|
||||
onSubmit(val, setIdle);
|
||||
}}
|
||||
>
|
||||
{value !== false || !showLoading ? (
|
||||
<input
|
||||
type={hid && password ? "password" : "text"}
|
||||
value={val as any}
|
||||
placeholder={placeholder}
|
||||
minLength={minLenght}
|
||||
disabled={(disWHidden && password && hid) || disabled || idle}
|
||||
className={`bg-zinc-800 ${
|
||||
val === value && !password ? "rounded-r-xl" : ""
|
||||
} pl-2 rounded-l-xl w-full py-1 transition`}
|
||||
onInput={(e) => {
|
||||
const v = (e.target as HTMLInputElement).value;
|
||||
setVal(v);
|
||||
onInput(v, setIdle);
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<span
|
||||
className={`w-full bg-zinc-800 py-1 flex items-center justify-center`}
|
||||
>
|
||||
<LoadingSpinner size={25} />
|
||||
</span>
|
||||
)}
|
||||
|
||||
{password && (
|
||||
<button
|
||||
className={`bg-zinc-600 hover:bg-zinc-700 cursor-pointer transition-colors ${
|
||||
val === value ? "rounded-r-xl" : ""
|
||||
} p-1 text-2xl `}
|
||||
onContextMenu={(e) => {
|
||||
e.preventDefault();
|
||||
if ((disWHidden && password && hid) || disabled || idle) return;
|
||||
setVal(value);
|
||||
}}
|
||||
onClick={() => {
|
||||
setHid(!hid);
|
||||
}}
|
||||
>
|
||||
{hid ? <BiShow /> : <BiHide />}
|
||||
</button>
|
||||
)}
|
||||
|
||||
{val !== value && (
|
||||
<button
|
||||
disabled={idle}
|
||||
className={`bg-zinc-600 disabled:bg-zinc-900 hover:bg-zinc-700
|
||||
p-1 text-2xl rounded-r-xl transition-colors not-disabled:cursor-pointer`}
|
||||
onContextMenu={(e) => {
|
||||
e.preventDefault();
|
||||
setVal(value);
|
||||
}}
|
||||
>
|
||||
{idle ? <LoadingSpinner size={24} /> : <BiCheck />}
|
||||
</button>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
import trashcss from "./trash.module.css";
|
||||
export function TextPreloader({ width = "5rem" }) {
|
||||
return (
|
||||
<span
|
||||
className={"h-4 block bg-zinc-900 overflow-hidden rounded-full w-(--w)"}
|
||||
style={{ "--w": width } as Record<string, string>}
|
||||
>
|
||||
<span
|
||||
className={
|
||||
"block h-10 -translate-y-3 w-3 bg-zinc-300 relative blur-[7px] " +
|
||||
trashcss.anim_preloader
|
||||
}
|
||||
></span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
export function DengiButton({
|
||||
onClick,
|
||||
children,
|
||||
disabled = false,
|
||||
className = "",
|
||||
}: {
|
||||
onClick?: () => void;
|
||||
children?: any;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
}) {
|
||||
return (
|
||||
<span
|
||||
role="button"
|
||||
className={
|
||||
"flex bg-black items-center justify-center border p-1 gap-2 px-2 border-white " +
|
||||
(disabled
|
||||
? "cursor-not-allowed text-zinc-700 border-zinc-900 md:hover:border-red-950/50 "
|
||||
: "not-disabled:cursor-pointer md:not-hover:border-zinc-700 md:not-hover:text-zinc-400 text-white ") +
|
||||
"rounded-xl transition-colors h-10 min-w-10 not-md:p-2 " +
|
||||
(className ? className : "")
|
||||
}
|
||||
aria-disabled={disabled}
|
||||
onClick={disabled ? undefined : onClick}
|
||||
>
|
||||
{children}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
const defaultDialogContent = {
|
||||
message: "?",
|
||||
yesBtn: "da",
|
||||
noBtn: "net",
|
||||
bgDissmis: true,
|
||||
yesBlocked: false,
|
||||
yesIcon: <BiCheck />,
|
||||
noIcon: <BiX />,
|
||||
noBtnStyle: "",
|
||||
yesBtnStyle: "",
|
||||
};
|
||||
export function DengiYesOrNoDialog({
|
||||
content = defaultDialogContent,
|
||||
show = false,
|
||||
//@ts-ignore
|
||||
onAnswer,
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
{show && (
|
||||
<div
|
||||
className="fixed z-99 bg-black/50 backdrop-blur-xl top-0 left-0 w-full h-full overflow-hidden flex items-center justify-center"
|
||||
onClick={(e) => {
|
||||
if (e.target === e.currentTarget && content.bgDissmis)
|
||||
onAnswer(false);
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="flex flex-col justify-center gap-4 p-4 border bg-black border-zinc-400 rounded-2xl"
|
||||
>
|
||||
<span>{content.message}</span>
|
||||
<div className="flex gap-2 justify-stretch">
|
||||
<DengiButton
|
||||
className={content.yesBtnStyle + " w-full"}
|
||||
onClick={() => onAnswer(true)}
|
||||
disabled={content.yesBlocked}
|
||||
>
|
||||
{content.yesIcon}
|
||||
{content.yesBtn}
|
||||
</DengiButton>
|
||||
<DengiButton
|
||||
className={content.noBtnStyle + " w-full"}
|
||||
onClick={() => onAnswer(false)}
|
||||
>
|
||||
{content.noIcon}
|
||||
{content.noBtn}
|
||||
</DengiButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import { API_BASE_URL } from "../App";
|
||||
import { b64e } from "./trash";
|
||||
|
||||
export async function makeRequest(
|
||||
url: string,
|
||||
params?:
|
||||
| string
|
||||
| Record<string, string>
|
||||
| string[][]
|
||||
| URLSearchParams
|
||||
| undefined
|
||||
) {
|
||||
try {
|
||||
const req = await fetch(url, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
||||
body: new URLSearchParams(params).toString(),
|
||||
});
|
||||
|
||||
return req.ok &&
|
||||
req.headers.get("Content-Type")?.includes("application/json")
|
||||
? [1, await req.json()]
|
||||
: [req.status, await req.text()];
|
||||
} catch (err) {
|
||||
return [-1, err];
|
||||
}
|
||||
}
|
||||
|
||||
export function LoginReq(pass: string) {
|
||||
return makeRequest(API_BASE_URL + "?login", { pass });
|
||||
}
|
||||
|
||||
export function ServerReq(pass: string) {
|
||||
return makeRequest(API_BASE_URL + "?server", { pass });
|
||||
}
|
||||
|
||||
export function ServerBlockReq(pass: string, block: boolean) {
|
||||
return makeRequest(API_BASE_URL + "?server", {
|
||||
pass,
|
||||
action: block ? "disable" : "enable",
|
||||
});
|
||||
}
|
||||
export function ServerMsgBlockReq(pass: string, value: string) {
|
||||
return makeRequest(API_BASE_URL + "?server", {
|
||||
pass,
|
||||
action: "update_block_message",
|
||||
value,
|
||||
});
|
||||
}
|
||||
|
||||
export function ClassesReq(pass: string) {
|
||||
return makeRequest(API_BASE_URL + "?class", { pass });
|
||||
}
|
||||
|
||||
export function ClassReq(pass: string, classId: string) {
|
||||
return makeRequest(API_BASE_URL + "?class", { pass, classId });
|
||||
}
|
||||
|
||||
export function ClassUpdateNameReq(
|
||||
pass: string,
|
||||
classId: string,
|
||||
value: string
|
||||
) {
|
||||
return makeRequest(API_BASE_URL + "?class", {
|
||||
pass,
|
||||
classId,
|
||||
action: "update_name",
|
||||
value,
|
||||
});
|
||||
}
|
||||
|
||||
export function CreateClassReq(
|
||||
pass: string,
|
||||
classId: string,
|
||||
className: string
|
||||
) {
|
||||
return makeRequest(API_BASE_URL + "?class", {
|
||||
pass,
|
||||
classId,
|
||||
action: "create",
|
||||
value: className,
|
||||
});
|
||||
}
|
||||
|
||||
export function DELETEClassRequest(pass: string, classId: string) {
|
||||
return makeRequest(API_BASE_URL + "?class", {
|
||||
pass,
|
||||
classId,
|
||||
action: "DELETE",
|
||||
});
|
||||
}
|
||||
|
||||
export function AdminUpdateReq(
|
||||
pass: string,
|
||||
adminId: string,
|
||||
action: "level" | "name",
|
||||
value: string
|
||||
) {
|
||||
return makeRequest(API_BASE_URL + "?admin", {
|
||||
pass,
|
||||
adminId,
|
||||
action: "update_" + action,
|
||||
value,
|
||||
});
|
||||
}
|
||||
|
||||
export function AdminRemoveReq(pass: string, adminId: string) {
|
||||
return makeRequest(API_BASE_URL + "?admin", {
|
||||
pass,
|
||||
adminId,
|
||||
action: "DELETE",
|
||||
});
|
||||
}
|
||||
|
||||
export function AdminCreateReq(
|
||||
pass: string,
|
||||
classId: string,
|
||||
adminId: string,
|
||||
adminName: string,
|
||||
adminPrems: string
|
||||
) {
|
||||
return makeRequest(API_BASE_URL + "?class", {
|
||||
pass,
|
||||
classId,
|
||||
action: "create_admin",
|
||||
value: `${adminId};${b64e(adminName)};${adminPrems}`,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
.anim_preloader {
|
||||
animation: anim-preloader 1s infinite linear;
|
||||
}
|
||||
@keyframes anim-preloader {
|
||||
from {
|
||||
transform: translateX(-50px) rotate(20deg);
|
||||
}
|
||||
to {
|
||||
transform: translateX(calc((var(--w, 50px)) + (50px))) rotate(20deg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import { CLIENT_FRONTEND_URL } from "../App";
|
||||
|
||||
export const secondPathSegment = (p: string) =>
|
||||
p.replace(/^\/?[^/]+/, "").replace(/^\/+/, "");
|
||||
|
||||
export function b64e(str: string) {
|
||||
return btoa(
|
||||
encodeURIComponent(str).replace(
|
||||
/%([0-9A-F]{2})/g,
|
||||
function toSolidBytes(_match, p1) {
|
||||
// @ts-ignore
|
||||
return String.fromCharCode("0x" + p1);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export function b64d(str: string) {
|
||||
return decodeURIComponent(
|
||||
atob(str)
|
||||
.split("")
|
||||
.map(function (c) {
|
||||
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
|
||||
})
|
||||
.join("")
|
||||
);
|
||||
}
|
||||
|
||||
/** by claude
|
||||
* @param {string} text - The text to copy to clipboard
|
||||
* @returns {Promise<boolean>} - Returns true if successful, false otherwise
|
||||
*/
|
||||
export async function copyToClipboard(text: string) {
|
||||
// Method 1: Modern Clipboard API (preferred)
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.warn("Clipboard API failed, trying fallback:", err);
|
||||
}
|
||||
}
|
||||
// Method 2: Fallback for older browsers or non-secure contexts
|
||||
try {
|
||||
const textarea = document.createElement("textarea");
|
||||
textarea.value = text;
|
||||
textarea.style.position = "fixed";
|
||||
textarea.style.left = "-999999px";
|
||||
textarea.style.top = "-999999px";
|
||||
textarea.style.opacity = "0";
|
||||
textarea.setAttribute("readonly", "");
|
||||
document.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
textarea.setSelectionRange(0, text.length);
|
||||
const success = document.execCommand("copy");
|
||||
document.body.removeChild(textarea);
|
||||
return success;
|
||||
} catch (err) {
|
||||
console.error("All copy methods failed:", err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// dx4 specific
|
||||
export async function copyDXLink(
|
||||
classId: string,
|
||||
adminId: string | undefined = undefined
|
||||
) {
|
||||
return copyToClipboard(
|
||||
CLIENT_FRONTEND_URL + "#//" + classId + (adminId ? ";" + b64e(adminId) : "")
|
||||
);
|
||||
}
|
||||
|
||||
export const randomString = (length: number, symbols: string[]) => {
|
||||
const len = symbols.length;
|
||||
return Array.from(
|
||||
{ length },
|
||||
() => symbols[Math.floor(Math.random() * len)]
|
||||
).join("");
|
||||
};
|
||||
|
||||
|
||||
export const AvailableSymbols = (() => {
|
||||
const a = "abcdefghijklmnopqrstuvwxyz"; // alphabet
|
||||
const A = a.toUpperCase(); // ALPHABET
|
||||
const n = "1234567890"; // numbers
|
||||
const s = "_-"; // specials
|
||||
return (a + n + A + s).split("");
|
||||
})();
|
||||
|
||||
export const AvailableAdminSymbols = [...AvailableSymbols, ..."$()*^%@!+=.".split("")];
|
||||
@@ -0,0 +1 @@
|
||||
export type ssroutetype = (setRoute: (e: string) => void, r: string) => void;
|
||||
Reference in New Issue
Block a user