34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import SessionManager from '../session/SessionManager';
|
|
import { Comment } from '../models/Comment';
|
|
import FormData from 'form-data';
|
|
|
|
export class CommentPoster {
|
|
|
|
/**
|
|
* Posts a comment as a reply to a given rdrama comment.
|
|
*
|
|
* @param parentId The ID of the parent comment to reply to. Expected format: 'c_{id}'.
|
|
* @param body The body of the comment to post.
|
|
* @returns A promise resolving to the Axios response.
|
|
*/
|
|
public static async postComment(parentId: string, body: string): Promise<Comment> {
|
|
const sessionManager = SessionManager.getInstance();
|
|
const formData = new FormData();
|
|
formData.append('parent_fullname', parentId);
|
|
formData.append('body', body);
|
|
|
|
try {
|
|
const response = await sessionManager.axiosInstance.post('/comment', formData, {
|
|
headers: {
|
|
'Content-Type': 'multipart/form-data'
|
|
}
|
|
});
|
|
console.log(`Comment posted successfully to ${parentId}`);
|
|
return response.data;
|
|
} catch (error) {
|
|
console.error(`Failed to post comment to ${parentId}:`, error);
|
|
throw error; // Rethrow for handling elsewhere
|
|
}
|
|
}
|
|
}
|