galvanic corrosion rewrite

commit this before something goes horribly wrong
This commit is contained in:
2025-08-12 21:04:52 -04:00
parent 941c8400c0
commit f19552929e
40 changed files with 28149 additions and 73212 deletions

View File

@@ -1,18 +1,15 @@
import { createHonoRoute } from "../../../util/import.ts";
import { authenticate } from "../../../util/api.ts";
import { authenticate, galvanicError, GalvanicErrors, RateLimiter, recNetError } from "../../../util/api.ts";
import Server from "../../../server/server.ts";
import z from "zod";
import { typedZValidator } from "../../../util/validators.ts";
import { transformStringToEnum, typedZValidator } from "../../../util/validators.ts";
import { PlatformType } from "../../../server/platforms/types.ts";
import Steam from "../../../util/steam/steam.ts";
export const route = createHonoRoute('/account');
const transformNumber = (arg: string, ctx: z.RefinementCtx<string>) => {
const int = parseInt(arg);
if (isNaN(int) || !Number.isSafeInteger(int)) ctx.addIssue('Number is not valid');
else return int;
}
const bulkAccountQuerySchema = z.object({
id: z.union([ z.string().transform(transformNumber), z.array(z.string().transform(transformNumber)) ])
id: z.union([ z.coerce.number(), z.array(z.coerce.number()) ])
});
route.app.get('/bulk', typedZValidator('query', bulkAccountQuerySchema), async c => {
const { id } = c.req.valid('query');
@@ -29,6 +26,51 @@ route.app.get('/bulk', typedZValidator('query', bulkAccountQuerySchema), async c
);
});
const postCreateRateLimiter = new RateLimiter(60, 3);
const createAccountBodySchema = z.object({
platform: z.string().transform(transformStringToEnum<PlatformType>(PlatformType)),
platformId: z.string().min(14).max(20),
deviceId: z.string().min(32).max(64)
});
route.app.post('/create', postCreateRateLimiter.middle(), typedZValidator('form', createAccountBodySchema), async c => {
const form = c.req.valid('form');
if (typeof form.platform == 'undefined')
return c.json(galvanicError(GalvanicErrors.jex));
else if (form.platform == PlatformType.Steam) {
const steam = await Steam.GetPlayerSummaries([form.platformId]);
if (steam.length == 0)
return c.json(galvanicError(GalvanicErrors.sploot));
const cachedlogins = await Server.Platforms.getCachedLogins(form.platform, form.platformId, true);
if (cachedlogins.length == 0) {
const profile = await Server.Profiles.create(form.platform, form.platformId, steam[0].realname ?? steam[0].personaname);
if (!profile) return c.json(galvanicError(GalvanicErrors.sploot));
Server.Content.steamAvatarDownloadForProfile(profile, steam[0].avatarfull);
return c.json({
success: true,
value: profile.export()
});
} else {
const profile = await Server.Profiles.create(form.platform, form.platformId);
if (!profile) return c.json(galvanicError(GalvanicErrors.sploot));
return c.json({
success: true,
value: profile.export()
});
}
} else return c.json(recNetError("Not a Steam user"));
});
route.app.use(authenticate);
route.app.get('/me', c => {