more fun optimizations
I think I removed like 5 KB or something?
This commit is contained in:
parent
128539d426
commit
f28bf996dc
2 changed files with 117 additions and 148 deletions
176
JS/BlueskyAPI.js
176
JS/BlueskyAPI.js
|
@ -1,23 +1,22 @@
|
|||
import * as Variables from "./Variables.js";
|
||||
|
||||
let Token = localStorage.getItem(Variables.BlueskyAccessToken);
|
||||
if (Token == null) {
|
||||
console.error("No Bluesky access token!");
|
||||
}
|
||||
|
||||
// Getters
|
||||
// This gets the timeline. The cursor is a time in Z form.
|
||||
export async function GetTimeline(Cursor) {
|
||||
if (localStorage.getItem(Variables.BlueskyAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
let DPoP;
|
||||
let request;
|
||||
if (Cursor == "") {
|
||||
DPoP = await ClientDPoPPDS("GET", localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/app.bsky.feed.getTimeline");
|
||||
request = fetch(localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/app.bsky.feed.getTimeline", {method: "GET", headers: {"Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}});
|
||||
} else {
|
||||
DPoP = await ClientDPoPPDS("GET", localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/app.bsky.feed.getTimeline?cursor=" + Cursor);
|
||||
request = fetch(localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/app.bsky.feed.getTimeline?cursor=" + Cursor, {method: "GET", headers: {"Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}});
|
||||
let FetchThing = localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/app.bsky.feed.getTimeline";
|
||||
if (Cursor != "") {
|
||||
FetchThing += "?cursor=" + Cursor;
|
||||
}
|
||||
let DPoP = await ClientDPoPPDS("GET", FetchThing);
|
||||
let request = fetch(FetchThing, {method: "GET", headers: {"Authorization": "DPoP " + Token, "DPoP": DPoP}});;
|
||||
let body = await request.then((response) => response.json());
|
||||
let status = await request.then((response) => response.status);
|
||||
let header = await request.then((response) => response.headers.get("dpop-nonce"));
|
||||
|
@ -30,20 +29,15 @@ export async function GetTimeline(Cursor) {
|
|||
|
||||
// Gets a "public" timeline (essentially a feed by bsky.app where you can discover posts).
|
||||
export async function GetPublicTimeline(Cursor) {
|
||||
if (localStorage.getItem(Variables.BlueskyAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
let DPoP;
|
||||
let request;
|
||||
if (Cursor == "") {
|
||||
DPoP = await ClientDPoPPDS("GET", localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/app.bsky.feed.getFeed?feed=at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.generator/whats-hot");
|
||||
request = fetch(localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/app.bsky.feed.getFeed?feed=at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.generator/whats-hot", {method: "GET", headers: {"Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}});
|
||||
} else {
|
||||
DPoP = await ClientDPoPPDS("GET", localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/app.bsky.feed.getTimeline?feed=at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.generator/whats-hot&cursor=" + Cursor);
|
||||
request = fetch(localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/app.bsky.feed.getTimeline?feed=at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.generator/whats-hot&cursor=" + Cursor, {method: "GET", headers: {"Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}});
|
||||
let FetchThing = localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/app.bsky.feed.getFeed?feed=at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.generator/whats-hot";
|
||||
if (Cursor != "") {
|
||||
FetchThing += "&cursor=" + Cursor;
|
||||
}
|
||||
let DPoP = await ClientDPoPPDS("GET", FetchThing);
|
||||
let request = fetch(FetchThing, {method: "GET", headers: {"Authorization": "DPoP " + Token, "DPoP": DPoP}});
|
||||
let body = await request.then((response) => response.json());
|
||||
let status = await request.then((response) => response.status);
|
||||
let header = await request.then((response) => response.headers.get("dpop-nonce"));
|
||||
|
@ -55,13 +49,12 @@ export async function GetPublicTimeline(Cursor) {
|
|||
}
|
||||
|
||||
export async function GetProfile(DID) {
|
||||
if (localStorage.getItem(Variables.BlueskyAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
let DPoP = await ClientDPoPPDS("GET", localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/app.bsky.actor.getProfile?actor=" + DID);
|
||||
let request = fetch(localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/app.bsky.actor.getProfile?actor=" + DID, { method: "GET", headers: {"Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}});
|
||||
let FetchThing = localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/app.bsky.actor.getProfile?actor=" + DID;
|
||||
let DPoP = await ClientDPoPPDS("GET", FetchThing);
|
||||
let request = fetch(FetchThing, { method: "GET", headers: {"Authorization": "DPoP " + Token, "DPoP": DPoP}});
|
||||
let body = await request.then((response) => response.json());
|
||||
let status = await request.then((response) => response.status);
|
||||
let header = await request.then((response) => response.headers.get("dpop-nonce"));
|
||||
|
@ -74,13 +67,12 @@ export async function GetProfile(DID) {
|
|||
|
||||
// This gets the post. If there are multiple URIs, they must be within an array.
|
||||
export async function GetPosts(URIs) {
|
||||
if (localStorage.getItem(Variables.BlueskyAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
let DPoP = await ClientDPoPPDS("GET", localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/app.bsky.feed.getPosts?uris=" + URIs);
|
||||
let request = fetch(localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/app.bsky.feed.getPosts?uris=" + URIs, { method: "GET", headers: {"Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}});
|
||||
let FetchThing = localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/app.bsky.feed.getPosts?uris=" + URIs;
|
||||
let DPoP = await ClientDPoPPDS("GET", FetchThing);
|
||||
let request = fetch(FetchThing, { method: "GET", headers: {"Authorization": "DPoP " + Token, "DPoP": DPoP}});
|
||||
let body = await request.then((response) => response.json());
|
||||
let status = await request.then((response) => response.status);
|
||||
let header = await request.then((response) => response.headers.get("dpop-nonce"));
|
||||
|
@ -100,13 +92,17 @@ export async function GetBlob(DID, CID) {
|
|||
|
||||
// Gets a record. The repo is the account DID, the collection is the type of record, and the key is the little bit at the end.
|
||||
export async function GetRecord(Repo, Collection, RKey) {
|
||||
if (Token == null) {
|
||||
return "";
|
||||
}
|
||||
let RequestBody = {
|
||||
"repo": Repo,
|
||||
"collection": Collection,
|
||||
"rkey": RKey
|
||||
}
|
||||
let DPoP = await ClientDPoPPDS("GET", localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/com.atproto.repo.getRecord?repo=" + Repo + "&collection=" + Collection + "&rkey=" + RKey);
|
||||
let request = fetch(localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/com.atproto.repo.getRecord?repo=" + Repo + "&collection=" + Collection + "&rkey=" + RKey, { method: "GET", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}});
|
||||
let FetchThing = localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/com.atproto.repo.getRecord?repo=" + Repo + "&collection=" + Collection + "&rkey=" + RKey;
|
||||
let DPoP = await ClientDPoPPDS("GET", FetchThing);
|
||||
let request = fetch(FetchThing, { method: "GET", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + Token, "DPoP": DPoP}});
|
||||
let body = await request.then((response) => response.json());
|
||||
let status = await request.then((response) => response.status);
|
||||
let header = await request.then((response) => response.headers.get("dpop-nonce"));
|
||||
|
@ -120,28 +116,20 @@ export async function GetRecord(Repo, Collection, RKey) {
|
|||
// Creators
|
||||
// This creates a post. Requires the DID of the account and the Text for the record.
|
||||
export async function CreatePost(DID, Text, ContentWarning = undefined) {
|
||||
if (localStorage.getItem(Variables.BlueskyAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null) {
|
||||
return "";
|
||||
}
|
||||
let Record;
|
||||
if (ContentWarning == undefined) {
|
||||
Record = {
|
||||
let Record = {
|
||||
"$type": "app.bsky.feed.post",
|
||||
"text": Text,
|
||||
"createdAt": new Date(Date.now()).toISOString()
|
||||
}
|
||||
} else {
|
||||
Record = {
|
||||
"$type": "app.bsky.feed.post",
|
||||
"text": Text,
|
||||
"createdAt": new Date(Date.now()).toISOString(),
|
||||
"labels": {
|
||||
};
|
||||
if (ContentWarning != undefined) {
|
||||
Record.labels = {
|
||||
"$type": "com.atproto.label.defs#selfLabels",
|
||||
"values": [{
|
||||
"val": ContentWarning
|
||||
}]
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
let body = await CreateRecord(DID, "app.bsky.feed.post", Record, undefined);
|
||||
|
@ -156,48 +144,30 @@ export async function CreatePost(DID, Text, ContentWarning = undefined) {
|
|||
|
||||
// Creates a reply post. The RootID is always the first post, the ReplyID is the post you are replying to.
|
||||
export async function CreateReplyPost(DID, Text, ReplyID, RootID, ContentWarning = undefined) {
|
||||
if (localStorage.getItem(Variables.BlueskyAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null) {
|
||||
return "";
|
||||
}
|
||||
let Record;
|
||||
if (ContentWarning == undefined) {
|
||||
Record = {
|
||||
"$type": "app.bsky.feed.post",
|
||||
"text": Text,
|
||||
"createdAt": new Date(Date.now()).toISOString(),
|
||||
"reply": {
|
||||
"parent": {
|
||||
"uri": ReplyID.uri,
|
||||
"cid": ReplyID.cid
|
||||
},
|
||||
"root": {
|
||||
"uri": RootID.uri,
|
||||
"cid": RootID.cid
|
||||
}
|
||||
let Record = {
|
||||
"$type": "app.bsky.feed.post",
|
||||
"text": Text,
|
||||
"createdAt": new Date(Date.now()).toISOString(),
|
||||
"reply": {
|
||||
"parent": {
|
||||
"uri": ReplyID.uri,
|
||||
"cid": ReplyID.cid
|
||||
},
|
||||
"root": {
|
||||
"uri": RootID.uri,
|
||||
"cid": RootID.cid
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Record = {
|
||||
"$type": "app.bsky.feed.post",
|
||||
"text": Text,
|
||||
"createdAt": new Date(Date.now()).toISOString(),
|
||||
"reply": {
|
||||
"parent": {
|
||||
"uri": ReplyID.uri,
|
||||
"cid": ReplyID.cid
|
||||
},
|
||||
"root": {
|
||||
"uri": RootID.uri,
|
||||
"cid": RootID.cid
|
||||
},
|
||||
},
|
||||
"labels": {
|
||||
};
|
||||
if (ContentWarning != undefined) {
|
||||
Record.labels = {
|
||||
"$type": "com.atproto.label.defs#selfLabels",
|
||||
"values": [{
|
||||
"val": ContentWarning
|
||||
}]
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
let body = await CreateRecord(DID, "app.bsky.feed.post", Record, undefined);
|
||||
|
@ -212,8 +182,7 @@ export async function CreateReplyPost(DID, Text, ReplyID, RootID, ContentWarning
|
|||
|
||||
// Creates a Thread Gate for who can reply. Requires the account DID, a post, and a list of who is allowed.
|
||||
export async function CreateThreadGate(DID, Post, VisibilitySettings) {
|
||||
if (localStorage.getItem(Variables.BlueskyAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null) {
|
||||
return "";
|
||||
}
|
||||
let Record = {
|
||||
|
@ -228,8 +197,7 @@ export async function CreateThreadGate(DID, Post, VisibilitySettings) {
|
|||
|
||||
// Create a like and send it to the server.
|
||||
export async function CreateLike(DID, RefURI, RefCID) {
|
||||
if (localStorage.getItem(Variables.BlueskyAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null) {
|
||||
return "";
|
||||
}
|
||||
let StrongRef = {
|
||||
|
@ -253,8 +221,7 @@ export async function CreateLike(DID, RefURI, RefCID) {
|
|||
}
|
||||
|
||||
export async function CreateFollow(DID, SubjectDID) {
|
||||
if (localStorage.getItem(Variables.BlueskyAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null) {
|
||||
return "";
|
||||
}
|
||||
let Record = {
|
||||
|
@ -273,8 +240,7 @@ export async function CreateFollow(DID, SubjectDID) {
|
|||
}
|
||||
|
||||
export async function CreateBlock(DID, SubjectDID) {
|
||||
if (localStorage.getItem(Variables.BlueskyAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null) {
|
||||
return "";
|
||||
}
|
||||
let Record = {
|
||||
|
@ -320,14 +286,18 @@ export async function CreateRepost(DID, RefURI, RefCID) {
|
|||
|
||||
// Put record updates a record.
|
||||
export async function PutRecord(Repo, Collection, Record, RKey) {
|
||||
if (Token == null) {
|
||||
return "";
|
||||
}
|
||||
let RequestBody = {
|
||||
"repo": Repo,
|
||||
"collection": Collection,
|
||||
"record": Record,
|
||||
"rkey": RKey
|
||||
}
|
||||
let DPoP = await ClientDPoPPDS("POST", localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/com.atproto.repo.putRecord");
|
||||
let request = fetch(localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/com.atproto.repo.putRecord", { body: JSON.stringify(RequestBody), method: "POST", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}});
|
||||
let FetchThing = localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/com.atproto.repo.putRecord";
|
||||
let DPoP = await ClientDPoPPDS("POST", FetchThing);
|
||||
let request = fetch(FetchThing, { body: JSON.stringify(RequestBody), method: "POST", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + Token, "DPoP": DPoP}});
|
||||
let body = await request.then((response) => response.json());
|
||||
let status = await request.then((response) => response.status);
|
||||
let header = await request.then((response) => response.headers.get("dpop-nonce"));
|
||||
|
@ -340,6 +310,9 @@ export async function PutRecord(Repo, Collection, Record, RKey) {
|
|||
|
||||
// Creates a record. Universal way of making things.
|
||||
export async function CreateRecord(Repo, Collection, Record, RKey) {
|
||||
if (Token == null) {
|
||||
return "";
|
||||
}
|
||||
let RequestBody = {
|
||||
"repo": Repo,
|
||||
"collection": Collection,
|
||||
|
@ -348,8 +321,9 @@ export async function CreateRecord(Repo, Collection, Record, RKey) {
|
|||
if (RKey != undefined) {
|
||||
RequestBody.rkey = RKey;
|
||||
}
|
||||
let DPoP = await ClientDPoPPDS("POST", localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/com.atproto.repo.createRecord");
|
||||
let request = fetch(localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/com.atproto.repo.createRecord", { body: JSON.stringify(RequestBody), method: "POST", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}});
|
||||
let FetchThing = localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/com.atproto.repo.createRecord";
|
||||
let DPoP = await ClientDPoPPDS("POST", FetchThing);
|
||||
let request = fetch(FetchThing, { body: JSON.stringify(RequestBody), method: "POST", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + Token, "DPoP": DPoP}});
|
||||
let body = await request.then((response) => response.json());
|
||||
let status = await request.then((response) => response.status);
|
||||
let header = await request.then((response) => response.headers.get("dpop-nonce"));
|
||||
|
@ -361,6 +335,7 @@ export async function CreateRecord(Repo, Collection, Record, RKey) {
|
|||
}
|
||||
|
||||
// Applyers
|
||||
// Currently this only applies to the link Facets.
|
||||
export function ApplyFacets(record, text) {
|
||||
let StringArray = [];
|
||||
let SplitAreas = [0];
|
||||
|
@ -396,19 +371,24 @@ export function ApplyFacets(record, text) {
|
|||
}
|
||||
if (TempText == "") {
|
||||
return text;
|
||||
}return TempText;
|
||||
}
|
||||
return TempText;
|
||||
}
|
||||
|
||||
// Deleters
|
||||
// Removes a record. Can be a like, a repost, a post, etc.
|
||||
export async function DeleteRecord(Repo, Collection, RKey) {
|
||||
if (Token == null) {
|
||||
return "";
|
||||
}
|
||||
let RequestBody = {
|
||||
"repo": Repo,
|
||||
"collection": Collection,
|
||||
"rkey": RKey
|
||||
}
|
||||
let DPoP = await ClientDPoPPDS("POST", localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/com.atproto.repo.deleteRecord");
|
||||
let request = fetch(localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/com.atproto.repo.deleteRecord", { body: JSON.stringify(RequestBody), method: "POST", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + localStorage.getItem(Variables.BlueskyAccessToken), "DPoP": DPoP}});
|
||||
let FetchThing = localStorage.getItem(Variables.BlueskyPDS) + "/xrpc/com.atproto.repo.deleteRecord";
|
||||
let DPoP = await ClientDPoPPDS("POST", FetchThing);
|
||||
let request = fetch(FetchThing, { body: JSON.stringify(RequestBody), method: "POST", headers: {"Content-Type": "application/json", "Authorization": "DPoP " + Token, "DPoP": DPoP}});
|
||||
let body = await request.then((response) => response.json());
|
||||
let status = await request.then((response) => response.status);
|
||||
let header = await request.then((response) => response.headers.get("dpop-nonce"));
|
||||
|
|
|
@ -2,42 +2,41 @@ import * as Variables from "./Variables.js";
|
|||
|
||||
export const Scopes = "read write follow push";
|
||||
|
||||
let TokenType = localStorage.getItem(Variables.MastodonTokenType);
|
||||
let Token = localStorage.getItem(Variables.MastodonAccessToken);
|
||||
if (Token == null || TokenType == null) {
|
||||
console.error("No Mastodon access token!");
|
||||
}
|
||||
|
||||
// Getters
|
||||
// Gets the public timeline.
|
||||
export async function GetPublicTimeline(Local = false, Remote = false, Website, Cursor) {
|
||||
// Variables can be found in `setting.js`
|
||||
let Timeline;
|
||||
|
||||
if (Cursor == "") {
|
||||
if (Remote == true && Local == false) {
|
||||
Timeline = await fetch(Website + "/api/v1/timelines/public?remote=true")
|
||||
.then((response) => response.json());
|
||||
Timeline = fetch(Website + "/api/v1/timelines/public?remote=true");
|
||||
} else if (Local == true && Remote == false) {
|
||||
Timeline = await fetch(Website + "/api/v1/timelines/public?local=true")
|
||||
.then((response) => response.json());
|
||||
Timeline = fetch(Website + "/api/v1/timelines/public?local=true");
|
||||
} else {
|
||||
Timeline = await fetch(Website + "/api/v1/timelines/public")
|
||||
.then((response) => response.json());
|
||||
Timeline = fetch(Website + "/api/v1/timelines/public");
|
||||
}
|
||||
} else {
|
||||
if (Remote == true && Local == false) {
|
||||
Timeline = await fetch(Website + "/api/v1/timelines/public?remote=true&max_id=" + Cursor)
|
||||
.then((response) => response.json());
|
||||
Timeline = fetch(Website + "/api/v1/timelines/public?remote=true&max_id=" + Cursor);
|
||||
} else if (Local == true && Remote == false) {
|
||||
Timeline = await fetch(Website + "/api/v1/timelines/public?local=true&max_id=" + Cursor)
|
||||
.then((response) => response.json());
|
||||
Timeline = fetch(Website + "/api/v1/timelines/public?local=true&max_id=" + Cursor);
|
||||
} else {
|
||||
Timeline = await fetch(Website + "/api/v1/timelines/public?max_id=" + Cursor)
|
||||
.then((response) => response.json());
|
||||
Timeline = fetch(Website + "/api/v1/timelines/public?max_id=" + Cursor);
|
||||
}
|
||||
}
|
||||
return Timeline;
|
||||
let request = await Timeline.then((response) => response.json());
|
||||
return request;
|
||||
}
|
||||
|
||||
// Get the personal timeline.
|
||||
export async function GetTimeline(Cursor = "") {
|
||||
if (localStorage.getItem(Variables.MastodonAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null || TokenType == null) {
|
||||
return "";
|
||||
}
|
||||
// If there is a timestamp, GET with the timestamp.
|
||||
|
@ -45,65 +44,59 @@ export async function GetTimeline(Cursor = "") {
|
|||
if (Cursor != "") {
|
||||
request += "?max_id=" + Cursor;
|
||||
}
|
||||
return await fetch(request, {method: "GET", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}})
|
||||
return await fetch(request, {method: "GET", headers: {"Authorization": TokenType + " " + Token}})
|
||||
.then((response) => response.json());
|
||||
}
|
||||
|
||||
// Get the relationship. The token houses the person you are getting a relationship for.
|
||||
export async function GetRelationship(ID) {
|
||||
if (localStorage.getItem(Variables.MastodonAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null || TokenType == null) {
|
||||
return "";
|
||||
}
|
||||
return await fetch(localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/accounts/relationships?id[]=" + ID, {method: "GET", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}})
|
||||
return await fetch(localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/accounts/relationships?id[]=" + ID, {method: "GET", headers: {"Authorization": TokenType + " " + Token}})
|
||||
.then((response) => response.json());
|
||||
}
|
||||
|
||||
// Gets the favorites of a user that you have access to.
|
||||
export async function GetFavorites() {
|
||||
if (localStorage.getItem(Variables.MastodonAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null || TokenType == null) {
|
||||
return "";
|
||||
}
|
||||
return await fetch(localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/favourites", {method: "GET", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}})
|
||||
return await fetch(localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/favourites", {method: "GET", headers: {"Authorization": TokenType + " " + Token}})
|
||||
.then((response) => response.json());
|
||||
}
|
||||
|
||||
// Gets the bookmarks of a user that you have access to.
|
||||
export async function GetBookmarks() {
|
||||
if (localStorage.getItem(Variables.MastodonAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null || TokenType == null) {
|
||||
return "";
|
||||
}
|
||||
return await fetch(localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/bookmarks", {method: "GET", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}})
|
||||
return await fetch(localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/bookmarks", {method: "GET", headers: {"Authorization": TokenType + " " + Token}})
|
||||
.then((response) => response.json());
|
||||
}
|
||||
|
||||
// Gets the notifications of a user that you have access to.
|
||||
export async function GetNotifications() {
|
||||
if (localStorage.getItem(Variables.MastodonAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null || TokenType == null) {
|
||||
return "";
|
||||
}
|
||||
return await fetch(localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/notifications", {method: "GET", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}})
|
||||
return await fetch(localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/notifications", {method: "GET", headers: {"Authorization": TokenType + " " + Token}})
|
||||
.then((response) => response.json());
|
||||
}
|
||||
|
||||
// A status is just a post. It gets it.
|
||||
export async function GetStatus(ID) {
|
||||
if (localStorage.getItem(Variables.MastodonAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null || TokenType == null) {
|
||||
return "";
|
||||
}
|
||||
return await fetch(localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/statuses/" + ID, {method: "GET", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}})
|
||||
return await fetch(localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/statuses/" + ID, {method: "GET", headers: {"Authorization": TokenType + " " + Token}})
|
||||
.then((response) => response.json());
|
||||
}
|
||||
|
||||
// Creators
|
||||
// Make a status
|
||||
export async function CreateStatus(Text, SpoilerText = undefined, Visibility = "public") {
|
||||
if (localStorage.getItem(Variables.MastodonAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null || TokenType == null) {
|
||||
return "";
|
||||
}
|
||||
// Stolen from StackOverflow.
|
||||
|
@ -114,7 +107,7 @@ export async function CreateStatus(Text, SpoilerText = undefined, Visibility = "
|
|||
FetchThing += "&spoiler_text=" + SpoilerText;
|
||||
}
|
||||
// Send the request.
|
||||
let request = fetch(FetchThing, {method: "POST", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}});
|
||||
let request = fetch(FetchThing, {method: "POST", headers: {"Authorization": TokenType + " " + Token}});
|
||||
let body = await request.then((response) => response.json());
|
||||
let status = await request.then((response) => response.status);
|
||||
// This is in case you went over the characters.
|
||||
|
@ -126,7 +119,7 @@ export async function CreateStatus(Text, SpoilerText = undefined, Visibility = "
|
|||
FetchThing += "&spoiler_text=" + SpoilerText;
|
||||
}
|
||||
// Send the request.
|
||||
request = fetch(FetchThing, {method: "POST", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}});
|
||||
request = fetch(FetchThing, {method: "POST", headers: {"Authorization": TokenType + " " + Token}});
|
||||
body = await request.then((response) => response.json());
|
||||
await CreateReplyStatus(Text.slice(matches[0] - 1, SpoilerText, Text.length - 1), Visibility, body.id);
|
||||
}
|
||||
|
@ -134,8 +127,7 @@ export async function CreateStatus(Text, SpoilerText = undefined, Visibility = "
|
|||
}
|
||||
|
||||
export async function CreateReplyStatus(Text, SpoilerText = undefined, Visibility = "public", ReplyID) {
|
||||
if (localStorage.getItem(Variables.MastodonAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null || TokenType == null) {
|
||||
return "";
|
||||
}
|
||||
// Stolen from StackOverflow
|
||||
|
@ -146,7 +138,7 @@ export async function CreateReplyStatus(Text, SpoilerText = undefined, Visibilit
|
|||
FetchThing += "&spoiler_text=" + SpoilerText;
|
||||
}
|
||||
// Send the request.
|
||||
let request = fetch(FetchThing, {method: "POST", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}});
|
||||
let request = fetch(FetchThing, {method: "POST", headers: {"Authorization": TokenType + " " + Token}});
|
||||
let body = await request.then((response) => response.json());
|
||||
let status = await request.then((response) => response.status);
|
||||
// This is in case you went over the characters.
|
||||
|
@ -158,7 +150,7 @@ export async function CreateReplyStatus(Text, SpoilerText = undefined, Visibilit
|
|||
FetchThing += "&spoiler_text=" + SpoilerText;
|
||||
}
|
||||
// Send the request.
|
||||
request = fetch(FetchThing, {method: "POST", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}});
|
||||
request = fetch(FetchThing, {method: "POST", headers: {"Authorization": TokenType + " " + Token}});
|
||||
body = await request.then((response) => response.json());
|
||||
await CreateReplyStatus(Text.slice(matches[0] - 1, Text.length - 1), SpoilerText, Visibility, body.id);
|
||||
}
|
||||
|
@ -166,8 +158,7 @@ export async function CreateReplyStatus(Text, SpoilerText = undefined, Visibilit
|
|||
}
|
||||
|
||||
export async function CreateFavorite(ID, IsFavorited) {
|
||||
if (localStorage.getItem(Variables.MastodonAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null || TokenType == null) {
|
||||
return "";
|
||||
}
|
||||
let request = localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/statuses/" + ID;
|
||||
|
@ -176,13 +167,12 @@ export async function CreateFavorite(ID, IsFavorited) {
|
|||
} else {
|
||||
request += "/unfavourite";
|
||||
}
|
||||
return await fetch(request, {method: "POST", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}})
|
||||
return await fetch(request, {method: "POST", headers: {"Authorization": TokenType + " " + Token}})
|
||||
.then((response) => response.json());
|
||||
}
|
||||
|
||||
export async function CreateReblog(ID, IsReblogged) {
|
||||
if (localStorage.getItem(Variables.MastodonAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null || TokenType == null) {
|
||||
return "";
|
||||
}
|
||||
let request = localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/statuses/" + ID;
|
||||
|
@ -191,7 +181,7 @@ export async function CreateReblog(ID, IsReblogged) {
|
|||
} else {
|
||||
request += "/unreblog";
|
||||
}
|
||||
return await fetch(request, {method: "POST", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}})
|
||||
return await fetch(request, {method: "POST", headers: {"Authorization": TokenType + " " + Token}})
|
||||
.then((response) => response.json());
|
||||
}
|
||||
|
||||
|
@ -206,13 +196,12 @@ export async function CreateFollow(ID, IsFollowed) {
|
|||
} else {
|
||||
request += "/unfollow";
|
||||
}
|
||||
return await fetch(request, {method: "POST", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}})
|
||||
return await fetch(request, {method: "POST", headers: {"Authorization": TokenType + " " + Token}})
|
||||
.then((response) => response.json());
|
||||
}
|
||||
|
||||
export async function CreateBlock(ID, IsBlocked) {
|
||||
if (localStorage.getItem(Variables.MastodonAccessToken) == null) {
|
||||
console.log("No access token!");
|
||||
if (Token == null || TokenType == null) {
|
||||
return "";
|
||||
}
|
||||
let request = localStorage.getItem(Variables.MastodonWebsite) + "/api/v1/accounts/" + ID;
|
||||
|
@ -221,7 +210,7 @@ export async function CreateBlock(ID, IsBlocked) {
|
|||
} else {
|
||||
request += "/unblock";
|
||||
}
|
||||
return await fetch(request, {method: "POST", headers: {"Authorization": localStorage.getItem(Variables.MastodonTokenType) + " " + localStorage.getItem(Variables.MastodonAccessToken)}})
|
||||
return await fetch(request, {method: "POST", headers: {"Authorization": TokenType + " " + Token}})
|
||||
.then((response) => response.json());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue