Textcreator LIVE V13.1 Cloud Music OS — Deel 21 van 23
Dit deel gaat direct verder onder deel 20.
Toegevoegd:
Security & Validation Engine V13.1
data controle
API input validatie
bescherming tegen lege records
foutafhandeling voor productiegebruik
Plak dit onder deel 20.
<script>
/*
====================================================
TEXTCREATOR LIVE V13.1
PART 21
SECURITY & VALIDATION ENGINE
====================================================
*/
const SECURITY_ENGINE={
version:"V13.1",
validated:0,
blocked:0,
errors:[]
};
/*
====================================================
CLEAN TEXT INPUT
====================================================
*/
function cleanText(value){
if(value===undefined || value===null){
return "";
}
return String(value)
.trim()
.replace(
/<script.*?>.*?<\/script>/gi,
""
)
.replace(
/javascript:/gi,
""
);
}
/*
====================================================
VALIDATE REQUIRED FIELD
====================================================
*/
function validateRequired(data,fields){
let missing=[];
fields.forEach(field=>{
if(
!data[field]
||
String(data[field]).trim()===""
){
missing.push(field);
}
});
return {
valid:
missing.length===0,
missing:missing
};
}
/*
====================================================
VALIDATE SONG
====================================================
*/
function validateSong(song){
const result=
validateRequired(
song,
[
"title"
]
);
if(!result.valid){
SECURITY_ENGINE.blocked++;
SECURITY_ENGINE.errors.push(
{
type:"song",
fields:
result.missing
}
);
return false;
}
SECURITY_ENGINE.validated++;
return true;
}
/*
====================================================
SANITIZE SONG DATA
====================================================
*/
function sanitizeSong(song){
let clean={};
Object.keys(song)
.forEach(key=>{
clean[key]=
cleanText(
song[key]
);
});
return clean;
}
/*
====================================================
VALIDATE API RESPONSE
====================================================
*/
function validateAPIResponse(data){
if(!data){
SECURITY_ENGINE.errors.push(
"Empty API response"
);
return false;
}
if(
typeof data !== "object"
){
SECURITY_ENGINE.errors.push(
"Invalid API format"
);
return false;
}
return true;
}
/*
====================================================
SAFE API WRAPPER
====================================================
*/
async function safeAPI(action){
try{
const result=
await api(action);
if(
!validateAPIResponse(result)
){
throw new Error(
"API validatie mislukt"
);
}
return result;
}
catch(error){
SECURITY_ENGINE.errors.push(
error.toString()
);
notify(
"API fout gecontroleerd",
"error"
);
return [];
}
}
/*
====================================================
SAFE SAVE
====================================================
*/
async function safeSaveSong(song){
const clean=
sanitizeSong(song);
if(
!validateSong(clean)
){
notify(
"Song bevat ontbrekende gegevens",
"error"
);
return null;
}
return await cloudSave(
"song",
clean
);
}
/*
====================================================
SECURITY REPORT
====================================================
*/
function securityReport(){
return {
version:
SECURITY_ENGINE.version,
validated:
SECURITY_ENGINE.validated,
blocked:
SECURITY_ENGINE.blocked,
errors:
SECURITY_ENGINE.errors
};
}
/*
====================================================
GLOBAL ERROR HANDLER
====================================================
*/
window.addEventListener(
"error",
function(event){
SECURITY_ENGINE.errors.push(
{
message:event.message,
time:new Date()
}
);
console.error(
"Global error",
event.error
);
}
);
/*
====================================================
INITIALIZE SECURITY
====================================================
*/
function initSecurityEngine(){
console.log(
"Security Engine gestart",
SECURITY_ENGINE
);
}
window.addEventListener(
"DOMContentLoaded",
()=>{
initSecurityEngine();
});
console.log(
"Security & Validation Engine V13.1 loaded"
);
</script>
Einde deel 21/23.
Nog 2 delen:
22 van 23
Final Integration Engine
alle engines koppelen:
Database
Router
UI
Cloud Sync
Export
Security
volledige startprocedure
23 van 23
Final Release Engine
V13.1 eindcontrole
productie boot
versie markering
klaar voor gebruik.