diff --git a/src/Consts.ts b/src/Consts.ts index cccd31e..2eb0adf 100644 --- a/src/Consts.ts +++ b/src/Consts.ts @@ -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; diff --git a/src/classes/Project.ts b/src/classes/Project.ts index ca0b1ec..d241ca0 100644 --- a/src/classes/Project.ts +++ b/src/classes/Project.ts @@ -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; } @@ -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; } @@ -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; } diff --git a/src/classes/Studio.ts b/src/classes/Studio.ts index 975cbf3..f2647cd 100644 --- a/src/classes/Studio.ts +++ b/src/classes/Studio.ts @@ -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` } } ); @@ -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` } } );