Skip to content

Commit

Permalink
add cape list route
Browse files Browse the repository at this point in the history
  • Loading branch information
InventivetalentDev committed Jan 23, 2025
1 parent 9c335b9 commit 2fe0b9d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
renderRoute,
testerRoute,
utilRoute,
v2CapesRouter,
v2DelayRouter,
v2GenerateRouter,
v2ImagesRouter,
Expand Down Expand Up @@ -357,6 +358,7 @@ async function init() {
app.use("/v2/me", v2MeRouter);
app.use("/v2/delay", v2DelayRouter);
app.use("/v2/images", v2ImagesRouter);
app.use("/v2/capes", v2CapesRouter);
app.use("/v2/usage", v2UsageRouter);
app.use("/v2/stats", v2StatsRouter);
app.use("/v2/sitemaps", v2SitemapsRouter);
Expand Down
17 changes: 17 additions & 0 deletions src/models/v2/capes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MineSkinV2Request } from "../../routes/v2/types";
import { Response } from "express";
import { V2ResponseBody } from "../../typings/v2/V2ResponseBody";
import { Cape } from "@mineskin/database";
import { V2MiscResponseBody } from "../../typings/v2/V2MiscResponseBody";

export async function listKnownCapes(req: MineSkinV2Request, res: Response<V2ResponseBody>): Promise<V2MiscResponseBody> {
const capes = await Cape.find();
return {
success: true,
capes: capes.map(cape => ({
uuid: cape.uuid,
alias: cape.alias,
url: cape.url
}))
}
}
20 changes: 20 additions & 0 deletions src/routes/v2/capes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Response, Router } from "express";
import { v2Router } from "./router";
import expressAsyncHandler from "express-async-handler";
import { MineSkinV2Request } from "./types";
import { wildcardCorsWithCredentials } from "../../middleware/cors";
import { V2MiscResponseBody } from "../../typings/v2/V2MiscResponseBody";
import { listKnownCapes } from "../../models/v2/capes";
import { formatV2Response } from "../../middleware/response";

const router: Router = v2Router();
router.use(wildcardCorsWithCredentials);

// alias of /latest
router.get("/", expressAsyncHandler(async (req: MineSkinV2Request, res: Response<V2MiscResponseBody>) => {
const result = await listKnownCapes(req, res);
res.header('Cache-Control', 'public, max-age=3600');
res.json(formatV2Response(req, result));
}));

export const v2CapesRouter: Router = router;
5 changes: 3 additions & 2 deletions src/routes/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export { v2QueueRouter } from "./queue";
export { v2SkinsRouter } from "./skins";
export { v2GenerateRouter } from "./generate";
export { v2MeRouter } from "./me";
export {v2ImagesRouter} from "./images";
export {v2DelayRouter} from "./delay";
export { v2ImagesRouter } from "./images";
export { v2DelayRouter } from "./delay";
export { v2CapesRouter } from "./capes";
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,7 @@ __metadata:

"@mineskin/database@git+ssh://[email protected]/MineSkin/mineskin-database.git":
version: 1.0.0
resolution: "@mineskin/database@git+ssh://[email protected]/MineSkin/mineskin-database.git#commit=fc85d760854b9b2f10158ea5af20d5bccce368e2"
resolution: "@mineskin/database@git+ssh://[email protected]/MineSkin/mineskin-database.git#commit=ffa976360305023b1ae47dfd7bb3edab79e11d1a"
dependencies:
"@mineskin/types": "git+ssh://[email protected]/MineSkin/mineskin-types.git"
"@sentry/cli": "npm:^2.32.2"
Expand All @@ -1461,13 +1461,13 @@ __metadata:
dotenv: "npm:^16.4.5"
mongoose: "npm:^8.5.3"
uuid: "npm:^10.0.0"
checksum: 10c0/4c7bec2bc4d60d13bcd70bb0f961226f3f14ba6b164ef39747a712cf9d545e54a92c735d2f735937200aaae47c6742b22fd52ff05dca7316aff8faffcf6e2ac1
checksum: 10c0/7e36b84a007e5d06e18400d3c985f24631ebcfd1581a54243686dd0a359ff4b26890c3ce95dee78c059689663694ece838e4977df6614bd625f50d1cebe88ef4
languageName: node
linkType: hard

"@mineskin/generator@git+ssh://[email protected]/MineSkin/mineskin-generator.git":
version: 0.0.0
resolution: "@mineskin/generator@git+ssh://[email protected]/MineSkin/mineskin-generator.git#commit=bf1f4d2d7387d8fc2b3631e8af16e8f22f2a7f42"
resolution: "@mineskin/generator@git+ssh://[email protected]/MineSkin/mineskin-generator.git#commit=337b0fd42923967a86625f8fc398bc21179df252"
dependencies:
"@hoangducnhuan/redlock": "npm:^6.0.0"
"@inventivetalent/imghash": "npm:^1.1.1"
Expand Down Expand Up @@ -1505,7 +1505,7 @@ __metadata:
winston: "npm:^3.14.2"
winston-daily-rotate-file: "npm:^5.0.0"
winston-transport-sentry-node: "npm:^3.0.0"
checksum: 10c0/9b09de38e1689ce2a42c922265836121b59dc40bf8363ced0608410c4a63e1841dffee1bdb47c1c22ce485b7c731c80ceba8a79e626cb5f3524074f7540848ab
checksum: 10c0/78f0a155e3eca36bec57d873cb3422eba53d996188687950d1964f98dd9feb18f4e9e139efcf15efffebf0da622c8baa95697c18a9745eae4b5dae3b77a5b909
languageName: node
linkType: hard

Expand Down Expand Up @@ -1539,8 +1539,8 @@ __metadata:

"@mineskin/types@git+ssh://[email protected]/MineSkin/mineskin-types.git":
version: 1.0.1
resolution: "@mineskin/types@git+ssh://[email protected]/MineSkin/mineskin-types.git#commit=e9694cc68e23d4dbfe74826bf81729713d7d4532"
checksum: 10c0/dc598ec2fb7ed37535c90aeb7f2065f2475f895608e759b0c0029dc12681827e11b0571ff1df351e8944c1d20039ee1855f26172cac3af24ce4fb9798f6ccc99
resolution: "@mineskin/types@git+ssh://[email protected]/MineSkin/mineskin-types.git#commit=26c68c4a2a6338a2e2696485e425159de3ab396e"
checksum: 10c0/1f7e22db2049a58d050146f931d415b0088e7b1bdf3a3c4d22d4963dad42a907f5aadb70cf969c0b68c5c9c52fdd74dbeef919b5c42456404059185dca92a6f3
languageName: node
linkType: hard

Expand Down

0 comments on commit 2fe0b9d

Please sign in to comment.