Add delete button for server saves
This commit is contained in:
@@ -5629,7 +5629,7 @@
|
|||||||
() => {
|
() => {
|
||||||
E.exportSavegamePrivateBin();
|
E.exportSavegamePrivateBin();
|
||||||
},
|
},
|
||||||
)}"><i class="fas fa-file-export"></i> ${e.T("settings-share-save-button", "Export save without file")}</button>\n <div id="savegameQR"></div>\n --\x3e\n </div>\n <div class="form-group">\n <h5 class="py-2 text-warning">Server Saves</h5>\n <div class="input-group mb-1">\n <input type="text" class="form-control bg-dark text-white" id="named-save-input" placeholder="Save name...">\n <div class="input-group-append">\n <button class="btn btn-outline-success" onclick="${wi.register(() => { E.exportNamedSave(); })}"><i class="fas fa-cloud-upload-alt"></i> Save on server</button>\n </div>\n </div>\n <input type="password" class="form-control bg-dark text-white mb-2" id="named-save-password" placeholder="Password (optional)">\n <small class="form-text text-muted mb-3">Upload a complete export to the server under a custom name.</small>\n <div class="input-group mt-2 mb-1">\n <select class="form-control bg-dark text-white" id="server-saves-select"><option value="">Loading saves...</option></select>\n <div class="input-group-append">\n <button class="btn btn-outline-warning" onclick="${wi.register(() => { E.importNamedSave(); })}"><i class="fas fa-cloud-download-alt"></i> Load from server</button>\n </div>\n </div>\n <input type="password" class="form-control bg-dark text-white mb-1" id="named-load-password" placeholder="Password (if protected)">\n <small class="form-text text-muted">Load a previously saved game from the server. This will overwrite your current progress.</small>\n </div>\n </div>\n </div>`;
|
)}"><i class="fas fa-file-export"></i> ${e.T("settings-share-save-button", "Export save without file")}</button>\n <div id="savegameQR"></div>\n --\x3e\n </div>\n <div class="form-group">\n <h5 class="py-2 text-warning">Server Saves</h5>\n <div class="input-group mb-1">\n <input type="text" class="form-control bg-dark text-white" id="named-save-input" placeholder="Save name...">\n <div class="input-group-append">\n <button class="btn btn-outline-success" onclick="${wi.register(() => { E.exportNamedSave(); })}"><i class="fas fa-cloud-upload-alt"></i> Save on server</button>\n </div>\n </div>\n <input type="password" class="form-control bg-dark text-white mb-2" id="named-save-password" placeholder="Password (optional)">\n <small class="form-text text-muted mb-3">Upload a complete export to the server under a custom name.</small>\n <div class="input-group mt-2 mb-1">\n <select class="form-control bg-dark text-white" id="server-saves-select"><option value="">Loading saves...</option></select>\n <div class="input-group-append">\n <button class="btn btn-outline-warning" onclick="${wi.register(() => { E.importNamedSave(); })}"><i class="fas fa-cloud-download-alt"></i> Load from server</button>\n <button class="btn btn-outline-danger" onclick="${wi.register(() => { E.deleteNamedSave(); })}"><i class="fas fa-trash"></i> Delete</button>\n </div>\n </div>\n <input type="password" class="form-control bg-dark text-white mb-1" id="named-load-password" placeholder="Password (if protected)">\n <small class="form-text text-muted">Load a previously saved game from the server. This will overwrite your current progress.</small>\n </div>\n </div>\n </div>`;
|
||||||
}
|
}
|
||||||
static mapManagementFormView() {
|
static mapManagementFormView() {
|
||||||
const e = s.getInstance();
|
const e = s.getInstance();
|
||||||
@@ -5941,6 +5941,26 @@
|
|||||||
n.showToast("Load failed", "Could not load the save from the server.", "danger");
|
n.showToast("Load failed", "Could not load the save from the server.", "danger");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static async deleteNamedSave() {
|
||||||
|
const save_name = $("#server-saves-select").val();
|
||||||
|
if (!save_name) return;
|
||||||
|
const password = $("#named-load-password").val();
|
||||||
|
try {
|
||||||
|
const headers = {};
|
||||||
|
if (password) headers["X-Password-Hash"] = await n.sha256_hex(password);
|
||||||
|
const res = await fetch(`https://pu-saves.burrson.de/saves/${encodeURIComponent(save_name)}`, { method: "DELETE", mode: "cors", headers });
|
||||||
|
if (res.status === 401) {
|
||||||
|
const msg = await res.text();
|
||||||
|
n.showToast("Access denied", msg.includes("required") ? "This save is password protected." : "Wrong password.", "danger");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!res.ok) throw "Not found";
|
||||||
|
n.showToast("Deleted", `Save "${save_name}" deleted from server.`, "success");
|
||||||
|
E.populateServerSaves();
|
||||||
|
} catch (e) {
|
||||||
|
n.showToast("Delete failed", "Could not delete the save from the server.", "danger");
|
||||||
|
}
|
||||||
|
}
|
||||||
static async importSaveGameClipboard() {
|
static async importSaveGameClipboard() {
|
||||||
const e = s.getInstance(),
|
const e = s.getInstance(),
|
||||||
t = {
|
t = {
|
||||||
|
|||||||
Reference in New Issue
Block a user