mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-26 20:19:50 +01:00
feat: api
This commit is contained in:
1 parent
2dc4f12246
commit
7e11c1e5ce
26 files changed
+149
-866
No files matched your search
@@ -1,29 +1,28 @@
|
||||
import { ProfileAvatarComponent } from '@protos/blitz_static_profile_avatar_component';
|
||||
import type { APIRoute, GetStaticPaths, GetStaticPathsItem } from 'astro';
|
||||
import { socketMetadata } from 'packages/website-ue/src/core/blitz/metadata.socket';
|
||||
import type { BlitzKitAvatar } from '@protos/blitzkit';
|
||||
import type { APIRoute, GetStaticPaths } from 'astro';
|
||||
import { api } from 'packages/website-ue/src/core/blitzkit/api';
|
||||
|
||||
export const getStaticPaths: GetStaticPaths = async () => {
|
||||
const paths: GetStaticPathsItem[] = [];
|
||||
|
||||
for (const item in socketMetadata.items) {
|
||||
if (!item.startsWith('ProfileAvatarEntity.')) continue;
|
||||
|
||||
const id = await socketMetadata
|
||||
.get(item)
|
||||
.then((item) => item.undiscriminatedId());
|
||||
|
||||
paths.push({ params: { id } });
|
||||
}
|
||||
|
||||
return paths;
|
||||
const { avatars } = await api.avatars();
|
||||
return avatars.map((avatar) => ({
|
||||
params: { id: avatar.id },
|
||||
props: { avatar },
|
||||
}));
|
||||
};
|
||||
|
||||
export const GET: APIRoute<{}, { id: string }> = async ({ params }) => {
|
||||
const item = await socketMetadata.get(`ProfileAvatarEntity.${params.id}`);
|
||||
export const GET: APIRoute<
|
||||
{ avatar: BlitzKitAvatar },
|
||||
{ id: string }
|
||||
> = async ({ params }) => {
|
||||
const item = api.metadata.get(`ProfileAvatarEntity.${params.id}`);
|
||||
const avatar = item.get(ProfileAvatarComponent, 'profileAvatarComponent');
|
||||
|
||||
try {
|
||||
return await fetch(avatar.avatar);
|
||||
const response = await fetch(avatar.avatar);
|
||||
const buffer = await response.arrayBuffer();
|
||||
|
||||
return new Response(buffer, { headers: response.headers });
|
||||
} catch {
|
||||
return new Response(null, { status: 404 });
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { BlitzKitAvatars } from '@protos/blitzkit';
|
||||
import type { APIRoute } from 'astro';
|
||||
import { api } from 'packages/website-ue/src/core/blitzkit/api';
|
||||
|
||||
export const GET: APIRoute = async () => {
|
||||
return new Response(BlitzKitAvatars.encode(await api.avatars()).finish());
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
import type { APIRoute, GetStaticPaths, GetStaticPathsItem } from 'astro';
|
||||
import { socketMetadata } from 'packages/website-ue/src/core/blitz/metadata.socket';
|
||||
|
||||
export const getStaticPaths: GetStaticPaths = () => {
|
||||
const paths: GetStaticPathsItem[] = [];
|
||||
|
||||
for (const item in socketMetadata.items) {
|
||||
paths.push({ params: { item } });
|
||||
}
|
||||
|
||||
return paths;
|
||||
};
|
||||
|
||||
export const GET: APIRoute<{}, { item: string }> = async ({ params }) => {
|
||||
return new Response(
|
||||
await socketMetadata.get(params.item).then((item) => item.encode()),
|
||||
{ headers: { 'Content-Type': 'application/octet-stream' } },
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user