From 283fe4c1b0dd0fc67fa5704ae1799cb69d923650 Mon Sep 17 00:00:00 2001 From: webdev03 <75148774+webdev03@users.noreply.github.com> Date: Tue, 24 Oct 2023 20:37:58 +1300 Subject: [PATCH] add acceptInvite --- src/classes/Studio.ts | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/classes/Studio.ts b/src/classes/Studio.ts index 3fdcea3..920d6ad 100644 --- a/src/classes/Studio.ts +++ b/src/classes/Studio.ts @@ -214,6 +214,30 @@ class Studio { } } + /** + * Accepts an invite to a studio + * You can check if you have an invite with the getUserData function + */ + async acceptInvite() { + if (!this.session) throw Error("You need to be logged in"); + const req = await fetch( + `https://scratch.mit.edu/site-api/users/curators-in/${this.id}/add/?usernames=${this.session.sessionJSON.user.username}`, + { + method: "PUT", + 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}/curators` + } + } + ); + if(!req.ok) { + throw Error(`Could not join studio -- did you get an invite? ${req.statusText}`); + }; + } + /** * Check if you are a manager, a curator, invited, or following the studio */ @@ -230,13 +254,13 @@ class Studio { ); if (!req.ok) { throw new Error(`Could not get data - ${req.statusText}`); - }; - return await req.json() as { + } + return (await req.json()) as { manager: boolean; curator: boolean; invited: boolean; following: boolean; - } + }; } /**