Add image test API.
This commit is contained in:
parent
27815fcfba
commit
14f02c5d53
1 changed files with 3 additions and 27 deletions
|
@ -59,40 +59,16 @@ export default class DiscordRPC {
|
||||||
const self = this;
|
const self = this;
|
||||||
ipcMain.on("discordrpc:updateImage", async (_event, imageurl) => {
|
ipcMain.on("discordrpc:updateImage", async (_event, imageurl) => {
|
||||||
if (!this._utils.getStoreValue("general.privateEnabled")) {
|
if (!this._utils.getStoreValue("general.privateEnabled")) {
|
||||||
let b64data = "";
|
fetch("https://api-test.cider.sh/v1/images", {
|
||||||
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", {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: postbody,
|
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
|
||||||
"User-Agent": this._utils.getWindow().webContents.getUserAgent(),
|
"User-Agent": this._utils.getWindow().webContents.getUserAgent(),
|
||||||
|
"url": imageurl
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then(function (json) {
|
.then(function (json) {
|
||||||
self._attributes["artwork"]["url"] = json.url;
|
self._attributes["artwork"]["url"] = json.imageUrl;
|
||||||
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.setActivity(self._attributes);
|
self.setActivity(self._attributes);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue