mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 12:09:51 +02:00
update (4)
This commit is contained in:
1 parent
f85d097c16
commit
59108d7637
7 files changed
+96
-6
No files matched your search
@@ -1,4 +1,4 @@
|
|||||||
export function assertSecret<Type>(secret?: Type) {
|
export function assertSecret(secret?: string) {
|
||||||
if (secret === undefined) throw new Error("Missing secret");
|
if (secret === undefined) throw new Error("Missing secret");
|
||||||
return secret;
|
return secret;
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,13 @@
|
|||||||
import {
|
import {
|
||||||
ClientBlitzKitAPI,
|
ClientBlitzKitAPI,
|
||||||
LocalVFS,
|
|
||||||
ServerBlitzKitAPI,
|
ServerBlitzKitAPI,
|
||||||
type BlitzKitAPI,
|
type BlitzKitAPI,
|
||||||
} from "@blitzkit/core";
|
} from "@blitzkit/core";
|
||||||
|
import { vfs } from "./vfs";
|
||||||
|
|
||||||
let _api: BlitzKitAPI;
|
let _api: BlitzKitAPI;
|
||||||
|
|
||||||
if (import.meta.env.SSR) {
|
if (import.meta.env.SSR) {
|
||||||
const vfs = new LocalVFS(
|
|
||||||
"/run/media/tresabhi/Windows/Program Files/WindowsApps/7458BE2C.WorldofTanksBlitz_11.19.272.0_x64__x4tje2y229k00",
|
|
||||||
);
|
|
||||||
|
|
||||||
_api = await new ServerBlitzKitAPI(vfs).init();
|
_api = await new ServerBlitzKitAPI(vfs).init();
|
||||||
} else {
|
} else {
|
||||||
_api = new ClientBlitzKitAPI();
|
_api = new ClientBlitzKitAPI();
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { assertSecret } from "@blitzkit/core";
|
||||||
|
import type { GetStaticPaths } from "astro";
|
||||||
|
|
||||||
|
export function chunkedStaticPaths(chunk: string) {
|
||||||
|
return function () {
|
||||||
|
const chunksEnv = assertSecret(import.meta.env.CHUNKS);
|
||||||
|
const chunks = chunksEnv.split(",");
|
||||||
|
|
||||||
|
if (chunksEnv !== "*" && !chunks.includes(chunk)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [{ params: { [`chunk_${chunk}`]: chunk } }];
|
||||||
|
} satisfies GetStaticPaths;
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import type {
|
||||||
|
GetStaticPathsItem,
|
||||||
|
GetStaticPathsOptions,
|
||||||
|
GetStaticPathsResult,
|
||||||
|
} from "astro";
|
||||||
|
|
||||||
|
type Promisable<T> = T | Promise<T>;
|
||||||
|
|
||||||
|
export function mixStaticPaths<
|
||||||
|
TypeA extends GetStaticPathsItem,
|
||||||
|
TypeB extends GetStaticPathsItem,
|
||||||
|
>(
|
||||||
|
a: (options: GetStaticPathsOptions) => Promisable<TypeA[]>,
|
||||||
|
b: (options: GetStaticPathsOptions) => Promisable<TypeB[]>,
|
||||||
|
) {
|
||||||
|
return async function (options: GetStaticPathsOptions) {
|
||||||
|
const pathsA = await a(options);
|
||||||
|
const pathsB = await b(options);
|
||||||
|
const paths: GetStaticPathsResult = [];
|
||||||
|
|
||||||
|
for (const pathA of pathsA) {
|
||||||
|
for (const pathB of pathsB) {
|
||||||
|
paths.push({
|
||||||
|
params: { ...pathA.params, ...pathB.params },
|
||||||
|
props: { ...pathA.props, ...pathB.props },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return paths as (TypeA & TypeB)[];
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { LocalVFS } from "@blitzkit/core";
|
||||||
|
|
||||||
|
export const vfs = new LocalVFS(
|
||||||
|
"/run/media/tresabhi/Windows/Program Files/WindowsApps/7458BE2C.WorldofTanksBlitz_11.19.272.0_x64__x4tje2y229k00",
|
||||||
|
);
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { chunkedStaticPaths } from "../../core/blitzkit/chunkedStaticPaths";
|
||||||
|
|
||||||
|
export const getStaticPaths = chunkedStaticPaths("api");
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import type { APIContext, GetStaticPathsItem } from "astro";
|
||||||
|
import sharp from "sharp";
|
||||||
|
import { mixStaticPaths } from "../../../../core/blitzkit/mixStaticPaths";
|
||||||
|
import { vfs } from "../../../../core/blitzkit/vfs";
|
||||||
|
import { getStaticPaths as _getStaticPaths } from "../../_index";
|
||||||
|
|
||||||
|
export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
|
||||||
|
const paths: GetStaticPathsItem[] = [];
|
||||||
|
|
||||||
|
const circleFiles = await vfs
|
||||||
|
.dir(`Data/Gfx/Lobby/flags`)
|
||||||
|
.then((files) =>
|
||||||
|
files.filter(
|
||||||
|
(flag) =>
|
||||||
|
flag.startsWith("flag_profile-stat_") &&
|
||||||
|
!flag.endsWith("@2x.packed.webp"),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const flag of circleFiles) {
|
||||||
|
const path = `Data/Gfx/Lobby/flags/${flag}`;
|
||||||
|
const id = flag.match(/flag_profile-stat_(.+)\.packed\.webp/)![1];
|
||||||
|
|
||||||
|
paths.push({
|
||||||
|
params: { id },
|
||||||
|
props: { path },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return paths;
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function GET({ props }: APIContext<{ path: string }>) {
|
||||||
|
const image = sharp(await vfs.file(props.path));
|
||||||
|
const content = await image.trim({ threshold: 100 }).toBuffer();
|
||||||
|
const bytes = new Uint8Array(content);
|
||||||
|
|
||||||
|
return new Response(bytes);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user