@akomalabs/kemono
Version:
A production-grade TypeScript API wrapper for the Kemono/Coomer platforms
113 lines • 3.67 kB
JavaScript
import { AuthenticationError } from '../errors/api-error';
/**
* Favorites API endpoints
*/
export class FavoritesApi {
client;
constructor(client) {
this.client = client;
}
/**
* List favorite creators
* @throws {AuthenticationError} If session key is not provided
* @returns Array of favorite creators
*/
async listCreators() {
try {
return await this.client.get('/account/favorites', { params: { type: 'artist' } });
}
catch (error) {
if (error instanceof AuthenticationError) {
throw new AuthenticationError('Session key is required to view favorites');
}
throw error;
}
}
/**
* List favorite posts
* @throws {AuthenticationError} If session key is not provided
* @returns Array of favorite posts
*/
async listPosts() {
try {
return await this.client.get('/account/favorites', { params: { type: 'post' } });
}
catch (error) {
if (error instanceof AuthenticationError) {
throw new AuthenticationError('Session key is required to view favorites');
}
throw error;
}
}
/**
* Add a creator to favorites
* @param service Platform service
* @param creatorId Creator's ID
* @throws {AuthenticationError} If session key is not provided
*/
async addCreator(service, creatorId) {
try {
await this.client.post(`/favorites/creator/${service}/${creatorId}`);
}
catch (error) {
if (error instanceof AuthenticationError) {
throw new AuthenticationError('Session key is required to manage favorites');
}
throw error;
}
}
/**
* Remove a creator from favorites
* @param service Platform service
* @param creatorId Creator's ID
* @throws {AuthenticationError} If session key is not provided
*/
async removeCreator(service, creatorId) {
try {
await this.client.delete(`/favorites/creator/${service}/${creatorId}`);
}
catch (error) {
if (error instanceof AuthenticationError) {
throw new AuthenticationError('Session key is required to manage favorites');
}
throw error;
}
}
/**
* Add a post to favorites
* @param service Platform service
* @param creatorId Creator's ID
* @param postId Post ID
* @throws {AuthenticationError} If session key is not provided
*/
async addPost(service, creatorId, postId) {
try {
await this.client.post(`/favorites/post/${service}/${creatorId}/${postId}`);
}
catch (error) {
if (error instanceof AuthenticationError) {
throw new AuthenticationError('Session key is required to manage favorites');
}
throw error;
}
}
/**
* Remove a post from favorites
* @param service Platform service
* @param creatorId Creator's ID
* @param postId Post ID
* @throws {AuthenticationError} If session key is not provided
*/
async removePost(service, creatorId, postId) {
try {
await this.client.delete(`/favorites/post/${service}/${creatorId}/${postId}`);
}
catch (error) {
if (error instanceof AuthenticationError) {
throw new AuthenticationError('Session key is required to manage favorites');
}
throw error;
}
}
}
//# sourceMappingURL=favorites.js.map