Replace restClient in getstatus_novelai

This commit is contained in:
Cohee 2023-08-30 21:58:46 +03:00
parent a757532c3e
commit ce46e1a4ca
1 changed files with 21 additions and 20 deletions

View File

@ -1850,8 +1850,7 @@ function getImages(path) {
//***********Novel.ai API //***********Novel.ai API
app.post("/getstatus_novelai", jsonParser, function (request, response_getstatus_novel = response) { app.post("/getstatus_novelai", jsonParser, async function (request, response_getstatus_novel) {
if (!request.body) return response_getstatus_novel.sendStatus(400); if (!request.body) return response_getstatus_novel.sendStatus(400);
const api_key_novel = readSecret(SECRET_KEYS.NOVEL); const api_key_novel = readSecret(SECRET_KEYS.NOVEL);
@ -1859,28 +1858,30 @@ app.post("/getstatus_novelai", jsonParser, function (request, response_getstatus
return response_getstatus_novel.sendStatus(401); return response_getstatus_novel.sendStatus(401);
} }
var data = {}; try {
var args = { const response = await fetch(api_novelai + "/user/subscription", {
data: data, method: 'GET',
headers: { "Content-Type": "application/json", "Authorization": "Bearer " + api_key_novel } headers: {
}; 'Content-Type': 'application/json',
'Authorization': "Bearer " + api_key_novel,
},
});
restClient.get(api_novelai + "/user/subscription", args, function (data, response) { if (response.ok) {
if (response.statusCode == 200) { const data = await response.json();
//console.log(data); return response_getstatus_novel.send(data);
response_getstatus_novel.send(data);//data); } else if (response.status == 401) {
console.log('NovelAI Access Token is incorrect.');
return response_getstatus_novel.send({ error: true });
} }
else { else {
if (response.statusCode == 401) { console.log('NovelAI returned an error:', response.statusText);
console.log('Access Token is incorrect.'); return response_getstatus_novel.send({ error: true });
} }
} catch (error) {
console.log(data); console.log(error);
response_getstatus_novel.send({ error: true }); return response_getstatus_novel.send({ error: true });
} }
}).on('error', function () {
response_getstatus_novel.send({ error: true });
});
}); });
app.post("/generate_novelai", jsonParser, async function (request, response_generate_novel = response) { app.post("/generate_novelai", jsonParser, async function (request, response_generate_novel = response) {