mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge pull request #1281 from Tony-sama/staging
Live2d assets management
This commit is contained in:
1
public/assets/live2d/.placeholder
Normal file
1
public/assets/live2d/.placeholder
Normal file
@@ -0,0 +1 @@
|
||||
Put live2d model folders here
|
@@ -5,7 +5,7 @@ const fetch = require('node-fetch').default;
|
||||
const { finished } = require('stream/promises');
|
||||
const { DIRECTORIES, UNSAFE_EXTENSIONS } = require('./constants');
|
||||
|
||||
const VALID_CATEGORIES = ["bgm", "ambient", "blip"];
|
||||
const VALID_CATEGORIES = ["bgm", "ambient", "blip", "live2d"];
|
||||
|
||||
/**
|
||||
* Sanitizes the input filename for theasset.
|
||||
@@ -66,6 +66,26 @@ function registerEndpoints(app, jsonParser) {
|
||||
for (const folder of folders) {
|
||||
if (folder == "temp")
|
||||
continue;
|
||||
|
||||
// Live2d assets
|
||||
if (folder == "live2d") {
|
||||
output[folder] = [];
|
||||
const live2d_folders = fs.readdirSync(path.join(folderPath, folder));
|
||||
for (let model_folder of live2d_folders) {
|
||||
const live2d_model_path = path.join(folderPath, folder, model_folder);
|
||||
if (fs.statSync(live2d_model_path).isDirectory()) {
|
||||
for (let file of fs.readdirSync(live2d_model_path)) {
|
||||
if (file.includes("model")) {
|
||||
//console.debug("Asset live2d model found:",file)
|
||||
output[folder].push([`${model_folder}`,path.join("assets", folder, model_folder, file)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Other assets (bgm/ambient/blip)
|
||||
const files = fs.readdirSync(path.join(folderPath, folder))
|
||||
.filter(filename => {
|
||||
return filename != ".placeholder";
|
||||
@@ -227,6 +247,24 @@ function registerEndpoints(app, jsonParser) {
|
||||
let output = [];
|
||||
try {
|
||||
if (fs.existsSync(folderPath) && fs.statSync(folderPath).isDirectory()) {
|
||||
|
||||
// Live2d assets
|
||||
if (category == "live2d") {
|
||||
const folders = fs.readdirSync(folderPath)
|
||||
for (let modelFolder of folders) {
|
||||
const live2dModelPath = path.join(folderPath, modelFolder);
|
||||
if (fs.statSync(live2dModelPath).isDirectory()) {
|
||||
for (let file of fs.readdirSync(live2dModelPath)) {
|
||||
//console.debug("Character live2d model found:", file)
|
||||
if (file.includes("model"))
|
||||
output.push([`${modelFolder}`,path.join("characters", name, category, modelFolder, file) ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return response.send(output);
|
||||
}
|
||||
|
||||
// Other assets
|
||||
const files = fs.readdirSync(folderPath)
|
||||
.filter(filename => {
|
||||
return filename != ".placeholder";
|
||||
@@ -234,7 +272,6 @@ function registerEndpoints(app, jsonParser) {
|
||||
|
||||
for (let i of files)
|
||||
output.push(`/characters/${name}/${category}/${i}`);
|
||||
|
||||
}
|
||||
return response.send(output);
|
||||
}
|
||||
|
Reference in New Issue
Block a user