mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-04-17 12:17:21 +02:00
Reformat code.
This commit is contained in:
parent
43e70c9df1
commit
cd24de3c2e
@ -4,13 +4,11 @@ TODO:
|
|||||||
*/
|
*/
|
||||||
//const DEBUG_TONY_SAMA_FORK_MODE = false
|
//const DEBUG_TONY_SAMA_FORK_MODE = false
|
||||||
|
|
||||||
import { saveSettingsDebounced, getRequestHeaders, callPopup } from "../../../script.js";
|
import { getRequestHeaders, callPopup } from "../../../script.js";
|
||||||
import { getContext, getApiUrl, extension_settings, doExtrasFetch, ModuleWorkerWrapper, modules } from "../../extensions.js";
|
|
||||||
export { MODULE_NAME };
|
export { MODULE_NAME };
|
||||||
|
|
||||||
const MODULE_NAME = 'Assets';
|
const MODULE_NAME = 'Assets';
|
||||||
const DEBUG_PREFIX = "<Assets module> ";
|
const DEBUG_PREFIX = "<Assets module> ";
|
||||||
const UPDATE_INTERVAL = 1000;
|
|
||||||
let ASSETS_JSON_URL = "https://raw.githubusercontent.com/SillyTavern/SillyTavern-Content/main/index.json"
|
let ASSETS_JSON_URL = "https://raw.githubusercontent.com/SillyTavern/SillyTavern-Content/main/index.json"
|
||||||
|
|
||||||
const extensionName = "assets";
|
const extensionName = "assets";
|
||||||
@ -117,9 +115,12 @@ async function installAsset(url, assetType, filename) {
|
|||||||
console.debug(DEBUG_PREFIX, "Downloading ", url);
|
console.debug(DEBUG_PREFIX, "Downloading ", url);
|
||||||
const category = assetType;
|
const category = assetType;
|
||||||
try {
|
try {
|
||||||
const result = await fetch(`/asset_download?url=${url}&category=${category}&filename=${filename}`, {
|
const body = { url, category, filename };
|
||||||
|
const result = await fetch('/asset_download', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: getRequestHeaders(),
|
headers: getRequestHeaders(),
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
cache: 'no-cache',
|
||||||
});
|
});
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
console.debug(DEBUG_PREFIX, "Download success.")
|
console.debug(DEBUG_PREFIX, "Download success.")
|
||||||
|
@ -247,8 +247,7 @@ async function moduleWorker() {
|
|||||||
if (custom_background !== undefined)
|
if (custom_background !== undefined)
|
||||||
newBackground = custom_background
|
newBackground = custom_background
|
||||||
|
|
||||||
if (!isDataURL(newBackground))
|
if (!isDataURL(newBackground)) {
|
||||||
{
|
|
||||||
newBackground = newBackground.substring(newBackground.lastIndexOf("/") + 1).replace(/\.[^/.]+$/, "").replaceAll("%20", "-").replaceAll(" ", "-"); // remove path and spaces
|
newBackground = newBackground.substring(newBackground.lastIndexOf("/") + 1).replace(/\.[^/.]+$/, "").replaceAll("%20", "-").replaceAll(" ", "-"); // remove path and spaces
|
||||||
|
|
||||||
//console.debug(DEBUG_PREFIX,"Current backgroung:",newBackground);
|
//console.debug(DEBUG_PREFIX,"Current backgroung:",newBackground);
|
||||||
|
19
server.js
19
server.js
@ -5057,13 +5057,11 @@ app.post('/get_assets', jsonParser, async (request, response) => {
|
|||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
app.post('/asset_download', jsonParser, async (request, response) => {
|
app.post('/asset_download', jsonParser, async (request, response) => {
|
||||||
const fs = require('fs');
|
|
||||||
const { Readable } = require('stream');
|
const { Readable } = require('stream');
|
||||||
const { finished } = require('stream/promises');
|
const { finished } = require('stream/promises');
|
||||||
const path = require("path");
|
const url = request.body.url;
|
||||||
const url = request.query.url;
|
const inputCategory = request.body.category;
|
||||||
const inputCategory = request.query.category;
|
const inputFilename = sanitize(request.body.filename);
|
||||||
const inputFilename = request.query.filename;
|
|
||||||
const validCategories = ["bgm", "ambient"]
|
const validCategories = ["bgm", "ambient"]
|
||||||
|
|
||||||
// Check category
|
// Check category
|
||||||
@ -5112,10 +5110,7 @@ app.post('/asset_download', jsonParser, async (request, response) => {
|
|||||||
|
|
||||||
// Move into asset place
|
// Move into asset place
|
||||||
console.debug("Download finished, moving file from", temp_path, "to", file_path);
|
console.debug("Download finished, moving file from", temp_path, "to", file_path);
|
||||||
fs.rename(temp_path,file_path, (err) => {
|
fs.renameSync(temp_path, file_path);
|
||||||
if (err) throw err;
|
|
||||||
console.log('Rename complete!');
|
|
||||||
});
|
|
||||||
response.sendStatus(200);
|
response.sendStatus(200);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
@ -5125,7 +5120,6 @@ app.post('/asset_download', jsonParser, async (request, response) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
/**
|
/**
|
||||||
* HTTP POST handler function to retrieve a character background music list.
|
* HTTP POST handler function to retrieve a character background music list.
|
||||||
@ -5136,7 +5130,7 @@ app.post('/asset_download', jsonParser, async (request, response) => {
|
|||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
app.post('/get_character_assets_list', jsonParser, async (request, response) => {
|
app.post('/get_character_assets_list', jsonParser, async (request, response) => {
|
||||||
const name = request.query.name;
|
const name = sanitize(request.query.name);
|
||||||
const inputCategory = request.query.category;
|
const inputCategory = request.query.category;
|
||||||
const validCategories = ["bgm", "ambient"]
|
const validCategories = ["bgm", "ambient"]
|
||||||
|
|
||||||
@ -5171,7 +5165,4 @@ app.post('/get_character_assets_list', jsonParser, async (request, response) =>
|
|||||||
console.log(err);
|
console.log(err);
|
||||||
return response.sendStatus(500);
|
return response.sendStatus(500);
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user