feat: import and export mood profiles
Add GET /api/moods/export (custom-only filter) and POST /api/moods/import with skip reporting, plus export/import controls in the recommendations panel.
This commit is contained in:
1 parent
987e52931f
commit
49a7ab9918
9 files changed
+220
-43
No files matched your search
@@ -944,6 +944,35 @@ $("#moodDelete").addEventListener("click", async () => {
|
||||
toast(err.message);
|
||||
}
|
||||
});
|
||||
$("#moodExport").addEventListener("click", () => {
|
||||
const link = document.createElement("a");
|
||||
link.href = "/api/moods/export?custom=1";
|
||||
link.download = "steambase-moods.json";
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
});
|
||||
$("#moodImport").addEventListener("click", () => $("#moodImportFile").click());
|
||||
$("#moodImportFile").addEventListener("change", async () => {
|
||||
const input = $("#moodImportFile");
|
||||
const file = input.files && input.files[0];
|
||||
if (!file) return;
|
||||
try {
|
||||
const payload = JSON.parse(await file.text());
|
||||
const data = await api("/api/moods/import", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
await loadMoods();
|
||||
const skipped = (data.skipped || []).length;
|
||||
toast(`Импорт: добавлено ${data.imported}, обновлено ${data.updated}` +
|
||||
(skipped ? `, пропущено ${skipped}` : ""));
|
||||
} catch (err) {
|
||||
toast(err.message);
|
||||
} finally {
|
||||
input.value = "";
|
||||
}
|
||||
});
|
||||
$("#meSave").addEventListener("click", async () => {
|
||||
const name = $("#meName").value.trim().toLowerCase();
|
||||
const tags = {};
|
||||
|
||||
@@ -251,6 +251,9 @@ try {
|
||||
<button id="moodCreate" class="link" type="button">+ свой профиль</button>
|
||||
<button id="moodEdit" class="link hidden" type="button">редактировать</button>
|
||||
<button id="moodDelete" class="link hidden" type="button">удалить</button>
|
||||
<button id="moodExport" class="link" type="button">экспорт</button>
|
||||
<button id="moodImport" class="link" type="button">импорт</button>
|
||||
<input id="moodImportFile" type="file" accept="application/json,.json" hidden>
|
||||
</div>
|
||||
<div id="moodEditor" class="mood-editor hidden">
|
||||
<div class="me-grid">
|
||||
|
||||
Reference in new issue
Block a user