Add collection api.

This commit is contained in:
2025-07-30 16:28:33 +08:00
parent f8c4509633
commit 17b40f2214
10 changed files with 740 additions and 37 deletions

View File

@@ -191,3 +191,11 @@ export interface Activity {
comment?: Comment;
file?: RFile;
}
export interface Collection {
id: number;
title: string;
article: string;
user: User;
images: Image[];
}

View File

@@ -19,6 +19,7 @@ import {
TagWithCount,
Activity,
CommentWithRef,
Collection,
} from "./models.ts";
class Network {
@@ -688,6 +689,99 @@ class Network {
}),
);
}
async createCollection(
title: string,
article: string,
): Promise<Response<Collection>> {
return this._callApi(() =>
axios.postForm(`${this.apiBaseUrl}/collection/create`, {
title,
article,
}),
);
}
async updateCollection(
id: number,
title: string,
article: string,
): Promise<Response<any>> {
return this._callApi(() =>
axios.postForm(`${this.apiBaseUrl}/collection/update`, {
id,
title,
article,
}),
);
}
async deleteCollection(id: number): Promise<Response<any>> {
return this._callApi(() =>
axios.postForm(`${this.apiBaseUrl}/collection/delete`, {
id,
}),
);
}
async getCollection(id: number): Promise<Response<Collection>> {
return this._callApi(() =>
axios.get(`${this.apiBaseUrl}/collection/${id}`),
);
}
async listUserCollections(page: number = 1): Promise<PageResponse<Collection>> {
return this._callApi(() =>
axios.get(`${this.apiBaseUrl}/collection/list`, {
params: { page },
}),
);
}
async listCollectionResources(
collectionId: number,
page: number = 1,
): Promise<PageResponse<Resource>> {
return this._callApi(() =>
axios.get(`${this.apiBaseUrl}/collection/${collectionId}/resources`, {
params: { page },
}),
);
}
async addResourceToCollection(
collectionId: number,
resourceId: number,
): Promise<Response<any>> {
return this._callApi(() =>
axios.postForm(`${this.apiBaseUrl}/collection/add_resource`, {
collection_id: collectionId,
resource_id: resourceId,
}),
);
}
async removeResourceFromCollection(
collectionId: number,
resourceId: number,
): Promise<Response<any>> {
return this._callApi(() =>
axios.postForm(`${this.apiBaseUrl}/collection/remove_resource`, {
collection_id: collectionId,
resource_id: resourceId,
}),
);
}
async searchUserCollections(
keyword: string,
): Promise<Response<Collection[]>> {
return this._callApi(() =>
axios.get(`${this.apiBaseUrl}/collection/search`, {
params: { keyword },
}),
);
}
}
export const network = new Network();