Initial commit
This commit is contained in:
7
src/routes/accounts/root.ts
Normal file
7
src/routes/accounts/root.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { createHonoRoute, routeImporter } from "../../util/import.ts";
|
||||
|
||||
export const route = createHonoRoute('/accounts');
|
||||
|
||||
await routeImporter(route.app, 'src/routes/accounts/', [
|
||||
'routes'
|
||||
]);
|
||||
38
src/routes/accounts/routes/account.ts
Normal file
38
src/routes/accounts/routes/account.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { createHonoRoute } from "../../../util/import.ts";
|
||||
import { authenticate } from "../../../util/api.ts";
|
||||
import Server from "../../../server/server.ts";
|
||||
import z from "zod";
|
||||
import { typedZValidator } from "../../../util/validators.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)) ])
|
||||
});
|
||||
route.app.get('/bulk', typedZValidator('query', bulkAccountQuerySchema), async c => {
|
||||
const { id } = c.req.valid('query');
|
||||
let ids: number[] = [];
|
||||
|
||||
if (!id) return c.json([]);
|
||||
if (typeof id == 'number') ids = [id];
|
||||
else ids = id.filter(val => typeof val == 'number');
|
||||
|
||||
return c.json((await Promise.all(ids.map(id => Server.Profiles.get(id))))
|
||||
.filter(val => val !== null)
|
||||
.map(prof => prof.export())
|
||||
.filter(val => val !== null)
|
||||
);
|
||||
});
|
||||
|
||||
route.app.use('*', authenticate);
|
||||
|
||||
route.app.get('/me', c => {
|
||||
const profile = c.get('profile');
|
||||
|
||||
return c.json(profile.selfExport());
|
||||
});
|
||||
Reference in New Issue
Block a user