UPDATE: New data 4.1.5
All checks were successful
Gitea Auto Deploy / Deploy-Container (push) Successful in 40s
All checks were successful
Gitea Auto Deploy / Deploy-Container (push) Successful in 40s
This commit is contained in:
BIN
data/avatar_basic.json.br
Normal file
BIN
data/avatar_basic.json.br
Normal file
Binary file not shown.
BIN
data/monster_basic.json.br
Normal file
BIN
data/monster_basic.json.br
Normal file
Binary file not shown.
@@ -26,21 +26,16 @@ const nextConfig: NextConfig = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
protocol: "https",
|
protocol: "https",
|
||||||
hostname: "r2.kain.id.vn",
|
hostname: "cdn.punklorde.org",
|
||||||
pathname: "**",
|
pathname: "**",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
protocol: "https",
|
|
||||||
hostname: "cdn.kain.id.vn",
|
|
||||||
pathname: "**",
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
compiler: {
|
compiler: {
|
||||||
styledComponents: true,
|
styledComponents: true,
|
||||||
},
|
},
|
||||||
env: {
|
env: {
|
||||||
CDN_URL: "https://r2.kain.id.vn/asbres",
|
CDN_URL: "https://cdn.punklorde.org/asbres",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
55232
public/data/monster.json
55232
public/data/monster.json
File diff suppressed because it is too large
Load Diff
25
src/app/api/data/[name]/route.ts
Normal file
25
src/app/api/data/[name]/route.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { getDataCache } from "@/lib/cache/cache"
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
req: Request,
|
||||||
|
{ params }: { params: Promise<{ name: string }> }
|
||||||
|
) {
|
||||||
|
const { name } = await params
|
||||||
|
|
||||||
|
const item = getDataCache(name)
|
||||||
|
|
||||||
|
if (!item) {
|
||||||
|
return new Response("Not found", { status: 404 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const headers: Record<string, string> = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Cache-Control": "public, max-age=3600"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.type === "br") {
|
||||||
|
headers["Content-Encoding"] = "br"
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(new Uint8Array(item.buf), { headers })
|
||||||
|
}
|
||||||
@@ -5,6 +5,11 @@ import { useTranslations } from "next-intl";
|
|||||||
|
|
||||||
type TFunc = ReturnType<typeof useTranslations>
|
type TFunc = ReturnType<typeof useTranslations>
|
||||||
|
|
||||||
|
function cleanText(text: string): string {
|
||||||
|
if (!text) return ""
|
||||||
|
return text.replace(/<unbreak>(.*?)<\/unbreak>/g, "$1")
|
||||||
|
}
|
||||||
|
|
||||||
export function getNameChar(
|
export function getNameChar(
|
||||||
locale: string,
|
locale: string,
|
||||||
t: TFunc,
|
t: TFunc,
|
||||||
@@ -28,7 +33,7 @@ export function getNameChar(
|
|||||||
text = `${t("trailblazer")} • ${t(data?.baseType?.toLowerCase() ?? "")}`;
|
text = `${t("trailblazer")} • ${t(data?.baseType?.toLowerCase() ?? "")}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return text;
|
return cleanText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNameEnemy(locale: string, data: MonsterBasic | undefined): string {
|
export function getNameEnemy(locale: string, data: MonsterBasic | undefined): string {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export async function checkConnectTcpApi(): Promise<boolean> {
|
|||||||
|
|
||||||
export async function getCharacterListApi(): Promise<CharacterBasic[]> {
|
export async function getCharacterListApi(): Promise<CharacterBasic[]> {
|
||||||
try {
|
try {
|
||||||
const res = await axios.get<CharacterBasic[]>("/data/character.json");
|
const res = await axios.get<CharacterBasic[]>("/api/data/avatar_basic");
|
||||||
return res.data
|
return res.data
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (axios.isAxiosError(error)) {
|
if (axios.isAxiosError(error)) {
|
||||||
@@ -38,7 +38,7 @@ export async function getCharacterListApi(): Promise<CharacterBasic[]> {
|
|||||||
|
|
||||||
export async function getEnemyListApi(): Promise<MonsterBasic[]> {
|
export async function getEnemyListApi(): Promise<MonsterBasic[]> {
|
||||||
try {
|
try {
|
||||||
const res = await axios.get<MonsterBasic[]>("/data/monster.json");
|
const res = await axios.get<MonsterBasic[]>("/api/data/monster_basic");
|
||||||
return res.data
|
return res.data
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (axios.isAxiosError(error)) {
|
if (axios.isAxiosError(error)) {
|
||||||
|
|||||||
38
src/lib/cache/cache.ts
vendored
Normal file
38
src/lib/cache/cache.ts
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { readFileSync, readdirSync } from "fs"
|
||||||
|
import path from "path"
|
||||||
|
|
||||||
|
type CacheItem = {
|
||||||
|
buf: Uint8Array
|
||||||
|
type: "json" | "br"
|
||||||
|
}
|
||||||
|
|
||||||
|
const cache = new Map<string, CacheItem>()
|
||||||
|
|
||||||
|
const dir = path.join(process.cwd(), "data")
|
||||||
|
|
||||||
|
for (const f of readdirSync(dir)) {
|
||||||
|
const file = path.join(dir, f)
|
||||||
|
|
||||||
|
if (f.endsWith(".json.br")) {
|
||||||
|
const name = f.replace(".json.br", "")
|
||||||
|
const buf = new Uint8Array(readFileSync(file))
|
||||||
|
cache.set(name, {
|
||||||
|
buf,
|
||||||
|
type: "br"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f.endsWith(".json")) {
|
||||||
|
const name = f.replace(".json", "")
|
||||||
|
const buf = new Uint8Array(readFileSync(file))
|
||||||
|
|
||||||
|
cache.set(name, {
|
||||||
|
buf,
|
||||||
|
type: "json"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getDataCache(name: string) {
|
||||||
|
return cache.get(name)
|
||||||
|
}
|
||||||
1
src/lib/cache/index.ts
vendored
Normal file
1
src/lib/cache/index.ts
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from "./cache"
|
||||||
Reference in New Issue
Block a user