Просмотр исходного кода

🚀 Add Vercel deployment configuration

✨ Features:
- Added vercel.json for serverless deployment
- Created api/index.py entry point for Vercel
- Modified Flask app for serverless compatibility
- Updated requirements.txt with specific versions
- Enhanced error handling for cloud environments

🔧 Vercel Setup:
- Serverless Flask deployment ready
- 30s function timeout for magnet processing
- Static file serving configured
- Production-ready configuration
sh13y 6 месяцев назад
Родитель
Сommit
48c595dba6
4 измененных файлов с 40 добавлено и 8 удалено
  1. 6 0
      api/index.py
  2. 3 3
      requirements.txt
  3. 8 5
      simple_magnet2direct.py
  4. 23 0
      vercel.json

+ 6 - 0
api/index.py

@@ -0,0 +1,6 @@
+from simple_magnet2direct import app
+
+# Vercel expects the WSGI application to be called 'app'
+# This is the entry point for Vercel
+if __name__ == "__main__":
+    app.run()

+ 3 - 3
requirements.txt

@@ -1,3 +1,3 @@
-Flask>=2.0.0
-seedrcc>=1.0.0
-requests>=2.25.0
+Flask==2.3.3
+seedrcc==1.0.4
+requests==2.31.0

+ 8 - 5
simple_magnet2direct.py

@@ -11,15 +11,18 @@ app = Flask(__name__)
 DEFAULT_EMAIL = ""
 DEFAULT_PASSWORD = ""
 
-# Download folder
-DOWNLOAD_FOLDER = os.path.join(os.path.expanduser("~"), "Downloads", "Magnet2Direct")
+# Download folder (for local development only)
+DOWNLOAD_FOLDER = os.path.join(os.path.expanduser("~"), "Downloads", "Magnet2Direct") if os.path.expanduser("~") != "~" else "/tmp"
 
 # Global variables
 download_status = {"progress": 0, "status": "idle", "filename": "", "download_url": "", "file_size": "", "error": ""}
 
-# Create download folder
-if not os.path.exists(DOWNLOAD_FOLDER):
-    os.makedirs(DOWNLOAD_FOLDER)
+# Create download folder (only if not in serverless environment)
+try:
+    if not os.path.exists(DOWNLOAD_FOLDER) and os.path.expanduser("~") != "~":
+        os.makedirs(DOWNLOAD_FOLDER)
+except:
+    pass  # Skip folder creation in serverless environments
 
 HTML_TEMPLATE = """
 <!DOCTYPE html>

+ 23 - 0
vercel.json

@@ -0,0 +1,23 @@
+{
+  "version": 2,
+  "builds": [
+    {
+      "src": "api/index.py",
+      "use": "@vercel/python"
+    }
+  ],
+  "routes": [
+    {
+      "src": "/(.*)",
+      "dest": "api/index.py"
+    }
+  ],
+  "env": {
+    "PYTHONPATH": "./"
+  },
+  "functions": {
+    "api/index.py": {
+      "maxDuration": 30
+    }
+  }
+}