nhentai-tools
Version:
A toolset to interact with the doujin site nhentai.net
64 lines (63 loc) • 2.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.flag = exports.remove = exports.submit = exports.get = void 0;
const client_1 = require("./client");
const user_1 = require("./user");
/** Get all comments left under a gallery. Iterate over this at your own risk. */
const get = (id) => {
if (!id || !Number(id))
throw new Error('ID must be a number');
return client_1.client.get(`/api/gallery/${id}/comments`)
.then(({ data }) => {
if (data.error)
throw new Error(data.error);
return data;
});
};
exports.get = get;
/** Leave a comment under a gallery. */
const submit = (id, body) => {
if (!id || !Number(id))
throw new Error('ID must be a number');
if (!body)
throw new Error('Body is required');
if (!user_1.isLoggedIn)
throw new Error('User is not logged in');
return client_1.client.post(`/api/gallery/${id}/comments/submit`, { body })
.then(({ data }) => {
if (data.error)
throw new Error(data.error);
return data;
});
};
exports.submit = submit;
/** Remove a comment. */
const remove = (comment_id) => {
if (!comment_id || !Number(comment_id))
throw new Error('ID must be a number');
if (!user_1.isLoggedIn)
throw new Error('User is not logged in');
return client_1.client.post(`/api/comments/${comment_id}/delete`)
.then(({ data }) => {
if (data.error)
throw new Error(data.error);
return data;
});
};
exports.remove = remove;
/** Report/flag a comment. */
const flag = (comment_id, reason) => {
if (!comment_id || !Number(comment_id))
throw new Error('ID must be a number');
if (!reason)
throw new Error('Reason is required');
if (!user_1.isLoggedIn)
throw new Error('User is not logged in');
return client_1.client.post(`/api/comments/${comment_id}/flag`, { reason })
.then(({ data }) => {
if (data.error)
throw new Error(data.error);
return data;
});
};
exports.flag = flag;