forked from didirus/AstralRinth
* feat: abstract api-client DI into ui package * feat: cross platform page system * feat: tanstack as cross platform useAsyncData * feat: archon servers routes + labrinth billing routes * fix: dont use partial * feat: migrate server list page to tanstack + api-client + re-enabled broken features! * feat: migrate servers manage page to api-client before page system * feat: migrate manage page to page system * fix: type issues * fix: upgrade wrapper bugs * refactor: move state types into api-client * feat: disable financial stuff on app frontend * feat: finalize cross platform page system for now * fix: lint * fix: build issues * feat: remove papaparse * fix: lint * fix: interface error --------- Co-authored-by: Prospector <6166773+Prospector@users.noreply.github.com>
115 lines
2.7 KiB
TypeScript
115 lines
2.7 KiB
TypeScript
import { AbstractModule } from '../../../core/abstract-module'
|
|
import type { Labrinth } from '../types'
|
|
|
|
export class LabrinthProjectsV2Module extends AbstractModule {
|
|
public getModuleID(): string {
|
|
return 'labrinth_projects_v2'
|
|
}
|
|
|
|
/**
|
|
* Get a project by ID or slug
|
|
*
|
|
* @param id - Project ID or slug (e.g., 'sodium' or 'AANobbMI')
|
|
* @returns Promise resolving to the project data
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* const project = await client.labrinth.projects_v2.get('sodium')
|
|
* console.log(project.title) // "Sodium"
|
|
* ```
|
|
*/
|
|
public async get(id: string): Promise<Labrinth.Projects.v2.Project> {
|
|
return this.client.request<Labrinth.Projects.v2.Project>(`/project/${id}`, {
|
|
api: 'labrinth',
|
|
version: 2,
|
|
method: 'GET',
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Get multiple projects by IDs
|
|
*
|
|
* @param ids - Array of project IDs or slugs
|
|
* @returns Promise resolving to array of projects
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* const projects = await client.labrinth.projects_v2.getMultiple(['sodium', 'lithium', 'phosphor'])
|
|
* ```
|
|
*/
|
|
public async getMultiple(ids: string[]): Promise<Labrinth.Projects.v2.Project[]> {
|
|
return this.client.request<Labrinth.Projects.v2.Project[]>(`/projects`, {
|
|
api: 'labrinth',
|
|
version: 2,
|
|
method: 'GET',
|
|
params: { ids: JSON.stringify(ids) },
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Search projects
|
|
*
|
|
* @param params - Search parameters (query, facets, filters, etc.)
|
|
* @returns Promise resolving to search results
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* const results = await client.labrinth.projects_v2.search({
|
|
* query: 'optimization',
|
|
* facets: [['categories:optimization'], ['project_type:mod']],
|
|
* limit: 20
|
|
* })
|
|
* ```
|
|
*/
|
|
public async search(
|
|
params: Labrinth.Projects.v2.ProjectSearchParams,
|
|
): Promise<Labrinth.Projects.v2.SearchResult> {
|
|
return this.client.request<Labrinth.Projects.v2.SearchResult>(`/search`, {
|
|
api: 'labrinth',
|
|
version: 2,
|
|
method: 'GET',
|
|
params: params as Record<string, unknown>,
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Edit a project
|
|
*
|
|
* @param id - Project ID or slug
|
|
* @param data - Project update data
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* await client.labrinth.projects_v2.edit('sodium', {
|
|
* description: 'Updated description'
|
|
* })
|
|
* ```
|
|
*/
|
|
public async edit(id: string, data: Partial<Labrinth.Projects.v2.Project>): Promise<void> {
|
|
return this.client.request(`/project/${id}`, {
|
|
api: 'labrinth',
|
|
version: 2,
|
|
method: 'PATCH',
|
|
body: data,
|
|
})
|
|
}
|
|
|
|
/**
|
|
* Delete a project
|
|
*
|
|
* @param id - Project ID or slug
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* await client.labrinth.projects_v2.delete('my-project')
|
|
* ```
|
|
*/
|
|
public async delete(id: string): Promise<void> {
|
|
return this.client.request(`/project/${id}`, {
|
|
api: 'labrinth',
|
|
version: 2,
|
|
method: 'DELETE',
|
|
})
|
|
}
|
|
}
|