Add image test API.

This commit is contained in:
cryptofyre 2022-10-14 18:17:37 -05:00 committed by GitHub
parent 27815fcfba
commit 14f02c5d53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -59,40 +59,16 @@ export default class DiscordRPC {
const self = this;
ipcMain.on("discordrpc:updateImage", async (_event, imageurl) => {
if (!this._utils.getStoreValue("general.privateEnabled")) {
let b64data = "";
let postbody = "";
if (imageurl.startsWith("/ciderlocalart")) {
let port = await this._utils.getWindow().webContents.executeJavaScript(`app.clientPort`);
console.log("http://localhost:" + port + imageurl);
const response = await fetch("http://localhost:" + port + imageurl);
b64data = (await response.buffer()).toString("base64");
postbody = JSON.stringify({ data: b64data });
fetch("https://api.cider.sh/v1/images", {
fetch("https://api-test.cider.sh/v1/images", {
method: "POST",
body: postbody,
headers: {
"Content-Type": "application/json",
"User-Agent": this._utils.getWindow().webContents.getUserAgent(),
"url": imageurl
},
})
.then((res) => res.json())
.then(function (json) {
self._attributes["artwork"]["url"] = json.url;
self.setActivity(self._attributes);
});
} else {
postbody = JSON.stringify({ url: imageurl });
fetch("https://api.cider.sh/v1/images", {
method: "POST",
body: postbody,
headers: {
"Content-Type": "application/json",
"User-Agent": this._utils.getWindow().webContents.getUserAgent(),
},
})
.then((res) => res.json())
.then(function (json) {
self._attributes["artwork"]["url"] = json.url;
self._attributes["artwork"]["url"] = json.imageUrl;
self.setActivity(self._attributes);
});
}