mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +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 "@radix-ui/colors/amber-dark.css";
|
||||||
import {
|
|
||||||
createProgram,
|
|
||||||
displayPartsToString,
|
|
||||||
forEachChild,
|
|
||||||
isFunctionDeclaration,
|
|
||||||
} from "typescript";
|
|
||||||
import BaseLayout from "../../../layouts/BaseLayout.astro";
|
import BaseLayout from "../../../layouts/BaseLayout.astro";
|
||||||
|
|
||||||
export { getStaticPaths } from "../index.astro";
|
export { getStaticPaths } from "../index.astro";
|
||||||
|
|
||||||
const root = `/src/pages/api`;
|
const root = `/src/pages/api`;
|
||||||
const globbed = import.meta.glob("/src/pages/api/**/*.ts", {
|
const globbed = import.meta.glob("/src/pages/api/**/*", {
|
||||||
eager: true,
|
eager: true,
|
||||||
query: "?raw",
|
query: "?raw",
|
||||||
|
import: "default",
|
||||||
});
|
});
|
||||||
const paths: {
|
const paths: {
|
||||||
path: string;
|
path: string;
|
||||||
documentation: 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) {
|
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 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 });
|
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 { api } from "../../../core/api/dynamic";
|
||||||
import { imageProxy } from "../../../core/api/imageProxy";
|
import { imageProxy } from "../../../core/api/imageProxy";
|
||||||
|
|
||||||
export const getStaticPaths = (async () => {
|
export { getStaticPaths } from "./[id].json";
|
||||||
const { avatars } = await api.avatars();
|
|
||||||
|
|
||||||
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 }>) {
|
export async function GET({ params }: APIContext<never, { id: string }>) {
|
||||||
const avatar = await api.avatar(params.id);
|
const avatar = await api.avatar(params.id);
|
||||||
return await imageProxy(avatar.profile_avatar!.avatar);
|
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 { api } from "../../../core/api/dynamic";
|
||||||
import { imageProxy } from "../../../core/api/imageProxy";
|
import { imageProxy } from "../../../core/api/imageProxy";
|
||||||
|
|
||||||
export const getStaticPaths = (async () => {
|
export { getStaticPaths } from "./[id].json";
|
||||||
const { backgrounds } = await api.backgrounds();
|
|
||||||
|
|
||||||
return backgrounds.map((background) => ({
|
|
||||||
params: { id: background.name },
|
|
||||||
}));
|
|
||||||
}) satisfies GetStaticPaths;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One day I will write documentation for this
|
* 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