FIX: Đã fix cross-machine (v202608060500)
This commit is contained in:
+31
-2
@@ -14775,10 +14775,27 @@ const App = () => {
|
|||||||
if (!pendingWasNull) return;
|
if (!pendingWasNull) return;
|
||||||
|
|
||||||
var lastId = localStorage.getItem('sonic_project_id');
|
var lastId = localStorage.getItem('sonic_project_id');
|
||||||
if (!lastId) return;
|
|
||||||
var lastName = localStorage.getItem('sonic_project_name') || 'Dự án';
|
var lastName = localStorage.getItem('sonic_project_name') || 'Dự án';
|
||||||
try {
|
|
||||||
var parsed = null;
|
var parsed = null;
|
||||||
|
if (!lastId) {
|
||||||
|
// Máy mới / browser ẩn danh: localStorage TRỐNG (id/name không tồn tại
|
||||||
|
// trên máy này) → tự mở project Cloud GẦN NHẤT của tài khoản đang đăng
|
||||||
|
// nhập — project tạo trên máy khác vẫn mở được ngay.
|
||||||
|
const prof = currentUser || (function () { try { return JSON.parse(localStorage.getItem('sonic_user') || 'null'); } catch (e) { return null; } })();
|
||||||
|
if (prof && window.SonicAPI && window.SonicAPI.listCloudProjects) {
|
||||||
|
try {
|
||||||
|
const cloudList = await window.SonicAPI.listCloudProjects();
|
||||||
|
if (cloudList && cloudList.length > 0) {
|
||||||
|
const latest = cloudList[0]; // backend ORDER BY updated_at DESC
|
||||||
|
lastId = latest.id;
|
||||||
|
lastName = latest.name || lastName;
|
||||||
|
const proj = await window.SonicAPI.getCloudProject(lastId);
|
||||||
|
if (proj && proj.data_json) parsed = JSON.parse(proj.data_json);
|
||||||
|
}
|
||||||
|
} catch (e) { console.warn('restore cloud fallback error:', e); }
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
if (lastId.startsWith('local_')) {
|
if (lastId.startsWith('local_')) {
|
||||||
var localData = localStorage.getItem('sonic_local_project_data');
|
var localData = localStorage.getItem('sonic_local_project_data');
|
||||||
if (localData) parsed = JSON.parse(localData);
|
if (localData) parsed = JSON.parse(localData);
|
||||||
@@ -14786,6 +14803,9 @@ const App = () => {
|
|||||||
var proj = await window.SonicAPI.getCloudProject(lastId);
|
var proj = await window.SonicAPI.getCloudProject(lastId);
|
||||||
if (proj) parsed = JSON.parse(proj.data_json);
|
if (proj) parsed = JSON.parse(proj.data_json);
|
||||||
}
|
}
|
||||||
|
} catch (e) { console.warn('restore load error:', e); }
|
||||||
|
}
|
||||||
|
try {
|
||||||
if (!parsed) return;
|
if (!parsed) return;
|
||||||
var restoredBpm = bpm;
|
var restoredBpm = bpm;
|
||||||
var restoredTracks = [];
|
var restoredTracks = [];
|
||||||
@@ -21740,6 +21760,15 @@ const App = () => {
|
|||||||
setProjectName(finalName);
|
setProjectName(finalName);
|
||||||
window.SonicStorage.exportProjectToSFS(projectSchemaObj);
|
window.SonicStorage.exportProjectToSFS(projectSchemaObj);
|
||||||
showToast(`Đã lưu dự án local "${finalName}" thành công!`, "success");
|
showToast(`Đã lưu dự án local "${finalName}" thành công!`, "success");
|
||||||
|
// Đã đăng nhập → đồng bộ lên Cloud (fire-and-forget): project mở được từ
|
||||||
|
// máy khác / browser ẩn danh khi đăng nhập cùng tài khoản.
|
||||||
|
if (currentUser && window.SonicAPI && window.SonicAPI.saveCloudProject) {
|
||||||
|
window.SonicAPI.saveCloudProject(finalName, dataStr).then(function (res) {
|
||||||
|
if (res && res.project_id) {
|
||||||
|
console.log('[Cloud] local project synced:', res.project_id);
|
||||||
|
}
|
||||||
|
}).catch(function (e) { console.warn('Cloud sync local project failed:', e); });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSaveCloudProject = async (name, existingProjectId) => {
|
const handleSaveCloudProject = async (name, existingProjectId) => {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -24,7 +24,7 @@
|
|||||||
<script src="/static/js/services/midiExtractor.js?v=202607281052"></script>
|
<script src="/static/js/services/midiExtractor.js?v=202607281052"></script>
|
||||||
<script src="/static/js/services/promptTemplateManager.js?v=202607281039"></script>
|
<script src="/static/js/services/promptTemplateManager.js?v=202607281039"></script>
|
||||||
<script src="/static/js/services/undoRedoEngine.js?v=202607290941"></script>
|
<script src="/static/js/services/undoRedoEngine.js?v=202607290941"></script>
|
||||||
<script src="/static/js/app.precompiled.js?v=202608060430" defer></script>
|
<script src="/static/js/app.precompiled.js?v=202608060500" defer></script>
|
||||||
<link rel="stylesheet" href="/static/css/styles.css?v=202607271016">
|
<link rel="stylesheet" href="/static/css/styles.css?v=202607271016">
|
||||||
<style>
|
<style>
|
||||||
:root {
|
:root {
|
||||||
|
|||||||
@@ -1955,3 +1955,12 @@
|
|||||||
- **FIX (app.jsx effect [activeTab] ~14571):** `prevActiveTabRef` lưu tab trước; khi đổi tab → nếu tab CŨ là sub-tab (PIANO_ROLL/section/audio) đang `isPlaying` → `stopAllPlayback()` + set `isPlaying: false` cho tab đó. Tab MỚI không bị ảnh hưởng; MAIN giữ hành vi cũ (mở piano-roll lúc main play → main tiếp tục — handleEditMidiInTab đã xử lý).
|
- **FIX (app.jsx effect [activeTab] ~14571):** `prevActiveTabRef` lưu tab trước; khi đổi tab → nếu tab CŨ là sub-tab (PIANO_ROLL/section/audio) đang `isPlaying` → `stopAllPlayback()` + set `isPlaying: false` cho tab đó. Tab MỚI không bị ảnh hưởng; MAIN giữ hành vi cũ (mở piano-roll lúc main play → main tiếp tục — handleEditMidiInTab đã xử lý).
|
||||||
- **Các file ảnh hưởng:** `app/static/js/app.jsx`, `app/templates/index.html` (?v=202608060430), `wiki.md`. Rebuild precompiled.
|
- **Các file ảnh hưởng:** `app/static/js/app.jsx`, `app/templates/index.html` (?v=202608060430), `wiki.md`. Rebuild precompiled.
|
||||||
- **Ghi chú/Test:** `npm run build` → hard refresh → piano-roll play → bấm tab MAIN → âm piano-roll phải DỪNG ngay; play main → mở piano-roll → main tiếp tục (hành vi cũ).
|
- **Ghi chú/Test:** `npm run build` → hard refresh → piano-roll play → bấm tab MAIN → âm piano-roll phải DỪNG ngay; play main → mở piano-roll → main tiếp tục (hành vi cũ).
|
||||||
|
|
||||||
|
### [2026-08-06 05:00] Task: Project không mở được khi đăng nhập máy khác/ẩn danh — 2 fix cross-machine
|
||||||
|
- **Báo cáo user:** login máy khác / browser ẩn danh → không mở được project đã tạo trước đó.
|
||||||
|
- **Chẩn đoán:** backend cloud key ĐÚNG theo user_id (JWT) ✓; OpenProjectModal có tab Cloud (list per-user) + Local (localStorage MÁY-ĐỊNH XỨ). Vấn đề: (1) `restoreLastSessionProject` đọc `sonic_project_id` từ localStorage — máy mới → trống → không restore gì; (2) project lưu LOCAL (`local_` id — chưa login lúc save) → localStorage → machine-bound.
|
||||||
|
- **FIX (app.jsx):**
|
||||||
|
(1) `restoreLastSessionProject`: `!lastId` (máy mới) + có profile (currentUser hoặc `localStorage sonic_user`) → **tự mở project Cloud GẦN NHẤT** (listCloudProjects → [0] → getCloudProject → restore). Local id có sẵn → hành vi cũ.
|
||||||
|
(2) `handleSaveLocalProject`: đã login → **đồng bộ lên Cloud (fire-and-forget saveCloudProject)** — project mở được từ máy khác.
|
||||||
|
- **Các file ảnh hưởng:** `app/static/js/app.jsx`, `app/templates/index.html` (?v=202608060500), `wiki.md`. Rebuild precompiled.
|
||||||
|
- **Ghi chú/Test:** `npm run build` → hard refresh → login máy mới/ẩn danh → tự mở project Cloud gần nhất. Lưu local khi login → xuất hiện trong Cloud tab ở máy khác. Project local CŨ (tạo trước fix) → mở trên máy cũ + lưu lại → sync.
|
||||||
|
|||||||
Reference in New Issue
Block a user