This commit is contained in:
2025-08-22 20:19:15 -04:00
parent f19552929e
commit 391bf3d1f8
58 changed files with 535 additions and 24 deletions

View File

@@ -0,0 +1,3 @@
import { createHonoRoute } from "../../../util/import.ts";
export const route = createHonoRoute("/messages");

View File

@@ -0,0 +1,29 @@
import z from "zod";
import { createHonoRoute } from "../../../util/import.ts";
import { typedZValidator } from "../../../util/validators.ts";
import { authenticate } from "../../../util/api.ts";
import Server from "../../../server/server.ts";
export const route = createHonoRoute("/playerReputation");
const getRepIdParamSchema = z.object({
id: z.coerce.number().min(0).max(2_147_483_647)
})
route.app.get('/v1/:id', typedZValidator('param', getRepIdParamSchema), authenticate, async c => {
const { id } = c.req.valid('param');
const prof = await Server.Profiles.get(id);
if (!prof) return c.status(404);
else return c.json({
AccountId: id,
Noteriety: 0.0,
CheerGeneral: 0,
CheerHelpful: 0,
CheerGreatHost: 0,
CheerSportsman: 0,
CheerCreative: 0,
CheerCredit: 0,
SubscriberCount: 0,
SubscribedCount: 0,
});
});

74
src/routes/img/base.ts Normal file
View File

@@ -0,0 +1,74 @@
import z from "zod";
import Server from "../../server/server.ts";
import { createHonoRoute } from "../../util/import.ts";
import { typedZValidator } from "../../util/validators.ts";
import { FileType, File } from "../../server/content/base.ts";
import sharp from "sharp";
import path from "node:path";
import { RootPath } from "../../util/path.ts";
import Logging from "@proxnet/undead-logging";
export const route = createHonoRoute('/img');
async function convertImage(query: {cropSquare?: boolean | undefined;width?: number | undefined;height?: number | undefined;}, data: Uint8Array<ArrayBufferLike>): Promise<Uint8Array<ArrayBufferLike>> {
const image = sharp(data);
const rootMetadata = await image.metadata();
const rootWidth = rootMetadata.width;
const rootHeight = rootMetadata.height;
const squareSize = Math.min(rootWidth, rootHeight);
if (query.cropSquare) image.resize(squareSize, squareSize);
const newImage = sharp(await image.png().toBuffer());
if (query.width && query.height)
newImage.resize(query.width, query.height);
else if (query.width)
newImage.resize(query.width);
else if (query.height)
newImage.resize(undefined, query.height);
return await newImage.png().toBuffer();
}
const imgNameParamSchema = z.object({
imgName: z.string().min(4).includes('.')
});
const imgQuerySchema = z.object({
cropSquare: z.coerce.boolean().optional(),
width: z.coerce.number().max(3840).optional(),
height: z.coerce.number().max(2160).optional(),
});
route.app.get('/:imgName',
typedZValidator('param', imgNameParamSchema),
typedZValidator('query', imgQuerySchema),
async c => {
const { imgName } = c.req.valid('param');
const query = c.req.valid('query');
const file: File | null = await Server.Content.getFile(`img/${imgName}`);
let raw: Uint8Array<ArrayBuffer> | null = null;
if (!file) {
try {
raw = await Deno.readFile(path.join(RootPath, "res/baseimg/", imgName));
} catch {
raw = null;
}
}
if (!raw && file && file.Meta.Type !== FileType.Image) return c.status(404);
try {
let result: Uint8Array<ArrayBufferLike> | null = null;
if (file) result = await convertImage(query, file.Data);
else if (raw) result = await convertImage(query, raw);
if (result) return c.body(result, 200, { "Cache-Control": "public, no-transform, max-age=1800", "Content-Type": "image/png" });
else return c.status(404);
} catch (err) {
new Logging("ImageRoute").w(`Sharp error: ${err}`);
return c.status(500);
}
}
);