mirror of
https://github.com/DrizzleTime/Foxel.git
synced 2026-06-27 18:21:53 +08:00
feat: Add plugin center functionality
This commit is contained in:
52
web/src/api/pluginCenter.ts
Normal file
52
web/src/api/pluginCenter.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
export interface RepoItem {
|
||||
key: string;
|
||||
name: string;
|
||||
version: string;
|
||||
author?: string;
|
||||
description?: string;
|
||||
website?: string;
|
||||
github?: string;
|
||||
icon?: string;
|
||||
supportedExts?: string[];
|
||||
createdAt?: number;
|
||||
downloads?: number;
|
||||
directUrl: string;
|
||||
}
|
||||
|
||||
export interface RepoListResponse {
|
||||
items: RepoItem[];
|
||||
total: number;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
}
|
||||
|
||||
export interface RepoQueryParams {
|
||||
query?: string;
|
||||
author?: string;
|
||||
sort?: 'downloads' | 'createdAt';
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
}
|
||||
|
||||
const CENTER_BASE = 'https://center.foxel.cc';
|
||||
|
||||
export function buildCenterUrl(path: string) {
|
||||
return new URL(path, CENTER_BASE).href;
|
||||
}
|
||||
|
||||
export async function fetchRepoList(params: RepoQueryParams = {}): Promise<RepoListResponse> {
|
||||
const query = new URLSearchParams();
|
||||
if (params.query) query.set('query', params.query);
|
||||
if (params.author) query.set('author', params.author);
|
||||
if (params.sort) query.set('sort', params.sort);
|
||||
query.set('page', String(params.page ?? 1));
|
||||
query.set('pageSize', String(params.pageSize ?? 12));
|
||||
|
||||
const url = `${CENTER_BASE}/api/repo?${query.toString()}`;
|
||||
const resp = await fetch(url);
|
||||
if (!resp.ok) {
|
||||
throw new Error(`Repo fetch failed: ${resp.status}`);
|
||||
}
|
||||
return await resp.json();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user