mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'main' into dev
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 2.9 KiB |
Binary file not shown.
Before Width: | Height: | Size: 396 KiB After Width: | Height: | Size: 396 KiB |
Binary file not shown.
Before Width: | Height: | Size: 420 KiB After Width: | Height: | Size: 420 KiB |
File diff suppressed because it is too large
Load Diff
@ -10,7 +10,7 @@ let extensions = [];
|
|||||||
<h3>Extensions</h3>
|
<h3>Extensions</h3>
|
||||||
<input id="extensions_url" type="text" class="text_pole" />
|
<input id="extensions_url" type="text" class="text_pole" />
|
||||||
<div class="extensions_url_block">
|
<div class="extensions_url_block">
|
||||||
<input id="extensions_connect" type="submit" value="Connect" />
|
<input id="extensions_connect" class="menu_button" type="submit" value="Connect" />
|
||||||
<span class="expander"></span>
|
<span class="expander"></span>
|
||||||
<input id="extensions_autoconnect" type="checkbox"/><h4>Auto-connect</h4>
|
<input id="extensions_autoconnect" type="checkbox"/><h4>Auto-connect</h4>
|
||||||
</div>
|
</div>
|
||||||
@ -214,8 +214,9 @@ let extensions = [];
|
|||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(async function () {
|
$(document).ready(async function () {
|
||||||
|
debugger;
|
||||||
const url = localStorage.getItem(extensions_urlKey) ?? defaultUrl;
|
const url = localStorage.getItem(extensions_urlKey) ?? defaultUrl;
|
||||||
const autoConnect = Boolean(localStorage.getItem(extensions_autoConnectKey)) ?? false;
|
const autoConnect = localStorage.getItem(extensions_autoConnectKey) == 'true';
|
||||||
$('#rm_api_block').append(settings_html);
|
$('#rm_api_block').append(settings_html);
|
||||||
$('head').append(settings_style);
|
$('head').append(settings_style);
|
||||||
$("#extensions_url").val(url);
|
$("#extensions_url").val(url);
|
||||||
|
822
public/style.css
822
public/style.css
File diff suppressed because it is too large
Load Diff
103
server.js
103
server.js
@ -58,16 +58,20 @@ var api_key_novel;
|
|||||||
//New chats made with characters will use this new formatting.
|
//New chats made with characters will use this new formatting.
|
||||||
//Useable variable is (( humanizedISO8601Datetime ))
|
//Useable variable is (( humanizedISO8601Datetime ))
|
||||||
|
|
||||||
var baseDate = new Date(Date.now());
|
|
||||||
var humanYear = baseDate.getFullYear();
|
|
||||||
var humanMonth = (baseDate.getMonth()+1);
|
|
||||||
var humanDate = baseDate.getDate();
|
|
||||||
var humanHour = (baseDate.getHours() < 10? '0' : '') + baseDate.getHours();
|
|
||||||
var humanMinute = (baseDate.getMinutes() < 10? '0' : '') + baseDate.getMinutes();
|
|
||||||
var humanSecond = (baseDate.getSeconds() < 10? '0' : '') + baseDate.getSeconds();
|
|
||||||
var humanMillisecond = (baseDate.getMilliseconds() < 10? '0' : '') + baseDate.getMilliseconds();
|
|
||||||
|
|
||||||
var humanizedISO8601DateTime = (humanYear+"-"+humanMonth+"-"+humanDate+" @"+humanHour+"h "+humanMinute+"m "+humanSecond+"s "+humanMillisecond+"ms");
|
|
||||||
|
function humanizedISO8601DateTime() {
|
||||||
|
let baseDate = new Date(Date.now());
|
||||||
|
let humanYear = baseDate.getFullYear();
|
||||||
|
let humanMonth = (baseDate.getMonth()+1);
|
||||||
|
let humanDate = baseDate.getDate();
|
||||||
|
let humanHour = (baseDate.getHours() < 10? '0' : '') + baseDate.getHours();
|
||||||
|
let humanMinute = (baseDate.getMinutes() < 10? '0' : '') + baseDate.getMinutes();
|
||||||
|
let humanSecond = (baseDate.getSeconds() < 10? '0' : '') + baseDate.getSeconds();
|
||||||
|
let humanMillisecond = (baseDate.getMilliseconds() < 10? '0' : '') + baseDate.getMilliseconds();
|
||||||
|
let HumanizedDateTime = (humanYear+"-"+humanMonth+"-"+humanDate+" @"+humanHour+"h "+humanMinute+"m "+humanSecond+"s "+humanMillisecond+"ms");
|
||||||
|
return HumanizedDateTime;
|
||||||
|
};
|
||||||
|
|
||||||
var is_colab = false;
|
var is_colab = false;
|
||||||
var charactersPath = 'public/characters/';
|
var charactersPath = 'public/characters/';
|
||||||
@ -288,7 +292,7 @@ app.post("/generate", jsonParser, function(request, response_generate = response
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
app.post("/savechat", jsonParser, function(request, response){
|
app.post("/savechat", jsonParser, function(request, response){
|
||||||
//console.log('/savechat/ entered');
|
//console.log(humanizedISO8601DateTime()+':/savechat/ entered');
|
||||||
//console.log(request.data);
|
//console.log(request.data);
|
||||||
//console.log(request.body.bg);
|
//console.log(request.body.bg);
|
||||||
//const data = request.body;
|
//const data = request.body;
|
||||||
@ -296,8 +300,10 @@ app.post("/savechat", jsonParser, function(request, response){
|
|||||||
//console.log(request.body.chat);
|
//console.log(request.body.chat);
|
||||||
//var bg = "body {background-image: linear-gradient(rgba(19,21,44,0.75), rgba(19,21,44,0.75)), url(../backgrounds/"+request.body.bg+");}";
|
//var bg = "body {background-image: linear-gradient(rgba(19,21,44,0.75), rgba(19,21,44,0.75)), url(../backgrounds/"+request.body.bg+");}";
|
||||||
var dir_name = String(request.body.avatar_url).replace('.png','');
|
var dir_name = String(request.body.avatar_url).replace('.png','');
|
||||||
|
//console.log(humanizedISO8601DateTime()+':/savechat sees '+dir_name+' as the character name (derived from avatar PNG filename)');
|
||||||
let chat_data = request.body.chat;
|
let chat_data = request.body.chat;
|
||||||
let jsonlData = chat_data.map(JSON.stringify).join('\n');
|
let jsonlData = chat_data.map(JSON.stringify).join('\n');
|
||||||
|
//console.log(humanizedISO8601DateTime()+':/savechat saving a chat named '+request.body.file_name+'.jsonl');
|
||||||
fs.writeFile(chatsPath+dir_name+"/"+request.body.file_name+'.jsonl', jsonlData, 'utf8', function(err) {
|
fs.writeFile(chatsPath+dir_name+"/"+request.body.file_name+'.jsonl', jsonlData, 'utf8', function(err) {
|
||||||
if(err) {
|
if(err) {
|
||||||
response.send(err);
|
response.send(err);
|
||||||
@ -317,7 +323,7 @@ app.post("/getchat", jsonParser, function(request, response){
|
|||||||
//console.log(request);
|
//console.log(request);
|
||||||
//console.log(request.body.chat);
|
//console.log(request.body.chat);
|
||||||
//var bg = "body {background-image: linear-gradient(rgba(19,21,44,0.75), rgba(19,21,44,0.75)), url(../backgrounds/"+request.body.bg+");}";
|
//var bg = "body {background-image: linear-gradient(rgba(19,21,44,0.75), rgba(19,21,44,0.75)), url(../backgrounds/"+request.body.bg+");}";
|
||||||
//console.log('/getchat entered');
|
//console.log(humanizedISO8601DateTime()+':/getchat entered');
|
||||||
var dir_name = String(request.body.avatar_url).replace('.png','');
|
var dir_name = String(request.body.avatar_url).replace('.png','');
|
||||||
|
|
||||||
fs.stat(chatsPath+dir_name, function(err, stat) {
|
fs.stat(chatsPath+dir_name, function(err, stat) {
|
||||||
@ -334,7 +340,7 @@ app.post("/getchat", jsonParser, function(request, response){
|
|||||||
fs.stat(chatsPath+dir_name+"/"+request.body.file_name+".jsonl", function(err, stat) {
|
fs.stat(chatsPath+dir_name+"/"+request.body.file_name+".jsonl", function(err, stat) {
|
||||||
|
|
||||||
if (err === null) { //if no error (the file exists), read the file
|
if (err === null) { //if no error (the file exists), read the file
|
||||||
|
//console.log(humanizedISO8601DateTime()+':/getchat tries to access: '+chatsPath+dir_name+'/'+request.body.file_name+'.jsonl');
|
||||||
if(stat !== undefined){
|
if(stat !== undefined){
|
||||||
fs.readFile(chatsPath+dir_name+"/"+request.body.file_name+".jsonl", 'utf8', (err, data) => {
|
fs.readFile(chatsPath+dir_name+"/"+request.body.file_name+".jsonl", 'utf8', (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -362,11 +368,8 @@ app.post("/getchat", jsonParser, function(request, response){
|
|||||||
console.error(err);
|
console.error(err);
|
||||||
response.send({});
|
response.send({});
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -466,27 +469,29 @@ function checkServer(){
|
|||||||
|
|
||||||
//***************** Main functions
|
//***************** Main functions
|
||||||
function charaFormatData(data){
|
function charaFormatData(data){
|
||||||
var char = {"name": data.ch_name, "description": data.description, "personality": data.personality, "first_mes": data.first_mes, "avatar": 'none', "chat": Date.now(), "mes_example": data.mes_example, "scenario": data.scenario, "create_date": Date.now(), "talkativeness": data.talkativeness};
|
var char = {"name": data.ch_name, "description": data.description, "personality": data.personality, "first_mes": data.first_mes, "avatar": 'none', "chat": data.ch_name+' - '+humanizedISO8601DateTime(), "mes_example": data.mes_example, "scenario": data.scenario, "create_date": humanizedISO8601DateTime, "talkativeness": data.talkativeness};
|
||||||
return char;
|
return char;
|
||||||
}
|
}
|
||||||
app.post("/createcharacter", urlencodedParser, function(request, response){
|
app.post("/createcharacter", urlencodedParser, function(request, response){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//var sameNameChar = fs.existsSync(charactersPath+request.body.ch_name+'.png');
|
||||||
|
//if (sameNameChar == true) return response.sendStatus(500);
|
||||||
if(!request.body) return response.sendStatus(400);
|
if(!request.body) return response.sendStatus(400);
|
||||||
|
console.log('/createcharacter -- looking for -- '+(charactersPath+request.body.ch_name+'.png'));
|
||||||
|
console.log('Does this file already exists? '+fs.existsSync(charactersPath+request.body.ch_name+'.png'));
|
||||||
if (!fs.existsSync(charactersPath+request.body.ch_name+'.png')){
|
if (!fs.existsSync(charactersPath+request.body.ch_name+'.png')){
|
||||||
if(!fs.existsSync(chatsPath+request.body.ch_name) )fs.mkdirSync(chatsPath+request.body.ch_name);
|
if(!fs.existsSync(chatsPath+request.body.ch_name) )fs.mkdirSync(chatsPath+request.body.ch_name);
|
||||||
|
|
||||||
let filedata = request.file;
|
let filedata = request.file;
|
||||||
//console.log(filedata.mimetype);
|
//console.log(filedata.mimetype);
|
||||||
var fileType = ".png";
|
var fileType = ".png";
|
||||||
var img_file = "ai";
|
var img_file = "ai";
|
||||||
var img_path = "public/img/";
|
var img_path = "public/img/";
|
||||||
|
|
||||||
var char = charaFormatData(request.body);//{"name": request.body.ch_name, "description": request.body.description, "personality": request.body.personality, "first_mes": request.body.first_mes, "avatar": 'none', "chat": Date.now(), "last_mes": '', "mes_example": ''};
|
var char = charaFormatData(request.body);//{"name": request.body.ch_name, "description": request.body.description, "personality": request.body.personality, "first_mes": request.body.first_mes, "avatar": 'none', "chat": Date.now(), "last_mes": '', "mes_example": ''};
|
||||||
char = JSON.stringify(char);
|
char = JSON.stringify(char);
|
||||||
if(!filedata){
|
if(!filedata){
|
||||||
|
|
||||||
charaWrite('./public/img/fluffy.png', char, request.body.ch_name, response);
|
charaWrite('./public/img/fluffy.png', char, request.body.ch_name, response);
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
img_path = "./uploads/";
|
img_path = "./uploads/";
|
||||||
@ -500,7 +505,9 @@ app.post("/createcharacter", urlencodedParser, function(request, response){
|
|||||||
//console.log("The file was saved.");
|
//console.log("The file was saved.");
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
console.error("Error: Cannot save file. A character with that name already exists.");
|
||||||
response.send("Error: A character with that name already exists.");
|
response.send("Error: A character with that name already exists.");
|
||||||
|
//response.send({error: true});
|
||||||
}
|
}
|
||||||
//console.log(request.body);
|
//console.log(request.body);
|
||||||
//response.send(request.body.ch_name);
|
//response.send(request.body.ch_name);
|
||||||
@ -1020,12 +1027,14 @@ app.post("/getallchatsofcharacter", jsonParser, function(request, response){
|
|||||||
var char_dir = (request.body.avatar_url).replace('.png','')
|
var char_dir = (request.body.avatar_url).replace('.png','')
|
||||||
fs.readdir(chatsPath+char_dir, (err, files) => {
|
fs.readdir(chatsPath+char_dir, (err, files) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
console.log('found error in history loading');
|
||||||
console.error(err);
|
console.error(err);
|
||||||
response.send({error: true});
|
response.send({error: true});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter for JSON files
|
// filter for JSON files
|
||||||
|
console.log('looking for JSONL files');
|
||||||
const jsonFiles = files.filter(file => path.extname(file) === '.jsonl');
|
const jsonFiles = files.filter(file => path.extname(file) === '.jsonl');
|
||||||
|
|
||||||
// sort the files by name
|
// sort the files by name
|
||||||
@ -1033,10 +1042,10 @@ app.post("/getallchatsofcharacter", jsonParser, function(request, response){
|
|||||||
// print the sorted file names
|
// print the sorted file names
|
||||||
var chatData = {};
|
var chatData = {};
|
||||||
let ii = jsonFiles.length; //this is the number of files belonging to the character
|
let ii = jsonFiles.length; //this is the number of files belonging to the character
|
||||||
|
if (ii !== 0) {
|
||||||
|
//console.log('found '+ii+' chat logs to load');
|
||||||
for(let i = jsonFiles.length-1; i >= 0; i--){
|
for(let i = jsonFiles.length-1; i >= 0; i--){
|
||||||
const file = jsonFiles[i];
|
const file = jsonFiles[i];
|
||||||
|
|
||||||
const fileStream = fs.createReadStream(chatsPath+char_dir+'/'+file);
|
const fileStream = fs.createReadStream(chatsPath+char_dir+'/'+file);
|
||||||
const rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
input: fileStream,
|
input: fileStream,
|
||||||
@ -1056,18 +1065,23 @@ app.post("/getallchatsofcharacter", jsonParser, function(request, response){
|
|||||||
chatData[i]['mes'] = jsonData['mes'];
|
chatData[i]['mes'] = jsonData['mes'];
|
||||||
ii--;
|
ii--;
|
||||||
if(ii === 0){
|
if(ii === 0){
|
||||||
|
console.log('ii count went to zero, responding with chatData');
|
||||||
response.send(chatData);
|
response.send(chatData);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
console.log('just returning from getallchatsofcharacter');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log('successfully closing getallchatsofcharacter');
|
||||||
rl.close();
|
rl.close();
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
});
|
}else{
|
||||||
|
//console.log('Found No Chats. Exiting Load Routine.');
|
||||||
});
|
response.send({error: true});
|
||||||
|
};
|
||||||
|
})});
|
||||||
function getPngName(file){
|
function getPngName(file){
|
||||||
let i = 1;
|
let i = 1;
|
||||||
let base_name = file;
|
let base_name = file;
|
||||||
@ -1078,6 +1092,7 @@ function getPngName(file){
|
|||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
app.post("/importcharacter", urlencodedParser, async function(request, response){
|
app.post("/importcharacter", urlencodedParser, async function(request, response){
|
||||||
|
|
||||||
if(!request.body) return response.sendStatus(400);
|
if(!request.body) return response.sendStatus(400);
|
||||||
|
|
||||||
let png_name = '';
|
let png_name = '';
|
||||||
@ -1094,24 +1109,20 @@ app.post("/importcharacter", urlencodedParser, async function(request, response)
|
|||||||
}
|
}
|
||||||
const jsonData = JSON.parse(data);
|
const jsonData = JSON.parse(data);
|
||||||
|
|
||||||
try {
|
|
||||||
if(jsonData.name !== undefined){
|
if(jsonData.name !== undefined){
|
||||||
png_name = getPngName(jsonData.name);
|
png_name = getPngName(jsonData.name);
|
||||||
let char = {"name": jsonData.name, "description": jsonData.description ?? '', "personality": jsonData.personality ?? '', "first_mes": jsonData.first_mes ?? '', "avatar": 'none', "chat": Date.now(), "mes_example": jsonData.mes_example ?? '', "scenario": jsonData.scenario ?? '', "create_date": Date.now(), "talkativeness": jsonData.talkativeness ?? 0.5};
|
let char = {"name": jsonData.name, "description": jsonData.description ?? '', "personality": jsonData.personality ?? '', "first_mes": jsonData.first_mes ?? '', "avatar": 'none', "chat": humanizedISO8601DateTime(), "mes_example": jsonData.mes_example ?? '', "scenario": jsonData.scenario ?? '', "create_date": humanizedISO8601DateTime, "talkativeness": jsonData.talkativeness ?? 0.5};
|
||||||
char = JSON.stringify(char);
|
char = JSON.stringify(char);
|
||||||
await charaWrite('./public/img/fluffy.png', char, png_name, response, {file_name: png_name});
|
charaWrite('./public/img/fluffy.png', char, png_name, response, {file_name: png_name});
|
||||||
}else if(jsonData.char_name !== undefined){//json Pygmalion notepad
|
}else if(jsonData.char_name !== undefined){//json Pygmalion notepad
|
||||||
png_name = getPngName(jsonData.char_name);
|
png_name = getPngName(jsonData.char_name);
|
||||||
let char = {"name": jsonData.char_name, "description": jsonData.char_persona ?? '', "personality": '', "first_mes": jsonData.char_greeting ?? '', "avatar": 'none', "chat": Date.now(), "mes_example": jsonData.example_dialogue ?? '', "scenario": jsonData.world_scenario ?? '', "create_date": Date.now(), "talkativeness": jsonData.talkativeness ?? 0.5};
|
let char = {"name": jsonData.char_name, "description": jsonData.char_persona ?? '', "personality": '', "first_mes": jsonData.char_greeting ?? '', "avatar": 'none', "chat": humanizedISO8601DateTime(), "mes_example": jsonData.example_dialogue ?? '', "scenario": jsonData.world_scenario ?? '', "create_date": humanizedISO8601DateTime, "talkativeness": jsonData.talkativeness ?? 0.5};
|
||||||
char = JSON.stringify(char);
|
char = JSON.stringify(char);
|
||||||
await charaWrite('./public/img/fluffy.png', char, png_name, response, {file_name: png_name});
|
charaWrite('./public/img/fluffy.png', char, png_name, response, {file_name: png_name});
|
||||||
}else{
|
}else{
|
||||||
console.log('Incorrect character format .json');
|
console.log('Incorrect character format .json');
|
||||||
response.send({error:true});
|
response.send({error:true});
|
||||||
}
|
}
|
||||||
} catch {
|
|
||||||
response.send({ error: true });
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
try{
|
try{
|
||||||
@ -1121,7 +1132,7 @@ app.post("/importcharacter", urlencodedParser, async function(request, response)
|
|||||||
png_name = getPngName(jsonData.name);
|
png_name = getPngName(jsonData.name);
|
||||||
|
|
||||||
if(jsonData.name !== undefined){
|
if(jsonData.name !== undefined){
|
||||||
let char = {"name": jsonData.name, "description": jsonData.description ?? '', "personality": jsonData.personality ?? '', "first_mes": jsonData.first_mes ?? '', "avatar": 'none', "chat": Date.now(), "mes_example": jsonData.mes_example ?? '', "scenario": jsonData.scenario ?? '', "create_date": Date.now(), "talkativeness": jsonData.talkativeness ?? 0.5};
|
let char = {"name": jsonData.name, "description": jsonData.description ?? '', "personality": jsonData.personality ?? '', "first_mes": jsonData.first_mes ?? '', "avatar": 'none', "chat": humanizedISO8601DateTime(), "mes_example": jsonData.mes_example ?? '', "scenario": jsonData.scenario ?? '', "create_date": humanizedISO8601DateTime, "talkativeness": jsonData.talkativeness ?? 0.5};
|
||||||
char = JSON.stringify(char);
|
char = JSON.stringify(char);
|
||||||
await charaWrite('./uploads/'+filedata.filename, char, png_name, response, {file_name: png_name});
|
await charaWrite('./uploads/'+filedata.filename, char, png_name, response, {file_name: png_name});
|
||||||
/*
|
/*
|
||||||
@ -1153,6 +1164,7 @@ app.post("/importcharacter", urlencodedParser, async function(request, response)
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.post("/importchat", urlencodedParser, function(request, response){
|
app.post("/importchat", urlencodedParser, function(request, response){
|
||||||
|
//console.log(humanizedISO8601DateTime()+':/importchat begun');
|
||||||
if(!request.body) return response.sendStatus(400);
|
if(!request.body) return response.sendStatus(400);
|
||||||
|
|
||||||
var format = request.body.file_type;
|
var format = request.body.file_type;
|
||||||
@ -1176,11 +1188,12 @@ app.post("/importchat", urlencodedParser, function(request, response){
|
|||||||
const jsonData = JSON.parse(data);
|
const jsonData = JSON.parse(data);
|
||||||
var new_chat = [];
|
var new_chat = [];
|
||||||
if(jsonData.histories !== undefined){
|
if(jsonData.histories !== undefined){
|
||||||
|
//console.log('/importchat confirms JSON histories are defined');
|
||||||
let i = 0;
|
let i = 0;
|
||||||
new_chat[i] = {};
|
new_chat[i] = {};
|
||||||
new_chat[0]['user_name'] = 'You';
|
new_chat[0]['user_name'] = 'You';
|
||||||
new_chat[0]['character_name'] = ch_name;
|
new_chat[0]['character_name'] = ch_name;
|
||||||
new_chat[0]['create_date'] = Date.now() //Date.now();
|
new_chat[0]['create_date'] = humanizedISO8601DateTime() //Date.now();
|
||||||
i++;
|
i++;
|
||||||
jsonData.histories.histories[0].msgs.forEach(function(item) {
|
jsonData.histories.histories[0].msgs.forEach(function(item) {
|
||||||
new_chat[i] = {};
|
new_chat[i] = {};
|
||||||
@ -1191,12 +1204,13 @@ app.post("/importchat", urlencodedParser, function(request, response){
|
|||||||
}
|
}
|
||||||
new_chat[i]['is_user'] = item.src.is_human;
|
new_chat[i]['is_user'] = item.src.is_human;
|
||||||
new_chat[i]['is_name'] = true;
|
new_chat[i]['is_name'] = true;
|
||||||
new_chat[i]['send_date'] = Date.now() //Date.now();
|
new_chat[i]['send_date'] = humanizedISO8601DateTime() //Date.now();
|
||||||
new_chat[i]['mes'] = item.text;
|
new_chat[i]['mes'] = item.text;
|
||||||
i++;
|
i++;
|
||||||
});
|
});
|
||||||
const chatJsonlData = new_chat.map(JSON.stringify).join('\n');
|
const chatJsonlData = new_chat.map(JSON.stringify).join('\n');
|
||||||
fs.writeFile(chatsPath+avatar_url+'/'+ch_name+' - '+humanizedISO8601DateTime+' imported.jsonl', chatJsonlData, 'utf8', function(err) { //added ch_name and replaced Date.now() with humanizedISO8601DateTime
|
//console.log('/importchat saving a file: '+ch_name+' - '+humanizedISO8601DateTime()+' imported.jsonl');
|
||||||
|
fs.writeFile(chatsPath+avatar_url+'/'+ch_name+' - '+humanizedISO8601DateTime()+' imported.jsonl', chatJsonlData, 'utf8', function(err) { //added ch_name and replaced Date.now() with humanizedISO8601DateTime
|
||||||
|
|
||||||
if(err) {
|
if(err) {
|
||||||
response.send(err);
|
response.send(err);
|
||||||
@ -1216,6 +1230,7 @@ app.post("/importchat", urlencodedParser, function(request, response){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if(format === 'jsonl'){
|
if(format === 'jsonl'){
|
||||||
|
//console.log(humanizedISO8601DateTime()+':imported chat format is JSONL');
|
||||||
const fileStream = fs.createReadStream('./uploads/'+filedata.filename);
|
const fileStream = fs.createReadStream('./uploads/'+filedata.filename);
|
||||||
const rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
input: fileStream,
|
input: fileStream,
|
||||||
@ -1226,7 +1241,8 @@ app.post("/importchat", urlencodedParser, function(request, response){
|
|||||||
let jsonData = JSON.parse(line);
|
let jsonData = JSON.parse(line);
|
||||||
|
|
||||||
if(jsonData.user_name !== undefined){
|
if(jsonData.user_name !== undefined){
|
||||||
fs.copyFile('./uploads/'+filedata.filename, chatsPath+avatar_url+'/'+ch_name+' - '+humanizedISO8601DateTime+'.jsonl', (err) => { //added character name and replaced Date.now() with humanizedISO8601DateTime
|
//console.log(humanizedISO8601DateTime()+':/importchat copying chat as '+ch_name+' - '+humanizedISO8601DateTime()+'.jsonl');
|
||||||
|
fs.copyFile('./uploads/'+filedata.filename, chatsPath+avatar_url+'/'+ch_name+' - '+humanizedISO8601DateTime()+'.jsonl', (err) => { //added character name and replaced Date.now() with humanizedISO8601DateTime
|
||||||
if(err) {
|
if(err) {
|
||||||
response.send({error:true});
|
response.send({error:true});
|
||||||
return console.log(err);
|
return console.log(err);
|
||||||
@ -1524,7 +1540,7 @@ function convertStage2(){
|
|||||||
//console.log(directoriesB[key]);
|
//console.log(directoriesB[key]);
|
||||||
|
|
||||||
var char = JSON.parse(charactersB[key]);
|
var char = JSON.parse(charactersB[key]);
|
||||||
char.create_date = Date.now();
|
char.create_date = humanizedISO8601DateTime();
|
||||||
charactersB[key] = JSON.stringify(char);
|
charactersB[key] = JSON.stringify(char);
|
||||||
var avatar = 'public/img/fluffy.png';
|
var avatar = 'public/img/fluffy.png';
|
||||||
if(char.avatar !== 'none'){
|
if(char.avatar !== 'none'){
|
||||||
@ -1554,7 +1570,7 @@ function convertStage2(){
|
|||||||
}
|
}
|
||||||
let i = 0;
|
let i = 0;
|
||||||
let ii = 0;
|
let ii = 0;
|
||||||
new_chat_data[i] = {user_name:'You', character_name:char.name, create_date: Date.now()};
|
new_chat_data[i] = {user_name:'You', character_name:char.name, create_date: humanizedISO8601DateTime()};
|
||||||
i++;
|
i++;
|
||||||
ii++;
|
ii++;
|
||||||
chat_data.forEach(function(mes) {
|
chat_data.forEach(function(mes) {
|
||||||
@ -1570,14 +1586,14 @@ function convertStage2(){
|
|||||||
new_chat_data[ii]['name'] = char.name;
|
new_chat_data[ii]['name'] = char.name;
|
||||||
new_chat_data[ii]['is_user'] = false;
|
new_chat_data[ii]['is_user'] = false;
|
||||||
new_chat_data[ii]['is_name'] = is_name;
|
new_chat_data[ii]['is_name'] = is_name;
|
||||||
new_chat_data[ii]['send_date'] = Date.now(); //Date.now();
|
new_chat_data[ii]['send_date'] = humanizedISO8601DateTime(); //Date.now();
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
mes = mes.replace(this_chat_user_name+':','');
|
mes = mes.replace(this_chat_user_name+':','');
|
||||||
new_chat_data[ii]['name'] = 'You';
|
new_chat_data[ii]['name'] = 'You';
|
||||||
new_chat_data[ii]['is_user'] = true;
|
new_chat_data[ii]['is_user'] = true;
|
||||||
new_chat_data[ii]['is_name'] = true;
|
new_chat_data[ii]['is_name'] = true;
|
||||||
new_chat_data[ii]['send_date'] = Date.now() //Date.now();
|
new_chat_data[ii]['send_date'] = humanizedISO8601DateTime(); //Date.now();
|
||||||
|
|
||||||
}
|
}
|
||||||
new_chat_data[ii]['mes'] = mes.trim();
|
new_chat_data[ii]['mes'] = mes.trim();
|
||||||
@ -1589,6 +1605,7 @@ function convertStage2(){
|
|||||||
});
|
});
|
||||||
const jsonlData = new_chat_data.map(JSON.stringify).join('\n');
|
const jsonlData = new_chat_data.map(JSON.stringify).join('\n');
|
||||||
// Write the contents to the destination folder
|
// Write the contents to the destination folder
|
||||||
|
//console.log('convertstage2 writing a file: '+chatsPath+char.name+'/' + file+'l');
|
||||||
fs.writeFileSync(chatsPath+char.name+'/' + file+'l', jsonlData);
|
fs.writeFileSync(chatsPath+char.name+'/' + file+'l', jsonlData);
|
||||||
});
|
});
|
||||||
//fs.rmSync('public/characters/'+directoriesB[key],{ recursive: true });
|
//fs.rmSync('public/characters/'+directoriesB[key],{ recursive: true });
|
||||||
|
Reference in New Issue
Block a user