mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: profile and backgroud apis
This commit is contained in:
1 parent
c98271f783
commit
5a1a0c59f1
9 files changed
+92
-44
No files matched your search
@@ -1,45 +1,52 @@
|
||||
---
|
||||
import "@radix-ui/colors/amber-dark.css";
|
||||
import {
|
||||
createProgram,
|
||||
displayPartsToString,
|
||||
forEachChild,
|
||||
isFunctionDeclaration,
|
||||
} from "typescript";
|
||||
import BaseLayout from "../../../layouts/BaseLayout.astro";
|
||||
|
||||
export { getStaticPaths } from "../index.astro";
|
||||
|
||||
const root = `/src/pages/api`;
|
||||
const globbed = import.meta.glob("/src/pages/api/**/*.ts", {
|
||||
const globbed = import.meta.glob("/src/pages/api/**/*", {
|
||||
eager: true,
|
||||
query: "?raw",
|
||||
import: "default",
|
||||
});
|
||||
const paths: {
|
||||
path: string;
|
||||
documentation: string;
|
||||
}[] = [];
|
||||
|
||||
// for (const fullPath in globbed) {
|
||||
// const relativePath = `.${fullPath}`;
|
||||
// const path = fullPath.slice(root.length + 1, -3);
|
||||
// const program = createProgram([relativePath], {});
|
||||
// const source = program.getSourceFile(relativePath);
|
||||
// if (!source) throw new Error(`Could not find source for ${fullPath}`);
|
||||
|
||||
// const checker = program.getTypeChecker();
|
||||
|
||||
// const getter = forEachChild(source, (node) => {
|
||||
// if (!isFunctionDeclaration(node) || node.name?.text !== "GET") return;
|
||||
// return checker.getSymbolAtLocation(node.name);
|
||||
// });
|
||||
|
||||
// const documentationComment = getter?.getDocumentationComment(checker);
|
||||
// if (!documentationComment) continue;
|
||||
|
||||
// const documentation = displayPartsToString(documentationComment);
|
||||
// if (documentation.length === 0) continue;
|
||||
|
||||
// paths.push({ path, documentation });
|
||||
// }
|
||||
|
||||
for (const fullPath in globbed) {
|
||||
const relativePath = `.${fullPath}`;
|
||||
if (!fullPath.endsWith(".ts")) continue;
|
||||
|
||||
const mdPath = fullPath.replace(".ts", ".md");
|
||||
const documentation = globbed[mdPath] as string;
|
||||
|
||||
if (!documentation) continue;
|
||||
|
||||
const path = fullPath.slice(root.length + 1, -3);
|
||||
const program = createProgram([relativePath], {});
|
||||
const source = program.getSourceFile(relativePath);
|
||||
if (!source) throw new Error(`Could not find source for ${fullPath}`);
|
||||
|
||||
const checker = program.getTypeChecker();
|
||||
|
||||
const getter = forEachChild(source, (node) => {
|
||||
if (!isFunctionDeclaration(node) || node.name?.text !== "GET") return;
|
||||
return checker.getSymbolAtLocation(node.name);
|
||||
});
|
||||
|
||||
const documentationComment = getter?.getDocumentationComment(checker);
|
||||
if (!documentationComment) continue;
|
||||
|
||||
const documentation = displayPartsToString(documentationComment);
|
||||
if (documentation.length === 0) continue;
|
||||
|
||||
paths.push({ path, documentation });
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { APIContext, GetStaticPaths } from "astro";
|
||||
import { api } from "../../../core/api/dynamic";
|
||||
|
||||
export const getStaticPaths = (async () => {
|
||||
const { avatars } = await api.avatars();
|
||||
|
||||
return avatars.map((avatar) => ({
|
||||
params: { id: avatar.name },
|
||||
}));
|
||||
}) satisfies GetStaticPaths;
|
||||
|
||||
export async function GET({ params }: APIContext<never, { id: string }>) {
|
||||
const avatar = await api.avatar(params.id);
|
||||
return Response.json(avatar);
|
||||
}
|
||||
@@ -1,18 +1,9 @@
|
||||
import type { APIContext, GetStaticPaths } from "astro";
|
||||
import type { APIContext } from "astro";
|
||||
import { api } from "../../../core/api/dynamic";
|
||||
import { imageProxy } from "../../../core/api/imageProxy";
|
||||
|
||||
export const getStaticPaths = (async () => {
|
||||
const { avatars } = await api.avatars();
|
||||
export { getStaticPaths } from "./[id].json";
|
||||
|
||||
return avatars.map((avatar) => ({
|
||||
params: { id: avatar.name },
|
||||
}));
|
||||
}) satisfies GetStaticPaths;
|
||||
|
||||
/**
|
||||
* One day I will write documentation for this
|
||||
*/
|
||||
export async function GET({ params }: APIContext<never, { id: string }>) {
|
||||
const avatar = await api.avatar(params.id);
|
||||
return await imageProxy(avatar.profile_avatar!.avatar);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { api } from "../../../core/api/dynamic";
|
||||
|
||||
export async function GET() {
|
||||
const { avatars } = await api.avatars();
|
||||
return Response.json(avatars);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { api } from "../../../core/api/dynamic";
|
||||
|
||||
export async function GET() {
|
||||
const { avatars } = await api.avatars();
|
||||
const list = avatars.map((avatar) => avatar.name);
|
||||
return Response.json(list);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { APIContext, GetStaticPaths } from "astro";
|
||||
import { api } from "../../../core/api/dynamic";
|
||||
|
||||
export const getStaticPaths = (async () => {
|
||||
const { backgrounds } = await api.backgrounds();
|
||||
|
||||
return backgrounds.map((background) => ({
|
||||
params: { id: background.name },
|
||||
}));
|
||||
}) satisfies GetStaticPaths;
|
||||
|
||||
export async function GET({ params }: APIContext<never, { id: string }>) {
|
||||
const background = await api.background(params.id);
|
||||
return Response.json(background);
|
||||
}
|
||||
@@ -1,14 +1,8 @@
|
||||
import type { APIContext, GetStaticPaths } from "astro";
|
||||
import type { APIContext } from "astro";
|
||||
import { api } from "../../../core/api/dynamic";
|
||||
import { imageProxy } from "../../../core/api/imageProxy";
|
||||
|
||||
export const getStaticPaths = (async () => {
|
||||
const { backgrounds } = await api.backgrounds();
|
||||
|
||||
return backgrounds.map((background) => ({
|
||||
params: { id: background.name },
|
||||
}));
|
||||
}) satisfies GetStaticPaths;
|
||||
export { getStaticPaths } from "./[id].json";
|
||||
|
||||
/**
|
||||
* One day I will write documentation for this
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { api } from "../../../core/api/dynamic";
|
||||
|
||||
export async function GET() {
|
||||
const { backgrounds } = await api.backgrounds();
|
||||
return Response.json(backgrounds);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { api } from "../../../core/api/dynamic";
|
||||
|
||||
export async function GET() {
|
||||
const { backgrounds } = await api.backgrounds();
|
||||
const list = backgrounds.map((background) => background.name);
|
||||
return Response.json(list);
|
||||
}
|
||||
Reference in new issue
Block a user