Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
guyutongxue committed Dec 30, 2024
0 parents commit 2ff060f
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/vercel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Vercel Production Deployment
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
push:
branches:
- main
jobs:
Deploy-Production:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- run: bunx vercel deploy --prod --token=${{ secrets.VERCEL_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vercel
node_modules

/data
68 changes: 68 additions & 0 deletions api/v2/data/[id].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// @ts-check
import characters_ from "../../../data/characters.json";
import actionCards_ from "../../../data/action_cards.json";
import entities_ from "../../../data/entities.json";
import keywords_ from "../../../data/keywords.json";

/**
* @typedef {import("@gi-tcg/static-data").CharacterRawData} CharacterRawData
* @typedef {import("@gi-tcg/static-data").ActionCardRawData} ActionCardRawData
* @typedef {import("@gi-tcg/static-data").EntityRawData} EntityRawData
* @typedef {import("@gi-tcg/static-data").KeywordRawData} KeywordRawData
*/

/** @type {CharacterRawData[]} */
const characters = characters_;

/** @type {ActionCardRawData[]} */
const actionCards = actionCards_;

/** @type {EntityRawData[]} */
const entities = /** @type {EntityRawData[]} */ (entities_);

/** @type {KeywordRawData[]} */
const keywords = keywords_;

/**
* @typedef {import("@vercel/node").VercelRequest} VercelRequest
* @typedef {import("@vercel/node").VercelResponse} VercelResponse
*/

const skills = [...characters, ...entities].flatMap((ch) => ch.skills);

/**
*
* @param {import('@gi-tcg/static-data').EntityRawData} x
*/
function key(x) {
if (x.type === "GCG_CARD_SUMMON") return 0;
else return 1;
}

const sortedEntities = entities.toSorted((a, b) => key(a) - key(b));

const all = [
...characters,
...actionCards,
...skills,
...sortedEntities,
...keywords,
];

/**
*
* @param {VercelRequest} req
* @param {VercelResponse} res
* @returns
*/
export default function handler(req, res) {
const { id } = req.query;
const found = all.find((obj) => obj.id === Number(id));
if (found) {
res.status(200).json(found);
return;
} else {
res.status(404).send("Not found");
return;
}
}
33 changes: 33 additions & 0 deletions api/v2/images/[id].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// @ts-check
import rawData from "../../../data/image_names.json";

/**
* @typedef {import("@vercel/node").VercelRequest} VercelRequest
* @typedef {import("@vercel/node").VercelResponse} VercelResponse
*/

/** @type {Record<string, string>} */
const imageMap = rawData;

/**
*
* @param {VercelRequest} req
* @param {VercelResponse} res
* @returns
*/
export default function handler(req, res) {
const { id, thumb } = req.query;
if (Array.isArray(id)) {
res.status(400)
.send("Bad request (multiple id)");
return;
}
const image = imageMap[id];
if (!image) {
res.status(404)
.send("Not found");
return;
}
const url = `https://api.hakush.in/gi/UI/${image}.webp`;
res.status(307).setHeader("Location", url).send(void 0);
}
Binary file added bun.lockb
Binary file not shown.
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@gi-tcg/assets-beta",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"build": "bun scripts/generate_data.ts"
},
"devDependencies": {
"@gi-tcg/static-data": "^0.16.1",
"@types/bun": "^1.1.14",
"vercel": "^39.2.2"
}
}
3 changes: 3 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<title>beta.assets.gi-tcg.guyutongxue.site</title>
<h1>beta.assets.gi-tcg.guyutongxue.site</h1>
<p>Use <code>api/v2</code> endpoints.</p>
61 changes: 61 additions & 0 deletions scripts/generate_data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

const BASE = `https://raw.githubusercontent.com/genius-invokation/genius-invokation-beta/refs/heads/beta/packages/static-data/src/data`;

const TARGET_PATH = `${import.meta.dirname}/../data`;

const FILENAMES = [
"action_cards.json",
"characters.json",
"entities.json",
"keywords.json"
];

const allData: any[] = [];

for (const filename of FILENAMES) {
const data = await fetch(`${BASE}/${filename}`).then((r) => r.text());
allData.push(...JSON.parse(data));
await Bun.write(`${TARGET_PATH}/${filename}`, data);
}

const result: Record<number, string> = {
"0": "UI_Gcg_Buff_Common_Element_Physics",
"1": "UI_Gcg_Buff_Common_Element_Ice",
"2": "UI_Gcg_Buff_Common_Element_Water",
"3": "UI_Gcg_Buff_Common_Element_Fire",
"4": "UI_Gcg_Buff_Common_Element_Electric",
"5": "UI_Gcg_Buff_Common_Element_Wind",
"6": "UI_Gcg_Buff_Common_Element_Rock",
"7": "UI_Gcg_Buff_Common_Element_Grass",
"9": "UI_Gcg_Buff_Common_Element_Heal",
};
const replaceNameMap: Record<string, string> = {
UI_Gcg_CardFace_Summon_AbyssEle: "UI_Gcg_CardFace_Summon_AbyssEle_Layer00",
UI_Gcg_CardFace_Char_Monster_Effigyice:
"UI_Gcg_CardFace_Char_Monster_EffigyIce",
};


// 召唤物、角色牌、行动牌
for (const obj of allData) {
let filename: string;
if ("cardFace" in obj && obj.cardFace) {
filename = obj.cardFace;
} else if ("icon" in obj && obj.icon) {
filename = obj.icon;
} else if ("buffIcon" in obj && obj.buffIcon) {
filename = obj.buffIcon;
} else if ("buffIconHash" in obj && obj.buffIconHash) {
filename = "UI_Gcg_Buff_Common_Special";
} else {
continue;
}
if (filename in replaceNameMap) {
filename = replaceNameMap[filename];
}
if (!result[obj.id]) {
result[obj.id] = filename;
}
}

await Bun.write(`${TARGET_PATH}/image_names.json`, JSON.stringify(result, null, 2));
15 changes: 15 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "Bundler",
"lib": ["ES2023"],

"moduleDetection": "force",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
},
}
28 changes: 28 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"installCommand": "bun install",
"buildCommand": "bun run build",
"headers": [
{
"source": "/api/(.*)",
"headers": [
{
"key": "Access-Control-Allow-Credentials",
"value": "true"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Access-Control-Allow-Methods",
"value": "GET,OPTIONS,PATCH,DELETE,POST,PUT"
},
{
"key": "Access-Control-Allow-Headers",
"value": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version"
}
]
}
],
"outputDirectory": "public"
}

0 comments on commit 2ff060f

Please sign in to comment.