Textcreator LIVE V13.1 Cloud Music OS — Deel 19 van 23
Dit deel gaat direct verder onder deel 18.
Toegevoegd:
Cloud Sync Engine V13.1
centrale synchronisatie laag
API save/update structuur
lokale backup voorbereiding
verbinding tussen frontend en Apps Script stabieler gemaakt
Plak dit onder deel 18.
<script>
/*
====================================================
TEXTCREATOR LIVE V13.1
PART 19
CLOUD SYNC ENGINE
====================================================
*/
const CLOUD_SYNC={
version:"V13.1",
online:false,
lastSync:null,
queue:[],
syncing:false
};
/*
====================================================
CREATE SYNC OBJECT
====================================================
*/
function createSyncObject(type,data){
return {
id:
"SYNC-"+Date.now(),
type:type,
data:data,
timestamp:
new Date().toISOString(),
version:
"V13.1"
};
}
/*
====================================================
ADD TO QUEUE
====================================================
*/
function addSyncQueue(type,data){
const item=
createSyncObject(
type,
data
);
CLOUD_SYNC.queue.push(
item
);
console.log(
"Sync queue toegevoegd",
item
);
return item;
}
/*
====================================================
SAVE CLOUD DATA
====================================================
*/
async function cloudSave(type,data){
const syncItem=
addSyncQueue(
type,
data
);
try{
CLOUD_SYNC.syncing=true;
const response=
await fetch(
API_URL,
{
method:"POST",
headers:{
"Content-Type":
"application/json"
},
body:
JSON.stringify({
action:"save",
...data,
sync_id:
syncItem.id,
sync_type:
type
})
}
);
const result=
await response.json();
CLOUD_SYNC.online=true;
CLOUD_SYNC.lastSync=
new Date();
removeSyncItem(
syncItem.id
);
notify(
"Cloud opslag succesvol",
"success"
);
return result;
}
catch(error){
console.error(
"Cloud Save error",
error
);
CLOUD_SYNC.online=false;
notify(
"Cloud opslag mislukt",
"error"
);
saveLocalBackup(
syncItem
);
return null;
}
finally{
CLOUD_SYNC.syncing=false;
}
}
/*
====================================================
REMOVE QUEUE ITEM
====================================================
*/
function removeSyncItem(id){
CLOUD_SYNC.queue=
CLOUD_SYNC.queue.filter(
item=>
item.id!==id
);
}
/*
====================================================
LOCAL BACKUP
====================================================
*/
function saveLocalBackup(data){
let backup=
JSON.parse(
localStorage.getItem(
"tc_v13_backup"
)
|| "[]"
);
backup.push(
data
);
localStorage.setItem(
"tc_v13_backup",
JSON.stringify(
backup
)
);
console.log(
"Lokale backup opgeslagen",
data
);
}
/*
====================================================
LOAD LOCAL BACKUP
====================================================
*/
function loadLocalBackup(){
return JSON.parse(
localStorage.getItem(
"tc_v13_backup"
)
|| "[]"
);
}
/*
====================================================
SYNC GENERATED SONG
====================================================
*/
async function syncSong(song){
if(!song){
notify(
"Geen song om te synchroniseren",
"error"
);
return;
}
return await cloudSave(
"song",
song
);
}
/*
====================================================
SYNC FAVORITES
====================================================
*/
async function syncFavorites(){
return await cloudSave(
"favorites",
SONG_ENGINE.favorites
);
}
/*
====================================================
SYNC STATUS
====================================================
*/
function cloudStatus(){
return {
online:
CLOUD_SYNC.online,
lastSync:
CLOUD_SYNC.lastSync,
queue:
CLOUD_SYNC.queue.length,
syncing:
CLOUD_SYNC.syncing
};
}
/*
====================================================
AUTO SYNC CHECK
====================================================
*/
function startCloudMonitor(){
setInterval(()=>{
console.log(
"Cloud monitor",
cloudStatus()
);
},30000);
}
/*
====================================================
INITIALIZE CLOUD ENGINE
====================================================
*/
function initCloudSync(){
console.log(
"Cloud Sync Engine gestart",
CLOUD_SYNC
);
startCloudMonitor();
}
window.addEventListener(
"DOMContentLoaded",
()=>{
initCloudSync();
});
console.log(
"Cloud Sync Engine V13.1 loaded"
);
</script>
Einde deel 19/23.
Volgend deel 20 van 23:
Export Engine
TXT export
PDF export
deelbare songkaarten
voorbereiding publicatie / promotie workflow.