Skip to content

Commit

Permalink
add acceptInvite
Browse files Browse the repository at this point in the history
  • Loading branch information
webdev03 committed Oct 24, 2023
1 parent 344c2e2 commit 283fe4c
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/classes/Studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;
}
};
}

/**
Expand Down

0 comments on commit 283fe4c

Please sign in to comment.