fix: prevent extending deleted vms

This commit is contained in:
2025-05-01 15:19:39 +01:00
parent cd7ac9e967
commit c859c153c1

View File

@ -565,10 +565,15 @@ async fn v1_renew_vm(
/// Extend a VM by LNURL payment /// Extend a VM by LNURL payment
#[get("/api/v1/vm/<id>/renew-lnurlp?<amount>")] #[get("/api/v1/vm/<id>/renew-lnurlp?<amount>")]
async fn v1_renew_vm_lnurlp( async fn v1_renew_vm_lnurlp(
db: &State<Arc<dyn LNVpsDb>>,
provisioner: &State<Arc<LNVpsProvisioner>>, provisioner: &State<Arc<LNVpsProvisioner>>,
id: u64, id: u64,
amount: u64, amount: u64,
) -> Result<Json<LnURLPayInvoice>, &'static str> { ) -> Result<Json<LnURLPayInvoice>, &'static str> {
let vm = db.get_vm(id).await.map_err(|_e| "VM not found")?;
if vm.deleted {
return Err("VM not found");
}
if amount < 1000 { if amount < 1000 {
return Err("Amount must be greater than 1000"); return Err("Amount must be greater than 1000");
} }
@ -593,7 +598,10 @@ async fn v1_lnurlp(
settings: &State<Settings>, settings: &State<Settings>,
id: u64, id: u64,
) -> Result<Json<PayResponse>, &'static str> { ) -> Result<Json<PayResponse>, &'static str> {
db.get_vm(id).await.map_err(|_e| "VM not found")?; let vm = db.get_vm(id).await.map_err(|_e| "VM not found")?;
if vm.deleted {
return Err("VM not found");
}
let meta = vec![vec!["text/plain".to_string(), format!("Extend VM {}", id)]]; let meta = vec![vec!["text/plain".to_string(), format!("Extend VM {}", id)]];
let rsp = PayResponse { let rsp = PayResponse {