Updated
This commit is contained in:
parent
fec3abd5d8
commit
bcb83dfea5
13 changed files with 1542 additions and 4019 deletions
|
|
@ -1,25 +1,46 @@
|
|||
import { ofetch } from 'ofetch'
|
||||
import { $backendUrl, $requestRetries, $requestRetryCodes } from '../../../../configs/config.api'
|
||||
import * as fs from "node:fs";
|
||||
import { ofetch } from "ofetch";
|
||||
import * as toml from "toml";
|
||||
|
||||
const URL = $backendUrl.get()
|
||||
const RETRY = $requestRetries.get()
|
||||
const CODES = $requestRetryCodes.get()
|
||||
const config = toml.parse(fs.readFileSync("configs/config.api.toml", "utf-8"));
|
||||
const URL = config.backend.backend_url;
|
||||
const RETRY = config.request.request_retries;
|
||||
const CODES = config.request.request_retry_codes;
|
||||
|
||||
export default async (api: string, value?: any, value2?: any) => {
|
||||
try {
|
||||
let fetch
|
||||
if (!value2) {
|
||||
if (!value) {
|
||||
fetch = await ofetch(URL + api, { parseResponse: JSON.parse, retry: RETRY, retryDelay: 500, retryStatusCodes: CODES })
|
||||
} else {
|
||||
fetch = await ofetch(URL + `${api}/${value}/fetch-data`, { parseResponse: JSON.parse, retry: RETRY, retryDelay: 500, retryStatusCodes: CODES })
|
||||
}
|
||||
} else {
|
||||
fetch = await ofetch(URL + `${api}/${value}/${value2}/fetch-data`, { parseResponse: JSON.parse, retry: RETRY, retryDelay: 500, retryStatusCodes: CODES })
|
||||
}
|
||||
const result = fetch
|
||||
return [result, null]
|
||||
} catch (error) {
|
||||
return [[], error]
|
||||
}
|
||||
}
|
||||
export default async (
|
||||
api: string,
|
||||
value?: string | number,
|
||||
value2?: string | number,
|
||||
) => {
|
||||
try {
|
||||
let fetch: { [key: string]: unknown };
|
||||
if (!value2) {
|
||||
if (!value) {
|
||||
fetch = await ofetch(URL + api, {
|
||||
parseResponse: JSON.parse,
|
||||
retry: RETRY,
|
||||
retryDelay: 500,
|
||||
retryStatusCodes: CODES,
|
||||
});
|
||||
} else {
|
||||
fetch = await ofetch(`${URL}${api}/${value}/fetch-data`, {
|
||||
parseResponse: JSON.parse,
|
||||
retry: RETRY,
|
||||
retryDelay: 500,
|
||||
retryStatusCodes: CODES,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
fetch = await ofetch(`${URL}${api}/${value}/${value2}/fetch-data`, {
|
||||
parseResponse: JSON.parse,
|
||||
retry: RETRY,
|
||||
retryDelay: 500,
|
||||
retryStatusCodes: CODES,
|
||||
});
|
||||
}
|
||||
const result = fetch;
|
||||
return [result, null];
|
||||
} catch (error) {
|
||||
return [[], error];
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,37 +1,48 @@
|
|||
import dayjs from 'dayjs'
|
||||
import { ofetch } from 'ofetch'
|
||||
import { $backendUrl, $requestRetries, $requestRetryCodes } from '../../../../configs/config.api'
|
||||
import { $tokenExpiration, $tokenName } from '../../../../configs/config.security'
|
||||
import { encryptRsa } from '../../scripts'
|
||||
/** biome-ignore-all lint/suspicious/noExplicitAny: <_> */
|
||||
|
||||
const URL = $backendUrl.get()
|
||||
const TOKEN_NAME = $tokenName.get()
|
||||
const TOKEN_EXPIRATION = $tokenExpiration.get()
|
||||
const RETRY = $requestRetries.get()
|
||||
const CODES = $requestRetryCodes.get()
|
||||
import dayjs from "dayjs";
|
||||
import * as fs from "node:fs";
|
||||
import { ofetch } from "ofetch";
|
||||
import * as toml from "toml";
|
||||
import { encryptRsa } from "../../scripts/index.ts";
|
||||
|
||||
export default async (api: string, body: Object) => {
|
||||
const today = new Date()
|
||||
const todayUnix = dayjs(today).unix()
|
||||
const expiration = todayUnix + TOKEN_EXPIRATION
|
||||
const aes = await encryptRsa(`${api.toString()}-${todayUnix.toString()}-${expiration.toString()}`)
|
||||
const apiConfig = toml.parse(
|
||||
fs.readFileSync("configs/config.api.toml", "utf-8"),
|
||||
);
|
||||
const securityConfig = toml.parse(
|
||||
fs.readFileSync("configs/config.security.toml", "utf-8"),
|
||||
);
|
||||
|
||||
const hash = `${TOKEN_NAME}=${aes}token`
|
||||
try {
|
||||
await ofetch(URL + api, {
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Dasig-Token': hash,
|
||||
},
|
||||
retry: RETRY,
|
||||
retryDelay: 500,
|
||||
retryStatusCodes: CODES,
|
||||
method: 'POST',
|
||||
body: body,
|
||||
})
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
const TOKEN_NAME = securityConfig.token.token_name;
|
||||
const TOKEN_EXPIRATION = securityConfig.token.token_expiration;
|
||||
const URL = apiConfig.backend.backend_url;
|
||||
const RETRY = apiConfig.request.request_retries;
|
||||
const CODES = apiConfig.request.request_retry_codes;
|
||||
|
||||
export default async (api: string, body: { [key: string]: unknown }) => {
|
||||
const today = new Date();
|
||||
const todayUnix = dayjs(today).unix();
|
||||
const expiration = todayUnix + TOKEN_EXPIRATION;
|
||||
const aes = await encryptRsa(
|
||||
`${api.toString()}-${todayUnix.toString()}-${expiration.toString()}`,
|
||||
);
|
||||
|
||||
const hash = `${TOKEN_NAME}=${aes}token`;
|
||||
try {
|
||||
await ofetch(URL + api, {
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Cache-Control": "no-cache",
|
||||
"Dasig-Token": hash,
|
||||
},
|
||||
retry: RETRY,
|
||||
retryDelay: 500,
|
||||
retryStatusCodes: CODES,
|
||||
method: "POST",
|
||||
body: body,
|
||||
});
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
/** biome-ignore-all lint/complexity/noUselessFragments: <_> */
|
||||
import * as fs from "node:fs";
|
||||
import { type JSXElement, Show } from "solid-js";
|
||||
import { $fontSource } from "../../configs/config.site.ts";
|
||||
import * as toml from 'toml';
|
||||
import background1 from "../images/background.avif";
|
||||
import background2 from "../images/background.webp";
|
||||
import "../styles/HTML.sass";
|
||||
|
|
@ -22,6 +24,7 @@ interface Props {
|
|||
}
|
||||
|
||||
export default (props: Props) => {
|
||||
const config = toml.parse(fs.readFileSync('configs/config.site.toml', 'utf8'))
|
||||
return (
|
||||
<>
|
||||
<html lang="en">
|
||||
|
|
@ -40,7 +43,7 @@ export default (props: Props) => {
|
|||
<meta property="og:description" content={props.description} />
|
||||
<meta property="og:type" content="website" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.png" />
|
||||
<Show when={$fontSource.get() === "cdn"}>
|
||||
<Show when={config.font.source === "cdn"}>
|
||||
<link rel="preconnect" href="https://cdn.jsdelivr.net" />
|
||||
</Show>
|
||||
<Show when={props.preloadBackground}>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue