mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-20 14:10:39 +01:00
Avoid returning 401 as API response code
This commit is contained in:
parent
6f610204d6
commit
44ac2ca4e6
15
server.js
15
server.js
@ -1108,7 +1108,8 @@ app.post('/getstatus_openai', jsonParser, async function (request, response_gets
|
||||
}
|
||||
|
||||
if (!api_key_openai && !request.body.reverse_proxy) {
|
||||
return response_getstatus_openai.status(401).send({ error: true });
|
||||
console.log('OpenAI API key is missing.');
|
||||
return response_getstatus_openai.status(400).send({ error: true });
|
||||
}
|
||||
|
||||
try {
|
||||
@ -1262,7 +1263,8 @@ async function sendScaleRequest(request, response) {
|
||||
const api_key_scale = readSecret(SECRET_KEYS.SCALE);
|
||||
|
||||
if (!api_key_scale) {
|
||||
return response.status(401).send({ error: true });
|
||||
console.log('Scale API key is missing.');
|
||||
return response.status(400).send({ error: true });
|
||||
}
|
||||
|
||||
const requestPrompt = convertChatMLPrompt(request.body.messages);
|
||||
@ -1379,7 +1381,8 @@ async function sendClaudeRequest(request, response) {
|
||||
const api_key_claude = request.body.reverse_proxy ? request.body.proxy_password : readSecret(SECRET_KEYS.CLAUDE);
|
||||
|
||||
if (!api_key_claude) {
|
||||
return response.status(401).send({ error: true });
|
||||
console.log('Claude API key is missing.');
|
||||
return response.status(400).send({ error: true });
|
||||
}
|
||||
|
||||
try {
|
||||
@ -1468,7 +1471,8 @@ async function sendPalmRequest(request, response) {
|
||||
const api_key_palm = readSecret(SECRET_KEYS.PALM);
|
||||
|
||||
if (!api_key_palm) {
|
||||
return response.status(401).send({ error: true });
|
||||
console.log('Palm API key is missing.');
|
||||
return response.status(400).send({ error: true });
|
||||
}
|
||||
|
||||
const body = {
|
||||
@ -1573,7 +1577,8 @@ app.post('/generate_openai', jsonParser, function (request, response_generate_op
|
||||
}
|
||||
|
||||
if (!api_key_openai && !request.body.reverse_proxy) {
|
||||
return response_generate_openai.status(401).send({ error: true });
|
||||
console.log('OpenAI API key is missing.');
|
||||
return response_generate_openai.status(400).send({ error: true });
|
||||
}
|
||||
|
||||
// Add custom stop sequences
|
||||
|
@ -69,7 +69,8 @@ router.post('/status', jsonParser, async function (req, res) {
|
||||
const api_key_novel = readSecret(SECRET_KEYS.NOVEL);
|
||||
|
||||
if (!api_key_novel) {
|
||||
return res.sendStatus(401);
|
||||
console.log('NovelAI Access Token is missing.');
|
||||
return res.sendStatus(400);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -104,7 +105,8 @@ router.post('/generate', jsonParser, async function (req, res) {
|
||||
const api_key_novel = readSecret(SECRET_KEYS.NOVEL);
|
||||
|
||||
if (!api_key_novel) {
|
||||
return res.sendStatus(401);
|
||||
console.log('NovelAI Access Token is missing.');
|
||||
return res.sendStatus(400);
|
||||
}
|
||||
|
||||
const controller = new AbortController();
|
||||
@ -233,7 +235,8 @@ router.post('/generate-image', jsonParser, async (request, response) => {
|
||||
const key = readSecret(SECRET_KEYS.NOVEL);
|
||||
|
||||
if (!key) {
|
||||
return response.sendStatus(401);
|
||||
console.log('NovelAI Access Token is missing.');
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -327,7 +330,8 @@ router.post('/generate-voice', jsonParser, async (request, response) => {
|
||||
const token = readSecret(SECRET_KEYS.NOVEL);
|
||||
|
||||
if (!token) {
|
||||
return response.sendStatus(401);
|
||||
console.log('NovelAI Access Token is missing.');
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
const text = request.body.text;
|
||||
|
@ -21,7 +21,7 @@ router.post('/caption-image', jsonParser, async (request, response) => {
|
||||
|
||||
if (!key) {
|
||||
console.log('No key found for API', request.body.api);
|
||||
return response.sendStatus(401);
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
const body = {
|
||||
@ -91,7 +91,7 @@ router.post('/transcribe-audio', urlencodedParser, async (request, response) =>
|
||||
|
||||
if (!key) {
|
||||
console.log('No OpenAI key found');
|
||||
return response.sendStatus(401);
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
if (!request.file) {
|
||||
@ -139,7 +139,7 @@ router.post('/generate-voice', jsonParser, async (request, response) => {
|
||||
|
||||
if (!key) {
|
||||
console.log('No OpenAI key found');
|
||||
return response.sendStatus(401);
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
const result = await fetch('https://api.openai.com/v1/audio/speech', {
|
||||
@ -178,7 +178,7 @@ router.post('/generate-image', jsonParser, async (request, response) => {
|
||||
|
||||
if (!key) {
|
||||
console.log('No OpenAI key found');
|
||||
return response.sendStatus(401);
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
console.log('OpenAI request', request.body);
|
||||
|
@ -11,7 +11,7 @@ router.post('/search', jsonParser, async (request, response) => {
|
||||
|
||||
if (!key) {
|
||||
console.log('No SerpApi key found');
|
||||
return response.sendStatus(401);
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
const { query } = request.body;
|
||||
|
@ -16,7 +16,7 @@ router.post('/libre', jsonParser, async (request, response) => {
|
||||
|
||||
if (!url) {
|
||||
console.log('LibreTranslate URL is not configured.');
|
||||
return response.sendStatus(401);
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
const text = request.body.text;
|
||||
@ -102,7 +102,8 @@ router.post('/deepl', jsonParser, async (request, response) => {
|
||||
const key = readSecret(SECRET_KEYS.DEEPL);
|
||||
|
||||
if (!key) {
|
||||
return response.sendStatus(401);
|
||||
console.log('DeepL key is not configured.');
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
const text = request.body.text;
|
||||
@ -158,7 +159,7 @@ router.post('/onering', jsonParser, async (request, response) => {
|
||||
|
||||
if (!url) {
|
||||
console.log('OneRing URL is not configured.');
|
||||
return response.sendStatus(401);
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
if (!secretUrl && url === ONERING_URL_DEFAULT) {
|
||||
@ -211,7 +212,7 @@ router.post('/deeplx', jsonParser, async (request, response) => {
|
||||
|
||||
if (!url) {
|
||||
console.log('DeepLX URL is not configured.');
|
||||
return response.sendStatus(401);
|
||||
return response.sendStatus(400);
|
||||
}
|
||||
|
||||
if (!secretUrl && url === DEEPLX_URL_DEFAULT) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user