Skip to content

Commit

Permalink
Toggle comments
Browse files Browse the repository at this point in the history
  • Loading branch information
webdev03 committed Oct 5, 2023
1 parent 0b665d8 commit e2d1ec5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/classes/Profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,19 @@ class Profile {
}
return comments;
}

async toggleComments() {
const request = await fetch(`https://scratch.mit.edu/site-api/comments/user/${this.user}/toggle-comments/`, {
method: "POST",
headers: {
"X-CSRFToken": this.session.csrfToken,
Cookie: this.session.cookieSet,
Origin: "https://scratch.mit.edu",
Referer: `https://scratch.mit.edu/users/${this.user}/`
}
});
if(!request.ok) throw Error(`Request failed with status ${request.status}`);
}
}

export { Profile as default, UserAPIResponse };
16 changes: 16 additions & 0 deletions src/classes/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,22 @@ class Project {
return Number((await request.json())["id"]);
}

async setCommentsAllowed(state: boolean) {
const request = await fetch(`https://api.scratch.mit.edu/projects/${this.id}`, {
method: "PUT",
body: JSON.stringify({
comments_allowed: state
}),
headers: {
"X-Token": this.session.sessionJSON.user.token,
"Content-Type": "application/json",
Origin: "https://scratch.mit.edu",
Referer: "https://scratch.mit.edu/"
}
});
if(!request.ok) throw Error(`Request failed with status ${request.status}`)
}

/**
* Sets the title of the project (requires ownership of the project).
* @param value The value you want to set the title to.
Expand Down
17 changes: 17 additions & 0 deletions src/classes/Studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,23 @@ class Studio {
return Number((await request.json())["id"]);
}

/**
* Toggle comments on or off
*/
async toggleComments() {
const request = await fetch(`https://scratch.mit.edu/site-api/comments/gallery/${this.id}/toggle-comments/`, {
method: "POST",
headers: {
"User-Agent": UserAgent,
"X-CSRFToken": this.session.csrfToken,
Cookie: this.session.cookieSet,
Origin: "https://scratch.mit.edu",
Referer: `https://scratch.mit.edu/studios/${this.id}/comments`
}
});
if(!request.ok) throw Error(`Request failed with status ${request.status}`);
}

/**
* Gets the curators in a studio.
* @param limit The limit of curators to return.
Expand Down

0 comments on commit e2d1ec5

Please sign in to comment.