Skip to content

Commit

Permalink
Profile commenting
Browse files Browse the repository at this point in the history
  • Loading branch information
webdev03 committed Oct 29, 2023
1 parent 6d39983 commit 4455fb5
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/classes/Profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,34 @@ class Profile {
throw Error(`Request failed with status ${request.status}`);
}

/**
* Comment on a profile
*/
async comment(content: string, parent_id?: number, commentee_id?: number) {
if (!this.session?.auth) throw Error("You need to be logged in");
const req = await fetch(
`https://scratch.mit.edu/site-api/comments/user/${this.user}/add/`,
{
method: "POST",
body: JSON.stringify({
content,
parent_id: parent_id || "",
commentee_id: commentee_id || ""
}),
headers: {
"X-CSRFToken": this.session.auth.csrfToken,
"X-Token": this.session.auth.token,
"x-requested-with": "XMLHttpRequest",
Cookie: this.session.auth.cookieSet,
Origin: "https://scratch.mit.edu",
Referer: `https://scratch.mit.edu/users/${this.user}`,
"User-Agent": UserAgent
}
}
);
if (!req.ok) throw new Error("Error adding comment.");
}

/**
* Deletes a comment.
* @param id The comment ID, for example 12345, *not* comment-12345.
Expand All @@ -133,7 +161,6 @@ class Profile {
"X-Token": this.session.auth.token,
"x-requested-with": "XMLHttpRequest",
Cookie: this.session.auth.cookieSet,

referer: `https://scratch.mit.edu/users/${this.user}`,
"User-Agent": UserAgent
}
Expand Down

0 comments on commit 4455fb5

Please sign in to comment.