@@ -3,7 +3,7 @@ import { addScript, deleteScript } from "./scripts.ts";
33import { checkJWT } from "./utils/jwt.ts" ;
44import { addMaps , deleteMaps , getMaps , getDeploymentsByRepo , getUserToken } from "./db.ts" ;
55import { encryptEnv , decryptEnv } from "./utils/crypto.ts" ;
6-
6+ import { canAllocateStorage } from "./utils/container-storage.ts" ;
77// ... skipping to githubWebhook
88
99
@@ -57,6 +57,19 @@ async function addSubdomain(ctx: Context) {
5757 }
5858
5959 // We keep deployment config (port, stack, etc.) in the document to store them in DB for webhook usage
60+ if ( copy . volume_needed == "Yes" ) { const storageCheck = await canAllocateStorage ( 100 ) ;
61+ if ( ! storageCheck . can_allocate ) {
62+ ctx . response . status = 400 ;
63+ ctx . response . body = {
64+ status : "failed" ,
65+ error : "INSUFFICIENT_STORAGE" ,
66+ message : storageCheck . reason || "Not enough disk space" ,
67+ available_mb : storageCheck . available_mb ,
68+ requested_mb : storageCheck . requested_mb ,
69+ } ;
70+ console . log ( storageCheck . available_mb ) ;
71+ return ;
72+ } }
6073 const success : boolean = await addMaps ( document ) ;
6174
6275
@@ -146,7 +159,7 @@ async function addSubdomain(ctx: Context) {
146159 ctx . response . body = { "status" : "failed" } ;
147160 }
148161}
149- //!add volume removal logic on deleting the subdomain
162+
150163async function deleteSubdomain ( ctx : Context ) {
151164 if ( ! ctx . request . hasBody ) {
152165 ctx . throw ( 415 ) ;
0 commit comments