Textcreator LIVE V13.1 Cloud Music OS — Deel 15 van 23
Dit deel gaat direct verder onder deel 14.
Toegevoegd:
Database Layer V13.1
veilige data normalisatie
Sheet kolom herkenning
meerdere naamformaten ondersteunen
voorbereiding nieuwe Apps Script structuur
stabiele koppeling tussen Sheet → API → HTML
Plak dit onder deel 14.
<script>
/*
====================================================
TEXTCREATOR LIVE V13.1
PART 15
DATABASE LAYER ENGINE
====================================================
*/
const DATABASE_LAYER={
version:"V13.1",
collections:{
generated:[],
jukebox:[],
ai:[]
},
ready:false
};
/*
====================================================
NORMALIZE VALUE
====================================================
*/
function dbValue(obj,keys,defaultValue=""){
if(!obj)
return defaultValue;
for(let key of keys){
if(
obj[key] !== undefined &&
obj[key] !== null &&
obj[key] !== ""
){
return obj[key];
}
}
return defaultValue;
}
/*
====================================================
NORMALIZE SONG DATA
====================================================
*/
function normalizeSong(song){
return {
id:
dbValue(
song,
[
"ID",
"id",
"Id"
],
""
),
title:
dbValue(
song,
[
"Titel",
"title",
"Title"
],
"Zonder titel"
),
name:
dbValue(
song,
[
"Naam",
"name",
"Maker"
],
""
),
user:
dbValue(
song,
[
"User",
"user",
"Username"
],
""
),
genre:
dbValue(
song,
[
"Genre",
"genre",
"Muziekstijl"
],
""
),
mood:
dbValue(
song,
[
"Mood",
"mood",
"Emotie"
],
""
),
language:
dbValue(
song,
[
"Taal",
"language",
"Language"
],
"NL"
),
lyrics:
dbValue(
song,
[
"Lyrics",
"text",
"Tekst"
],
""
),
prompt:
dbValue(
song,
[
"Prompt",
"prompt"
],
""
),
suno:
dbValue(
song,
[
"Suno_URL",
"suno",
"Suno"
],
""
),
status:
dbValue(
song,
[
"Status",
"status"
],
""
),
public:
dbValue(
song,
[
"Public",
"public"
],
true
)
};
}
/*
====================================================
NORMALIZE AI DATA
====================================================
*/
function normalizeAI(ai){
return {
id:
dbValue(
ai,
[
"AI_ID",
"id"
],
""
),
provider:
dbValue(
ai,
[
"Provider",
"provider"
],
""
),
model:
dbValue(
ai,
[
"Model",
"model"
],
""
),
type:
dbValue(
ai,
[
"Type",
"type"
],
""
),
status:
dbValue(
ai,
[
"API_Status",
"status"
],
""
),
description:
dbValue(
ai,
[
"Beschrijving",
"description"
],
""
)
};
}
/*
====================================================
PROCESS GENERATED DATABASE
====================================================
*/
function processGeneratedDatabase(data){
if(!Array.isArray(data))
return [];
return data.map(song=>{
return normalizeSong(song);
});
}
/*
====================================================
PROCESS JUKEBOX DATABASE
====================================================
*/
function processJukeboxDatabase(data){
if(!Array.isArray(data))
return [];
return data
.filter(song=>{
return (
normalizeSong(song).public
!== false
);
})
.map(song=>{
return normalizeSong(song);
});
}
/*
====================================================
PROCESS AI DATABASE
====================================================
*/
function processAIDatabase(data){
if(!Array.isArray(data))
return [];
return data.map(ai=>{
return normalizeAI(ai);
});
}
/*
====================================================
LOAD COMPLETE DATABASE
====================================================
*/
async function loadDatabaseLayer(){
console.log(
"Database Layer starten"
);
try{
const generated=
await api(
"generated"
);
DATABASE_LAYER.collections.generated=
processGeneratedDatabase(
generated
);
APP.generated=
DATABASE_LAYER.collections.generated;
}
catch(error){
console.error(
"Generated database fout",
error
);
}
try{
const jukeboxData=
await api(
"jukebox"
);
DATABASE_LAYER.collections.jukebox=
processJukeboxDatabase(
jukeboxData
);
APP.songs=
DATABASE_LAYER.collections.jukebox;
}
catch(error){
console.error(
"Jukebox database fout",
error
);
}
try{
const aiData=
await api(
"ai"
);
DATABASE_LAYER.collections.ai=
processAIDatabase(
aiData
);
APP.ai=
DATABASE_LAYER.collections.ai;
}
catch(error){
console.error(
"AI database fout",
error
);
}
DATABASE_LAYER.ready=true;
console.log(
"DATABASE READY",
DATABASE_LAYER
);
}
/*
====================================================
DATABASE SEARCH
====================================================
*/
function databaseSearch(query){
const q=
String(query)
.toLowerCase();
return DATABASE_LAYER.collections.generated.filter(song=>{
return JSON.stringify(song)
.toLowerCase()
.includes(q);
});
}
/*
====================================================
DATABASE STATISTICS
====================================================
*/
function databaseStats(){
return {
songs:
DATABASE_LAYER.collections.generated.length,
jukebox:
DATABASE_LAYER.collections.jukebox.length,
ai:
DATABASE_LAYER.collections.ai.length,
ready:
DATABASE_LAYER.ready
};
}
console.log(
"Database Layer Engine V13.1 loaded"
);
</script>
Einde deel 15/23.
Volgend deel 16 van 23:
Router Engine
pagina/module navigatie
workspace management
centrale event structuur
voorbereiding V13.1 als echte webapp.