|
1 | 1 | let originalIndexDBSave = indexeddb_save |
2 | 2 | let numberOfActionsBetweenSaves = 5, currentTurn = 0 |
3 | 3 | 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) |
39 | 13 | } |
40 | | - |
41 | | - currentTurn = 0 |
42 | 14 | } |
43 | | - else { |
44 | | - currentTurn++ |
| 15 | + catch (e) |
| 16 | + { |
| 17 | + console.error("Error during autosave", e) |
45 | 18 | } |
| 19 | + currentTurn = 0 |
| 20 | + } |
| 21 | + else |
| 22 | + { |
| 23 | + currentTurn++ |
46 | 24 | } |
47 | 25 | } |
48 | 26 |
|
|
0 commit comments