chore: fmt [no ci]

This commit is contained in:
2026-07-07 22:16:21 +07:00 Unverified
parent 2db9bb10a2
commit 7bfabaa5a1
8 changed files with 147 additions and 127 deletions
+20 -20
View File
@@ -6,23 +6,23 @@ metadata:
spec:
ingressClassName: traefik
rules:
- host: api.dgnr.us
http:
paths:
- backend:
service:
name: enka-api
port:
number: 80
path: /
pathType: Prefix
- host: api.astrxl.dev
http:
paths:
- backend:
service:
name: enka-api
port:
number: 80
path: /
pathType: Prefix
- host: api.dgnr.us
http:
paths:
- backend:
service:
name: enka-api
port:
number: 80
path: /
pathType: Prefix
- host: api.astrxl.dev
http:
paths:
- backend:
service:
name: enka-api
port:
number: 80
path: /
pathType: Prefix
+9 -9
View File
@@ -4,12 +4,12 @@ kind: Kustomization
namespace: enka
resources:
- namespace.yaml
- deployment.yaml
- service.yaml
- ingress.yaml
- secret.yaml
- service-account.yaml
- role.yaml
- role-binding.yaml
- token-secret.yaml
- namespace.yaml
- deployment.yaml
- service.yaml
- ingress.yaml
- secret.yaml
- service-account.yaml
- role.yaml
- role-binding.yaml
- token-secret.yaml
+3 -3
View File
@@ -8,6 +8,6 @@ roleRef:
kind: Role
name: ci-deployer
subjects:
- kind: ServiceAccount
name: ci-deployer
namespace: enka
- kind: ServiceAccount
name: ci-deployer
namespace: enka
+15 -15
View File
@@ -4,18 +4,18 @@ metadata:
name: ci-deployer
namespace: enka
rules:
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get", "list", "watch", "update", "patch"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["services"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
- apiGroups: ["networking.k8s.io"]
resources: ["ingresses"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
- apiGroups: ["batch"]
resources: ["jobs"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get", "list", "watch", "update", "patch"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["services"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
- apiGroups: ["networking.k8s.io"]
resources: ["ingresses"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
- apiGroups: ["batch"]
resources: ["jobs"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
+3 -3
View File
@@ -6,8 +6,8 @@ metadata:
spec:
type: ClusterIP
ports:
- name: http
port: 80
targetPort: 3000
- name: http
port: 80
targetPort: 3000
selector:
app: enka-api
+76 -70
View File
@@ -484,82 +484,88 @@ export function card(app: App) {
afterResponse: ({ log }) => log`Rendering completed`,
},
)
.get("/enka/:username", async ({ params: { username }, query: { lang } }) => {
const errorLoc = cardErrorLocs[lang === "th" ? "th" : "en"];
try {
const cacheKey = `enka-redir::${username}`;
if (feature("API")) {
const cached = cache.get<Response>(cacheKey);
if (cached) return cached.clone();
}
.get(
"/enka/:username",
async ({ params: { username }, query: { lang } }) => {
const errorLoc = cardErrorLocs[lang === "th" ? "th" : "en"];
try {
const cacheKey = `enka-redir::${username}`;
if (feature("API")) {
const cached = cache.get<Response>(cacheKey);
if (cached) return cached.clone();
}
const [hoyo] = await fetch(
`https://enka.network/api/profile/${username}/hoyos/`,
)
.then(throwNotOk)
.then(
(r) =>
r.json() as Promise<
Record<string, { hoyo_type: number; order: NumberLike }>
>,
const [hoyo] = await fetch(
`https://enka.network/api/profile/${username}/hoyos/`,
)
.then((e) =>
Object.entries(e)
.map(([k, v]) => ({ hash: k, ...v }))
.sort((a, b) => Number(a.order) - Number(b.order))
.filter((e) => e.hoyo_type === 0),
.then(throwNotOk)
.then(
(r) =>
r.json() as Promise<
Record<string, { hoyo_type: number; order: NumberLike }>
>,
)
.then((e) =>
Object.entries(e)
.map(([k, v]) => ({ hash: k, ...v }))
.sort((a, b) => Number(a.order) - Number(b.order))
.filter((e) => e.hoyo_type === 0),
);
if (!hoyo) return status(404, errorLoc.profileNotFound);
const buildsArr = fetch(
`https://enka.network/api/profile/${username}/hoyos/${hoyo.hash}/builds/`,
)
.then(throwNotOk)
.then(
(r) =>
r.json() as Promise<
Record<string, { id: number; order: NumberLike }[]>
>,
);
const builds = await buildsArr.then((e) =>
((
pair:
| [string, { id: number; order: `${number}` }[]]
| undefined,
) =>
pair
? {
char: pair[0],
...pair[1]
.sort((a, b) => Number(a.order) - Number(b.order))
.shift(),
}
: undefined)(Object.entries(e).shift()),
);
if (!hoyo) return status(404, errorLoc.profileNotFound);
const buildsArr = fetch(
`https://enka.network/api/profile/${username}/hoyos/${hoyo.hash}/builds/`,
)
.then(throwNotOk)
.then(
(r) =>
r.json() as Promise<
Record<string, { id: number; order: NumberLike }[]>
>,
);
const builds = await buildsArr.then((e) =>
((
pair: [string, { id: number; order: `${number}` }[]] | undefined,
) =>
pair
? {
char: pair[0],
...pair[1]
.sort((a, b) => Number(a.order) - Number(b.order))
.shift(),
}
: undefined)(Object.entries(e).shift()),
);
if (!builds?.id) return status(404, errorLoc.buildNotFound);
if (!builds?.id) return status(404, errorLoc.buildNotFound);
const res = redirect(
`/v1/card/enka/${username}/${hoyo.hash}/${builds.char}/${builds.id}`,
);
queueMicrotask(async () => {
cache.set(cacheKey, res, 1000 * 60); // cache for 1 minute
cache.set(
`enka-redir::${username}::${hoyo.hash}`,
await buildsArr,
1000 * 120,
const res = redirect(
`/v1/card/enka/${username}/${hoyo.hash}/${builds.char}/${builds.id}`,
);
});
queueMicrotask(async () => {
cache.set(cacheKey, res, 1000 * 60); // cache for 1 minute
cache.set(
`enka-redir::${username}::${hoyo.hash}`,
await buildsArr,
1000 * 120,
);
});
return res.clone();
} catch (err) {
if (err instanceof ResponseNotOkError && err.status === 404)
return status(404, errorLoc.profileNotFound);
throw err;
}
}, {
query: t.Partial(
t.Object({
lang: Locale,
}),
),
})
return res.clone();
} catch (err) {
if (err instanceof ResponseNotOkError && err.status === 404)
return status(404, errorLoc.profileNotFound);
throw err;
}
},
{
query: t.Partial(
t.Object({
lang: Locale,
}),
),
},
)
.get(
"/enka/:username/:hash/:char/:build",
async ({
+1 -2
View File
@@ -243,8 +243,7 @@ export async function ListPage(
cons:
avatarInfoList?.find(
(e) => e.avatar.avatarId === a.avatar.avatarId,
)!.talentIdList?.length ??
a.talentLevel,
)!.talentIdList?.length ?? a.talentLevel,
}))
.map(({ a, c, cons }) => (
<div tw="relative flex flex-col rounded-[.3em] overflow-hidden shadow-[0_.08em_.35em_rgba(0,0,0,.18)]">
+20 -5
View File
@@ -33,19 +33,31 @@ export function webhookMerger(app: App) {
const oldData = existing.data;
const flushed = new Set<string>();
existing.data = merge(oldData, body, undefined, MAX_FIELD_LENGTH, flushed);
existing.data = merge(
oldData,
body,
undefined,
MAX_FIELD_LENGTH,
flushed,
);
existing.count++;
if (flushed.size > 0) {
existing.count = 1;
forward(id, url, oldData);
existing.timer = setTimeout(() => forward(id, url, existing.data), bufferTime);
existing.timer = setTimeout(
() => forward(id, url, existing.data),
bufferTime,
);
return status(202);
}
log.debug`collected ${existing}`;
existing.timer = setTimeout(() => forward(id, url, existing.data), bufferTime);
existing.timer = setTimeout(
() => forward(id, url, existing.data),
bufferTime,
);
return status(202);
}
@@ -77,11 +89,14 @@ async function getRoutes(): Promise<RouteMap> {
function parseRouteMap(raw: string): RouteMap {
const parsed = JSON.parse(raw) as unknown;
if (!Array.isArray(parsed)) throw new Error("WH_ROUTE_MAP must be a JSON array");
if (!Array.isArray(parsed))
throw new Error("WH_ROUTE_MAP must be a JSON array");
for (const [index, route] of parsed.entries()) {
if (!Array.isArray(route) || route.length !== 3) {
throw new Error(`WH_ROUTE_MAP route ${index} must be [id, url, bufferTime]`);
throw new Error(
`WH_ROUTE_MAP route ${index} must be [id, url, bufferTime]`,
);
}
const [id, url, bufferTime] = route;