This commit is contained in:
Patrick Alvin Alcala 2025-11-26 16:51:33 +08:00
parent fec3abd5d8
commit bcb83dfea5
13 changed files with 1542 additions and 4019 deletions

View file

@ -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) => {
export default async (
api: string,
value?: string | number,
value2?: string | number,
) => {
try {
let fetch
let fetch: { [key: string]: unknown };
if (!value2) {
if (!value) {
fetch = await ofetch(URL + api, { parseResponse: JSON.parse, retry: RETRY, retryDelay: 500, retryStatusCodes: CODES })
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 })
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 })
fetch = await ofetch(`${URL}${api}/${value}/${value2}/fetch-data`, {
parseResponse: JSON.parse,
retry: RETRY,
retryDelay: 500,
retryStatusCodes: CODES,
});
}
const result = fetch
return [result, null]
const result = fetch;
return [result, null];
} catch (error) {
return [[], error]
}
return [[], error];
}
};

View file

@ -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`
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,
Accept: "application/json",
"Cache-Control": "no-cache",
"Dasig-Token": hash,
},
retry: RETRY,
retryDelay: 500,
retryStatusCodes: CODES,
method: 'POST',
method: "POST",
body: body,
})
return true
});
return true;
} catch {
return false
}
return false;
}
};

View file

@ -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}>

View file

@ -1,16 +1,16 @@
.SILENT:
all:
deno install && deno install --allow-scripts=npm:sharp,npm:@parcel/watcher
bun install && bun pm trust --all
dev:
deno task dev
bun run dev
build:
deno task build && PORT=9000 deno run --allow-env --allow-read --allow-net .output/server/index.mjs &
bun run build && PORT=9000 node .output/server/index.mjs &
update:
deno update
bun update
docker:
docker compose up -d

1389
frontend/bun.lock Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,6 @@
[backend]
backend_url = "http://localhost:8080"
[request]
request_retries = 3
request_retry_codes = [400, 404, 405, 500, 502]

View file

@ -1,6 +0,0 @@
import { atom } from 'nanostores'
export const $backendUrl = atom('http://localhost:8080')
export const $requestRetries = atom<number>(3)
export const $requestRetryCodes = atom<Array<number>>([400, 404, 405, 500, 502])

View file

@ -1,10 +1,10 @@
import { atom } from 'nanostores'
[token]
token_name = "dasig" # output: dasig-token
token_encryption = "rsa"
token_expiration = 9 # seconds
export const $tokenName = atom<string>('dasig') // output: dasig-token
export const $tokenEncryption = atom<'rsa'>('rsa')
export const $tokenExpiration = atom<number>(9) // expires in 9 seconds
export const $rsaPublicKey = atom<string>(`-----BEGIN PUBLIC KEY-----
[rsa]
rsa_public_key = '''-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA9Aw5Zasdanf2biS69qoQ
/YZbyIM+LS7LOLNN3ot6nZH1FiTqTNy61ffUA2Y/s3hGz9L0+k6gRu7uGBza6XPU
+iuGdXxZd2mc3lrnPfR6SSllMwGlAVkYpQhmkB19igd8aLUbFiJ3pPKkNocv/yQa
@ -17,4 +17,4 @@ HvEuAHzUBr+GJM9w4/LF1mQSsmblB8q5S7qNaminYAw6wm35lRy7ZlIbJQlj/EyL
lCKWBbUEHkjzRFCoun9VVUc0guQTsTbchPD7Rgzg3SBK3Gws39n12WQPc7jKto0H
N39sJnNzllXw41gKRy9b2uYuaVYaQ0sjrFJ8ITuyO9NDDaEdeBqBBTtbRp2i0O4K
tvT2kItEEnVzjNutUatVOWcCAwEAAQ==
-----END PUBLIC KEY-----`)
-----END PUBLIC KEY-----'''

View file

@ -0,0 +1,11 @@
[website]
name = "Dasig"
description = "An architectural framework for pure speed fullstack development"
[font]
name = "inter"
source = "cdn" # cdn or local
[copyright]
name = "Pat Alcala"
year = 2025

View file

@ -1,10 +0,0 @@
import { atom } from 'nanostores'
export const $websiteName = atom<string>('Dasig')
export const $websiteDescription = atom<string>('A template for next level speed (Solid Version)')
export const $font = atom<string>('inter')
export const $fontSource = atom<'cdn'| 'local'>('cdn')
export const $companyName = atom<string>('Pat Alcala')
export const $copyRightYear = atom<number>(2025)

3922
frontend/deno.lock generated

File diff suppressed because it is too large Load diff

View file

@ -13,14 +13,13 @@
"@solidjs/start": "^1.1.0",
"consola": "^3.4.2",
"dayjs": "^1.11.19",
"eciesjs": "^0.4.16",
"jsencrypt": "^3.5.4",
"nanostores": "^1.1.0",
"ofetch": "^1.5.1",
"png-to-ico": "^3.0.1",
"sharp": "^0.34.5",
"solid-icons": "^1.1.0",
"solid-js": "^1.9.10",
"toml": "^3.0.0",
"vinxi": "^0.5.7",
"yargs": "^18.0.0"
},
@ -31,5 +30,8 @@
"@biomejs/biome": "^2.3.7",
"@types/node": "^24.10.1",
"sass-embedded": "^1.93.3"
}
},
"trustedDependencies": [
"@parcel/watcher"
]
}

View file

@ -1,11 +1,29 @@
// deno-lint-ignore-file jsx-no-children-prop
import { createHandler, StartServer } from '@solidjs/start/server';
import { HTML } from '../@dasig/index.ts';
import { $companyName, $font, $websiteDescription, $websiteName } from '../configs/config.site.ts';
const websiteName = $websiteName.get()
const websiteDescription = $websiteDescription.get()
const author = $companyName.get()
const font = $font.get()
import * as fs from "node:fs";
// import { $companyName, $font, $websiteDescription, $websiteName } from '../configs/config.site.ts';
import { createHandler, StartServer } from "@solidjs/start/server";
import * as toml from "toml";
import { HTML } from "../@dasig/index.ts";
export default createHandler(() => <StartServer document={({ assets, children, scripts }) => <HTML name={websiteName} description={websiteDescription} author={author} children={children} assets={assets} scripts={scripts} font={font} />} />)
const config = toml.parse(fs.readFileSync("configs/config.site.toml", "utf8"));
const websiteName = config.website.name;
const websiteDescription = config.website.description;
const author = config.copyright.name;
const font = config.font.name;
export default createHandler(() => (
<StartServer
document={({ assets, children, scripts }) => (
<HTML
name={websiteName}
description={websiteDescription}
author={author}
children={children}
assets={assets}
scripts={scripts}
font={font}
/>
)}
/>
));