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