mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
@@ -3,3 +3,4 @@ node_modules
|
|||||||
npm-debug.log
|
npm-debug.log
|
||||||
readme*
|
readme*
|
||||||
Start.bat
|
Start.bat
|
||||||
|
/dist
|
46
.github/workflows/build-and-publish-release-dev.yml
vendored
Normal file
46
.github/workflows/build-and-publish-release-dev.yml
vendored
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
name: Build and Publish Release (Dev)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- dev
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build_and_publish:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 18
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build and package with pkg
|
||||||
|
run: |
|
||||||
|
npm install -g pkg
|
||||||
|
npm run pkg
|
||||||
|
|
||||||
|
- name: Create or update release
|
||||||
|
id: create_release
|
||||||
|
uses: actions/create-release@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
tag_name: continuous-release-dev
|
||||||
|
release_name: Continuous Release (Dev)
|
||||||
|
draft: false
|
||||||
|
prerelease: true
|
||||||
|
|
||||||
|
- name: Upload binaries to release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
files: dist/*
|
||||||
|
release_id: ${{ steps.create_release.outputs.id }}
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
46
.github/workflows/build-and-publish-release-main.yml
vendored
Normal file
46
.github/workflows/build-and-publish-release-main.yml
vendored
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
name: Build and Publish Release (Main)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build_and_publish:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 18
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build and package with pkg
|
||||||
|
run: |
|
||||||
|
npm install -g pkg
|
||||||
|
npm run pkg
|
||||||
|
|
||||||
|
- name: Create or update release
|
||||||
|
id: create_release
|
||||||
|
uses: actions/create-release@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
tag_name: continuous-release-main
|
||||||
|
release_name: Continuous Release (Main)
|
||||||
|
draft: false
|
||||||
|
prerelease: true
|
||||||
|
|
||||||
|
- name: Upload binaries to release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
files: dist/*
|
||||||
|
release_id: ${{ steps.create_release.outputs.id }}
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -17,3 +17,4 @@ public/settings.json
|
|||||||
whitelist.txt
|
whitelist.txt
|
||||||
.vscode
|
.vscode
|
||||||
secrets.json
|
secrets.json
|
||||||
|
/dist
|
@@ -2,3 +2,5 @@ node_modules/
|
|||||||
/uploads/
|
/uploads/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
/thumbnails
|
/thumbnails
|
||||||
|
secrets.json
|
||||||
|
/dist
|
1182
package-lock.json
generated
1182
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
27
package.json
27
package.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@dqbd/tiktoken": "^1.0.2",
|
"@dqbd/tiktoken": "^1.0.2",
|
||||||
"axios": "^1.3.4",
|
"axios": "^0.27.2",
|
||||||
"command-exists": "^1.2.9",
|
"command-exists": "^1.2.9",
|
||||||
"compression": "^1",
|
"compression": "^1",
|
||||||
"cookie-parser": "^1.4.6",
|
"cookie-parser": "^1.4.6",
|
||||||
@@ -44,7 +44,8 @@
|
|||||||
},
|
},
|
||||||
"version": "1.5.4",
|
"version": "1.5.4",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node server.js"
|
"start": "node server.js",
|
||||||
|
"pkg": "pkg ."
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"sillytavern": "./server.js"
|
"sillytavern": "./server.js"
|
||||||
@@ -53,11 +54,27 @@
|
|||||||
"no-path-concat": "off",
|
"no-path-concat": "off",
|
||||||
"no-var": "off"
|
"no-var": "off"
|
||||||
},
|
},
|
||||||
|
"main": "server.js",
|
||||||
"pkg": {
|
"pkg": {
|
||||||
|
"targets": [
|
||||||
|
"node18-linux-arm64",
|
||||||
|
"node18-linux-x64",
|
||||||
|
"node18-macos-arm64",
|
||||||
|
"node18-macos-x64",
|
||||||
|
"node18-windows-arm64",
|
||||||
|
"node18-windows-x64"
|
||||||
|
],
|
||||||
"assets": [
|
"assets": [
|
||||||
"node_modules/open/xdg-open/",
|
"node_modules/**/*",
|
||||||
"public",
|
"poe_graphql/**/*"
|
||||||
"uploads"
|
],
|
||||||
|
"outputPath": "dist",
|
||||||
|
"scripts": [
|
||||||
|
"server.js"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"pkg": "^5.8.1",
|
||||||
|
"pkg-fetch": "^3.5.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
server.js
41
server.js
@@ -20,7 +20,10 @@ const cliArguments = yargs(hideBin(process.argv))
|
|||||||
}).argv;
|
}).argv;
|
||||||
|
|
||||||
// change all relative paths
|
// change all relative paths
|
||||||
process.chdir(__dirname)
|
const path = require('path');
|
||||||
|
const directory = process.pkg ? path.dirname(process.execPath) : __dirname;
|
||||||
|
console.log(process.pkg ? 'Running from binary' : 'Running from source');
|
||||||
|
process.chdir(directory);
|
||||||
|
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const compression = require('compression');
|
const compression = require('compression');
|
||||||
@@ -42,7 +45,7 @@ const encode = require('png-chunks-encode');
|
|||||||
const PNGtext = require('png-chunk-text');
|
const PNGtext = require('png-chunk-text');
|
||||||
|
|
||||||
const jimp = require('jimp');
|
const jimp = require('jimp');
|
||||||
const path = require('path');
|
//const path = require('path');
|
||||||
const sanitize = require('sanitize-filename');
|
const sanitize = require('sanitize-filename');
|
||||||
const mime = require('mime-types');
|
const mime = require('mime-types');
|
||||||
|
|
||||||
@@ -60,10 +63,10 @@ const utf8Encode = new TextEncoder();
|
|||||||
const utf8Decode = new TextDecoder('utf-8', { ignoreBOM: true });
|
const utf8Decode = new TextDecoder('utf-8', { ignoreBOM: true });
|
||||||
const commandExistsSync = require('command-exists').sync;
|
const commandExistsSync = require('command-exists').sync;
|
||||||
|
|
||||||
const config = require(path.join(__dirname, './config.conf'));
|
const config = require(path.join(process.cwd(), './config.conf'));
|
||||||
const server_port = process.env.SILLY_TAVERN_PORT || config.port;
|
const server_port = process.env.SILLY_TAVERN_PORT || config.port;
|
||||||
|
|
||||||
const whitelistPath = path.join(__dirname, "./whitelist.txt");
|
const whitelistPath = path.join(process.cwd(), "./whitelist.txt");
|
||||||
let whitelist = config.whitelist;
|
let whitelist = config.whitelist;
|
||||||
|
|
||||||
if (fs.existsSync(whitelistPath)) {
|
if (fs.existsSync(whitelistPath)) {
|
||||||
@@ -259,7 +262,7 @@ app.use((req, res, next) => {
|
|||||||
console.log(filePath);
|
console.log(filePath);
|
||||||
fs.access(filePath, fs.constants.R_OK, (err) => {
|
fs.access(filePath, fs.constants.R_OK, (err) => {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
res.sendFile(filePath, { root: __dirname });
|
res.sendFile(filePath, { root: process.cwd() });
|
||||||
} else {
|
} else {
|
||||||
res.send('Character not found: ' + filePath);
|
res.send('Character not found: ' + filePath);
|
||||||
//next();
|
//next();
|
||||||
@@ -270,10 +273,10 @@ app.use((req, res, next) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use(express.static(__dirname + "/public", { refresh: true }));
|
app.use(express.static(process.cwd() + "/public", { refresh: true }));
|
||||||
|
|
||||||
app.use('/backgrounds', (req, res) => {
|
app.use('/backgrounds', (req, res) => {
|
||||||
const filePath = decodeURIComponent(path.join(__dirname, 'public/backgrounds', req.url.replace(/%20/g, ' ')));
|
const filePath = decodeURIComponent(path.join(process.cwd(), 'public/backgrounds', req.url.replace(/%20/g, ' ')));
|
||||||
fs.readFile(filePath, (err, data) => {
|
fs.readFile(filePath, (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
res.status(404).send('File not found');
|
res.status(404).send('File not found');
|
||||||
@@ -285,7 +288,7 @@ app.use('/backgrounds', (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.use('/characters', (req, res) => {
|
app.use('/characters', (req, res) => {
|
||||||
const filePath = decodeURIComponent(path.join(__dirname, charactersPath, req.url.replace(/%20/g, ' ')));
|
const filePath = decodeURIComponent(path.join(process.cwd(), charactersPath, req.url.replace(/%20/g, ' ')));
|
||||||
fs.readFile(filePath, (err, data) => {
|
fs.readFile(filePath, (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
res.status(404).send('File not found');
|
res.status(404).send('File not found');
|
||||||
@@ -296,16 +299,16 @@ app.use('/characters', (req, res) => {
|
|||||||
});
|
});
|
||||||
app.use(multer({ dest: "uploads" }).single("avatar"));
|
app.use(multer({ dest: "uploads" }).single("avatar"));
|
||||||
app.get("/", function (request, response) {
|
app.get("/", function (request, response) {
|
||||||
response.sendFile(__dirname + "/public/index.html");
|
response.sendFile(process.cwd() + "/public/index.html");
|
||||||
});
|
});
|
||||||
app.get("/notes/*", function (request, response) {
|
app.get("/notes/*", function (request, response) {
|
||||||
response.sendFile(__dirname + "/public" + request.url + ".html");
|
response.sendFile(process.cwd() + "/public" + request.url + ".html");
|
||||||
});
|
});
|
||||||
app.get('/get_faq', function (_, response) {
|
app.get('/get_faq', function (_, response) {
|
||||||
response.sendFile(__dirname + "/faq.md");
|
response.sendFile(process.cwd() + "/faq.md");
|
||||||
});
|
});
|
||||||
app.get('/get_readme', function (_, response) {
|
app.get('/get_readme', function (_, response) {
|
||||||
response.sendFile(__dirname + "/readme.md");
|
response.sendFile(process.cwd() + "/readme.md");
|
||||||
});
|
});
|
||||||
app.get('/deviceinfo', function (request, response) {
|
app.get('/deviceinfo', function (request, response) {
|
||||||
const userAgent = request.header('user-agent');
|
const userAgent = request.header('user-agent');
|
||||||
@@ -658,13 +661,13 @@ function getVersion() {
|
|||||||
try {
|
try {
|
||||||
const pkgJson = require('./package.json');
|
const pkgJson = require('./package.json');
|
||||||
pkgVersion = pkgJson.version;
|
pkgVersion = pkgJson.version;
|
||||||
if (commandExistsSync('git')) {
|
if (!process.pkg && commandExistsSync('git')) {
|
||||||
gitRevision = require('child_process')
|
gitRevision = require('child_process')
|
||||||
.execSync('git rev-parse --short HEAD', { cwd: __dirname })
|
.execSync('git rev-parse --short HEAD', { cwd: process.cwd() })
|
||||||
.toString().trim();
|
.toString().trim();
|
||||||
|
|
||||||
gitBranch = require('child_process')
|
gitBranch = require('child_process')
|
||||||
.execSync('git rev-parse --abbrev-ref HEAD', { cwd: __dirname })
|
.execSync('git rev-parse --abbrev-ref HEAD', { cwd: process.cwd() })
|
||||||
.toString().trim();
|
.toString().trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1694,7 +1697,7 @@ app.post("/exportcharacter", jsonParser, async function (request, response) {
|
|||||||
|
|
||||||
switch (request.body.format) {
|
switch (request.body.format) {
|
||||||
case 'png':
|
case 'png':
|
||||||
return response.sendFile(filename, { root: __dirname });
|
return response.sendFile(filename, { root: process.cwd() });
|
||||||
case 'json': {
|
case 'json': {
|
||||||
try {
|
try {
|
||||||
let json = await charaRead(filename);
|
let json = await charaRead(filename);
|
||||||
@@ -1724,7 +1727,7 @@ app.post("/exportcharacter", jsonParser, async function (request, response) {
|
|||||||
await webp.cwebp(filename, inputWebpPath, '-q 95');
|
await webp.cwebp(filename, inputWebpPath, '-q 95');
|
||||||
await webp.webpmux_add(inputWebpPath, outputWebpPath, metadataPath, 'exif');
|
await webp.webpmux_add(inputWebpPath, outputWebpPath, metadataPath, 'exif');
|
||||||
|
|
||||||
response.sendFile(outputWebpPath, { root: __dirname }, () => {
|
response.sendFile(outputWebpPath, { root: process.cwd() }, () => {
|
||||||
fs.rmSync(inputWebpPath);
|
fs.rmSync(inputWebpPath);
|
||||||
fs.rmSync(metadataPath);
|
fs.rmSync(metadataPath);
|
||||||
fs.rmSync(outputWebpPath);
|
fs.rmSync(outputWebpPath);
|
||||||
@@ -2369,7 +2372,7 @@ app.get('/thumbnail', jsonParser, async function (request, response) {
|
|||||||
|
|
||||||
if (config.disableThumbnails == true) {
|
if (config.disableThumbnails == true) {
|
||||||
const pathToOriginalFile = path.join(getOriginalFolder(type), file);
|
const pathToOriginalFile = path.join(getOriginalFolder(type), file);
|
||||||
return response.sendFile(pathToOriginalFile, { root: __dirname });
|
return response.sendFile(pathToOriginalFile, { root: process.cwd() });
|
||||||
}
|
}
|
||||||
|
|
||||||
const pathToCachedFile = await generateThumbnail(type, file);
|
const pathToCachedFile = await generateThumbnail(type, file);
|
||||||
@@ -2378,7 +2381,7 @@ app.get('/thumbnail', jsonParser, async function (request, response) {
|
|||||||
return response.sendStatus(404);
|
return response.sendStatus(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.sendFile(pathToCachedFile, { root: __dirname });
|
return response.sendFile(pathToCachedFile, { root: process.cwd() });
|
||||||
});
|
});
|
||||||
|
|
||||||
/* OpenAI */
|
/* OpenAI */
|
||||||
|
@@ -3,9 +3,11 @@
|
|||||||
* allow access to the endpoint after successful authentication.
|
* allow access to the endpoint after successful authentication.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const {dirname} = require('path');
|
//const {dirname} = require('path');
|
||||||
const appDir = dirname(require.main.filename);
|
//const appDir = dirname(require.main.filename);
|
||||||
const config = require(appDir + '/config.conf');
|
//const config = require(appDir + '/config.conf');
|
||||||
|
const path = require('path');
|
||||||
|
const config = require(path.join(process.cwd(), './config.conf'));
|
||||||
|
|
||||||
const unauthorizedResponse = (res) => {
|
const unauthorizedResponse = (res) => {
|
||||||
res.set('WWW-Authenticate', 'Basic realm="SillyTavern", charset="UTF-8"');
|
res.set('WWW-Authenticate', 'Basic realm="SillyTavern", charset="UTF-8"');
|
||||||
|
Reference in New Issue
Block a user