sun-pc 2 mesi fa
parent
commit
99b5701e8a
2 ha cambiato i file con 19 aggiunte e 3 eliminazioni
  1. 4 2
      Dockerfile
  2. 15 1
      main.py

+ 4 - 2
Dockerfile

@@ -8,6 +8,7 @@ RUN apt-get update && apt-get install -y \
     python3 \
     python3-pip \
     ghostscript \
+    poppler-utils \
     && rm -rf /var/lib/apt/lists/*
 
 WORKDIR /app
@@ -19,8 +20,9 @@ RUN pip3 install --no-cache-dir -r requirements.txt
 # Copy application code
 COPY . .
 
-# Create directories for file processing
-RUN mkdir -p /app/uploads /app/processed
+# Create directories for file processing with proper permissions
+RUN mkdir -p /app/uploads /app/processed && \
+    chmod -R 777 /app/uploads /app/processed
 
 # Expose the port the app runs on
 EXPOSE 8000

+ 15 - 1
main.py

@@ -55,6 +55,13 @@ async def convert_eps_to_svg(file: UploadFile):
         raise HTTPException(status_code=400, detail="Only EPS files are accepted")
     
     try:
+        # Ensure directories exist and are writable
+        for directory in [UPLOAD_DIR, PROCESSED_DIR]:
+            if not os.path.exists(directory):
+                os.makedirs(directory, exist_ok=True)
+            if not os.access(directory, os.W_OK):
+                raise HTTPException(status_code=500, detail=f"Directory {directory} is not writable")
+
         # Save uploaded file
         input_path = os.path.join(UPLOAD_DIR, file.filename)
         with open(input_path, "wb") as f:
@@ -66,7 +73,14 @@ async def convert_eps_to_svg(file: UploadFile):
         final_svg = os.path.join(PROCESSED_DIR, f"{base_name}.svg")
         
         # Convert EPS to SVG
-        subprocess.run(['eps2svg', input_path, temp_svg], check=True)
+        try:
+            subprocess.run(['eps2svg', input_path, temp_svg], check=True, capture_output=True, text=True)
+        except subprocess.CalledProcessError as e:
+            raise HTTPException(status_code=500, detail=f"eps2svg conversion failed: {e.stderr}")
+        
+        # Check if temp_svg was created
+        if not os.path.exists(temp_svg):
+            raise HTTPException(status_code=500, detail="eps2svg failed to create output file")
         
         # Try to optimize SVG using scour
         try: