ResMan update

This commit is contained in:
ecki
2026-03-09 18:20:41 +01:00
parent a244225887
commit 2b82941b44
3 changed files with 38 additions and 36 deletions
+13 -26
View File
@@ -835,23 +835,17 @@ document.getElementById("domainModal").style.display="none"
async function saveDomain(){ async function saveDomain(){
const id=document.getElementById("domain_id").value const id = document.getElementById("domain_id").value
let cost=document.getElementById("domain_cost").value let cost = document.getElementById("domain_cost").value
if(cost){ if(cost){
cost=cost.replace(",",".") cost = cost.replace(",",".")
} }
let domain=document.getElementById("domain_name").value const data = {
/* https:// entfernen */ domain_name:document.getElementById("domain_name").value,
domain=domain.replace("https://","").replace("http://","").replace("/","")
const data={
domain_name:domain,
provider:document.getElementById("domain_provider").value, provider:document.getElementById("domain_provider").value,
ip_address:document.getElementById("domain_ip").value, ip_address:document.getElementById("domain_ip").value,
yearly_cost:cost || null, yearly_cost:cost || null,
@@ -859,11 +853,11 @@ notes:document.getElementById("domain_notes").value
} }
/* speichern */ let response
if(id){ if(id){
await fetch(API+"/domains/"+id,{ response = await fetch(API+"/domains/"+id,{
method:"PUT", method:"PUT",
headers:{'Content-Type':'application/json'}, headers:{'Content-Type':'application/json'},
body:JSON.stringify(data) body:JSON.stringify(data)
@@ -871,7 +865,7 @@ body:JSON.stringify(data)
}else{ }else{
await fetch(API+"/domains",{ response = await fetch(API+"/domains",{
method:"POST", method:"POST",
headers:{'Content-Type':'application/json'}, headers:{'Content-Type':'application/json'},
body:JSON.stringify(data) body:JSON.stringify(data)
@@ -879,22 +873,15 @@ body:JSON.stringify(data)
} }
/* DNS automatisch prüfen */ /* Fehler prüfen */
try{ if(!response.ok){
const dnsRes = await fetch(API+"/dns/"+domain) const err = await response.json()
const result = await dnsRes.json()
if(result.ips && result.ips.length){ alert("Fehler: "+err.error)
data.ip_address=result.ips[0] return
}
}catch(e){
console.log("DNS check failed")
} }
+21 -4
View File
@@ -78,10 +78,27 @@ notes
id: result.insertId id: result.insertId
}); });
} catch (err) { }catch (err) {
console.error("CREATE domain error:", err);
res.status(500).json({ error: "DB error" }); console.error("CREATE domain error:", err);
}
let message="Database error"
if(err.code==="WARN_DATA_TRUNCATED"){
message="Invalid price format (use 1.99)"
}
if(err.code==="ER_DUP_ENTRY"){
message="Domain already exists"
}
res.status(500).json({
error: message,
details: err.sqlMessage
})
}
}); });
+4 -6
View File
@@ -47,15 +47,13 @@ app.use("/resman/api/ipcheck", ipCheck)
app.use((err, req, res, next) => { app.use((err, req, res, next) => {
console.error("EXPRESS ERROR:"); console.error("EXPRESS ERROR:", err)
console.error(err);
res.status(500).json({ res.status(500).json({
error: "Internal Server Error" error: err.message || "Internal Server Error"
}); })
});
})
app.listen(3000, () => { app.listen(3000, () => {
console.log("ResMan running on port 3000"); console.log("ResMan running on port 3000");
}); });