Extras: Add API authentication support

An API key is extremely important for ST-Extras servers that are
exposed to the internet.

Add an API key field below where the user enters the extras URL. For
convenience, this key is persisted whenever the user refreshes the
page.

Also modify the fetch requests to always include API keys if present.

See ST-Extras for more information on how this works.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri
2023-06-02 22:21:21 -04:00
parent f4802952b6
commit 36ea41f0a6
7 changed files with 50 additions and 25 deletions

View File

@ -1,5 +1,5 @@
import { callPopup, getRequestHeaders, saveSettingsDebounced } from "../../../script.js";
import { getContext, getApiUrl, modules, extension_settings, ModuleWorkerWrapper } from "../../extensions.js";
import { getContext, getApiUrl, modules, extension_settings, ModuleWorkerWrapper, doExtrasFetch } from "../../extensions.js";
export { MODULE_NAME };
const MODULE_NAME = 'expressions';
@ -122,7 +122,7 @@ async function moduleWorker() {
const url = new URL(getApiUrl());
url.pathname = '/api/classify';
const apiResult = await fetch(url, {
const apiResult = await doExtrasFetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@ -265,7 +265,7 @@ async function getExpressionsList() {
url.pathname = '/api/classify/labels';
try {
const apiResult = await fetch(url, {
const apiResult = await doExtrasFetch(url, {
method: 'GET',
headers: { 'Bypass-Tunnel-Reminder': 'bypass' },
});