|
2 | 2 | import argparse |
3 | 3 | import json |
4 | 4 | import os |
5 | | -import shutil |
6 | | -import zipfile |
7 | 5 |
|
8 | 6 | # Third-party imports |
9 | 7 | from flask import Flask, jsonify, request, send_from_directory |
10 | 8 | from flask_restful import Api, Resource |
11 | 9 | from flask_sqlalchemy import SQLAlchemy |
12 | 10 | from werkzeug.utils import secure_filename |
13 | 11 |
|
| 12 | +# Our imports |
| 13 | +from deploy import DeployResource |
| 14 | + |
14 | 15 | app = Flask(__name__, static_folder='../dist', static_url_path='') |
15 | 16 | app.url_map.merge_slashes = False # Don't merge consecutive slashes |
16 | 17 | api = Api(app) |
@@ -232,58 +233,6 @@ def get(self): |
232 | 233 |
|
233 | 234 | return {'files': sorted(list(children))} |
234 | 235 |
|
235 | | -class DeployResource(Resource): |
236 | | - def post(self): |
237 | | - """Upload and extract a zip file to the deploy directory""" |
238 | | - if 'file' not in request.files: |
239 | | - return {'error': 'No file provided'}, 400 |
240 | | - |
241 | | - file = request.files['file'] |
242 | | - |
243 | | - if file.filename == '': |
244 | | - return {'error': 'No file selected'}, 400 |
245 | | - |
246 | | - if not file.filename.endswith('.zip'): |
247 | | - return {'error': 'Only zip files are allowed'}, 400 |
248 | | - |
249 | | - try: |
250 | | - # Create deploy directory if it doesn't exist |
251 | | - deploy_dir = os.path.join(basedir, 'deploy') |
252 | | - |
253 | | - # Clear existing deploy directory |
254 | | - if os.path.exists(deploy_dir): |
255 | | - shutil.rmtree(deploy_dir) |
256 | | - os.makedirs(deploy_dir) |
257 | | - |
258 | | - # Save the zip file temporarily |
259 | | - temp_zip_path = os.path.join(basedir, 'temp_deploy.zip') |
260 | | - file.save(temp_zip_path) |
261 | | - |
262 | | - # Extract the zip file |
263 | | - with zipfile.ZipFile(temp_zip_path, 'r') as zip_ref: |
264 | | - zip_ref.extractall(deploy_dir) |
265 | | - |
266 | | - # Remove the temporary zip file |
267 | | - os.remove(temp_zip_path) |
268 | | - |
269 | | - # List extracted files |
270 | | - extracted_files = [] |
271 | | - for root, dirs, files in os.walk(deploy_dir): |
272 | | - for filename in files: |
273 | | - rel_path = os.path.relpath(os.path.join(root, filename), deploy_dir) |
274 | | - extracted_files.append(rel_path) |
275 | | - |
276 | | - return { |
277 | | - 'message': 'Deployment successful', |
278 | | - 'deploy_directory': deploy_dir, |
279 | | - 'files_extracted': len(extracted_files), |
280 | | - 'files': extracted_files[:20] # Show first 20 files |
281 | | - } |
282 | | - except zipfile.BadZipFile: |
283 | | - return {'error': 'Invalid zip file'}, 400 |
284 | | - except Exception as e: |
285 | | - return {'error': f'Deployment failed: {str(e)}'}, 500 |
286 | | - |
287 | 236 | # Register API routes |
288 | 237 | # Storage API routes (more specific routes first) |
289 | 238 | api.add_resource(StorageEntryResource, '/entries/<path:entry_key>') |
|
0 commit comments