Skip to content

Commit 6ed619e

Browse files
author
prima
committed
feat: Autosave and server sync expansion
1 parent b29f0ab commit 6ed619e

File tree

9 files changed

+375
-132
lines changed

9 files changed

+375
-132
lines changed

embd_res/css/esoStyling.css

Lines changed: 15 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

embd_res/css/popupUtils.css

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@
4343
box-sizing: border-box;
4444
}
4545

46-
#popupContainer .popupContent input::placeholder,
47-
#popupContainer .popupContent textarea::placeholder {
48-
color: #666;
49-
}
50-
5146
.containAndScaleImage.tile {
5247
height: 128px;
5348
width: 128px;
@@ -83,7 +78,7 @@
8378
}
8479

8580
.characterCreatorGrid {
86-
color: white;
81+
color: var(--theme_color_text);
8782
padding: 10px;
8883
display: grid;
8984
grid-template-columns: 1fr 1fr;

embd_res/js/autosaveToServer.js

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,26 @@
11
let originalIndexDBSave = indexeddb_save
22
let numberOfActionsBetweenSaves = 5, currentTurn = 0
33
indexeddb_save = async (name, data) => {
4-
if (is_using_kcpp_with_server_saving() && !!localsettings?.enableAutosaveToServer) {
5-
if (name === "story") {
6-
if (currentTurn === numberOfActionsBetweenSaves) {
7-
try {
8-
await fetch(`${custom_kobold_endpoint}/api/data/delete`, {
9-
method: "POST",
10-
headers: getAuthHeaders(),
11-
body: JSON.stringify({ filename: "Autosave" })
12-
})
13-
.catch(e => {
14-
15-
})
16-
17-
let data = generate_compressed_story(true, true, true)
18-
let bodyData = {
19-
filename: "Autosave",
20-
data: btoa(data),
21-
type: "Save",
22-
isEncrypted: "0",
23-
group: "Public (can be accessed by anybody)",
24-
type: null,
25-
thumbnail: null
26-
};
27-
fetch(`${custom_kobold_endpoint}/api/data/put`, {
28-
method: "POST",
29-
body: JSON.stringify(bodyData),
30-
headers: getAuthHeaders()
31-
})
32-
.then(resp => resp.json())
33-
.catch(e => {
34-
handleError(e)
35-
})
36-
}
37-
catch (e) {
38-
console.error(e)
4+
if (name === "story") {
5+
if (currentTurn === numberOfActionsBetweenSaves)
6+
{
7+
try
8+
{
9+
let remoteDataSettings = JSON.parse(await indexeddb_load("remoteDataSettings"))
10+
if (!!remoteDataSettings) {
11+
let { remoteDataStorageUrl, autosaveName, autosaveMaxNumber, autosaveRemoteSync } = remoteDataSettings;
12+
await syncAutosave(autosaveName, true)
3913
}
40-
41-
currentTurn = 0
4214
}
43-
else {
44-
currentTurn++
15+
catch (e)
16+
{
17+
console.error("Error during autosave", e)
4518
}
19+
currentTurn = 0
20+
}
21+
else
22+
{
23+
currentTurn++
4624
}
4725
}
4826

0 commit comments

Comments
 (0)