Skip to content

Commit

Permalink
Studio patchwork and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
webdev03 committed Oct 2, 2023
1 parent 8cfd429 commit 02d715e
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 57 deletions.
20 changes: 11 additions & 9 deletions src/Consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ interface SessionJSON {
educator: boolean;
educator_invitee: boolean;
student: boolean;
mute_status: {
offenses: {
expiresAt: number;
messageType: string | null;
}[];
showWarning: boolean;
muteExpiresAt: number;
currentMessageType: string | null;
} | {};
mute_status:
| {
offenses: {
expiresAt: number;
messageType: string | null;
}[];
showWarning: boolean;
muteExpiresAt: number;
currentMessageType: string | null;
}
| {};
};
flags: {
must_reset_password: boolean;
Expand Down
103 changes: 57 additions & 46 deletions src/classes/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,17 +251,20 @@ class Project {
}

async setThumbnail(buffer: Buffer) {
const request = await fetch(`https://scratch.mit.edu/internalapi/project/thumbnail/${this.id}/set/`, {
method: "POST",
body: buffer,
headers: {
"X-CSRFToken": this.session.csrfToken,
"X-Token": this.session.sessionJSON.user.token,
"Cookie": this.session.cookieSet,
"User-Agent": UserAgent
const request = await fetch(
`https://scratch.mit.edu/internalapi/project/thumbnail/${this.id}/set/`,
{
method: "POST",
body: buffer,
headers: {
"X-CSRFToken": this.session.csrfToken,
"X-Token": this.session.sessionJSON.user.token,
Cookie: this.session.cookieSet,
"User-Agent": UserAgent
}
}
});
if(!request.ok) throw Error("Request not ok");
);
if (!request.ok) throw Error("Request not ok");
return;
}

Expand Down Expand Up @@ -345,25 +348,29 @@ class Project {
* @param loving Either true or false
*/
async setLoving(loving: boolean) {
const request = await fetch(`https://api.scratch.mit.edu/proxy/projects/${this.id}/loves/user/${this.session.sessionJSON.user.username}`, {
method: loving ? "POST" : "DELETE",
headers: {
"X-CSRFToken": this.session.csrfToken,
"X-Token": this.session.sessionJSON.user.token,
"x-requested-with": "XMLHttpRequest",
Cookie: this.session.cookieSet,
Referer: `https://scratch.mit.edu/projects/${this.id}/`,
"User-Agent": UserAgent,
Accept: "*/*",
"Content-Length": "0",
Origin: "https://scratch.mit.edu",
Host: "api.scratch.mit.edu",
"Cache-Control": "max-age=0, no-cache",
Pragma: "no-cache",
"Accept-Encoding": "gzip, deflate, br"
const request = await fetch(
`https://api.scratch.mit.edu/proxy/projects/${this.id}/loves/user/${this.session.sessionJSON.user.username}`,
{
method: loving ? "POST" : "DELETE",
headers: {
"X-CSRFToken": this.session.csrfToken,
"X-Token": this.session.sessionJSON.user.token,
"x-requested-with": "XMLHttpRequest",
Cookie: this.session.cookieSet,
Referer: `https://scratch.mit.edu/projects/${this.id}/`,
"User-Agent": UserAgent,
Accept: "*/*",
"Content-Length": "0",
Origin: "https://scratch.mit.edu",
Host: "api.scratch.mit.edu",
"Cache-Control": "max-age=0, no-cache",
Pragma: "no-cache",
"Accept-Encoding": "gzip, deflate, br"
}
}
});
if(!request.ok) throw Error(`Request failed with status ${request.status}`);
);
if (!request.ok)
throw Error(`Request failed with status ${request.status}`);
return;
}

Expand All @@ -373,25 +380,29 @@ class Project {
* @param favoriting Either true or false
*/
async setFavoriting(favoriting: boolean) {
const request = await fetch(`https://api.scratch.mit.edu/proxy/projects/${this.id}/favorites/user/${this.session.sessionJSON.user.username}`, {
method: favoriting ? "POST" : "DELETE",
headers: {
"X-CSRFToken": this.session.csrfToken,
"X-Token": this.session.sessionJSON.user.token,
"x-requested-with": "XMLHttpRequest",
Cookie: this.session.cookieSet,
Referer: `https://scratch.mit.edu/projects/${this.id}/`,
"User-Agent": UserAgent,
Accept: "*/*",
"Content-Length": "0",
Origin: "https://scratch.mit.edu",
Host: "api.scratch.mit.edu",
"Cache-Control": "max-age=0, no-cache",
Pragma: "no-cache",
"Accept-Encoding": "gzip, deflate, br"
const request = await fetch(
`https://api.scratch.mit.edu/proxy/projects/${this.id}/favorites/user/${this.session.sessionJSON.user.username}`,
{
method: favoriting ? "POST" : "DELETE",
headers: {
"X-CSRFToken": this.session.csrfToken,
"X-Token": this.session.sessionJSON.user.token,
"x-requested-with": "XMLHttpRequest",
Cookie: this.session.cookieSet,
Referer: `https://scratch.mit.edu/projects/${this.id}/`,
"User-Agent": UserAgent,
Accept: "*/*",
"Content-Length": "0",
Origin: "https://scratch.mit.edu",
Host: "api.scratch.mit.edu",
"Cache-Control": "max-age=0, no-cache",
Pragma: "no-cache",
"Accept-Encoding": "gzip, deflate, br"
}
}
});
if(!request.ok) throw Error(`Request failed with status ${request.status}`);
);
if (!request.ok)
throw Error(`Request failed with status ${request.status}`);
return;
}

Expand Down
8 changes: 6 additions & 2 deletions src/classes/Studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ class Studio {
headers: {
"User-Agent": UserAgent,
"X-CSRFToken": this.session.csrfToken,
Cookie: this.session.cookieSet
Cookie: this.session.cookieSet,
Origin: "https://scratch.mit.edu",
Referer: `https://scratch.mit.edu/studios/${this.id}/curators`
}
}
);
Expand All @@ -145,7 +147,9 @@ class Studio {
headers: {
"User-Agent": UserAgent,
"X-CSRFToken": this.session.csrfToken,
Cookie: this.session.cookieSet
Cookie: this.session.cookieSet,
Origin: "https://scratch.mit.edu",
Referer: `https://scratch.mit.edu/studios/${this.id}/curators`
}
}
);
Expand Down

0 comments on commit 02d715e

Please sign in to comment.