[patch] 修改逻辑: 在用户误触或开了多个GUI程序的时候不能同时建立多个连接 确保一个账号只能建立一个与后端的连接 友好提示的集成review 修改powershell语法问题
This commit is contained in:
@@ -1,171 +1,171 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
Upload GUI installer to KS3 object storage
|
Upload GUI installer to KS3 object storage
|
||||||
- Target directory: installers/
|
- Target directory: installers/
|
||||||
- Set proper HTTP headers for browser download
|
- Set proper HTTP headers for browser download
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ks3.connection import Connection
|
from ks3.connection import Connection
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print("ERROR: ks3sdk not installed. Please run: pip install ks3sdk")
|
print("ERROR: ks3sdk not installed. Please run: pip install ks3sdk")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Configure logging
|
# Configure logging
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
format='%(asctime)s [%(levelname)s] %(message)s'
|
format='%(asctime)s [%(levelname)s] %(message)s'
|
||||||
)
|
)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# KS3 Configuration (using actual project config)
|
# KS3 Configuration (using actual project config)
|
||||||
KS3_ACCESS_KEY = 'AKLT0Ey7Nq7ZSXykki0X0RGG'
|
KS3_ACCESS_KEY = 'AKLT0Ey7Nq7ZSXykki0X0RGG'
|
||||||
KS3_SECRET_KEY = 'OONxkt9wwJa1FIco21vCbirs1HB6AGzDWdRyV0k2'
|
KS3_SECRET_KEY = 'OONxkt9wwJa1FIco21vCbirs1HB6AGzDWdRyV0k2'
|
||||||
KS3_ENDPOINT = 'ks3-cn-guangzhou.ksyuncs.com' # Guangzhou region
|
KS3_ENDPOINT = 'ks3-cn-guangzhou.ksyuncs.com' # Guangzhou region
|
||||||
KS3_BUCKET = 'shuidrop-chat-server'
|
KS3_BUCKET = 'shuidrop-chat-server'
|
||||||
KS3_IS_SECURE = True # Use HTTPS
|
KS3_IS_SECURE = True # Use HTTPS
|
||||||
KS3_PREFIX = 'installers/'
|
KS3_PREFIX = 'installers/'
|
||||||
|
|
||||||
|
|
||||||
def get_ks3_connection():
|
def get_ks3_connection():
|
||||||
"""Get KS3 connection"""
|
"""Get KS3 connection"""
|
||||||
try:
|
try:
|
||||||
connection = Connection(
|
connection = Connection(
|
||||||
KS3_ACCESS_KEY,
|
KS3_ACCESS_KEY,
|
||||||
KS3_SECRET_KEY,
|
KS3_SECRET_KEY,
|
||||||
host=KS3_ENDPOINT,
|
host=KS3_ENDPOINT,
|
||||||
is_secure=KS3_IS_SECURE,
|
is_secure=KS3_IS_SECURE,
|
||||||
timeout=1800, # Increase timeout to 30 minutes for large files
|
timeout=1800, # Increase timeout to 30 minutes for large files
|
||||||
)
|
)
|
||||||
logger.info(f"KS3 connection established: {KS3_ENDPOINT}")
|
logger.info(f"KS3 connection established: {KS3_ENDPOINT}")
|
||||||
return connection
|
return connection
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"KS3 connection failed: {e}")
|
logger.error(f"KS3 connection failed: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def find_latest_installer():
|
def find_latest_installer():
|
||||||
"""Find the latest generated installer"""
|
"""Find the latest generated installer"""
|
||||||
project_root = Path(__file__).parent.parent.parent
|
project_root = Path(__file__).parent.parent.parent
|
||||||
installer_dir = project_root / 'installer' / 'output'
|
installer_dir = project_root / 'installer' / 'output'
|
||||||
|
|
||||||
if not installer_dir.exists():
|
if not installer_dir.exists():
|
||||||
logger.error(f"Installer directory not found: {installer_dir}")
|
logger.error(f"Installer directory not found: {installer_dir}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
installers = list(installer_dir.glob('*.exe'))
|
installers = list(installer_dir.glob('*.exe'))
|
||||||
if not installers:
|
if not installers:
|
||||||
logger.error(f"No installer files found in: {installer_dir}")
|
logger.error(f"No installer files found in: {installer_dir}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
latest_installer = max(installers, key=lambda p: p.stat().st_mtime)
|
latest_installer = max(installers, key=lambda p: p.stat().st_mtime)
|
||||||
file_size_mb = latest_installer.stat().st_size / 1024 / 1024
|
file_size_mb = latest_installer.stat().st_size / 1024 / 1024
|
||||||
|
|
||||||
logger.info(f"Found installer: {latest_installer.name}")
|
logger.info(f"Found installer: {latest_installer.name}")
|
||||||
logger.info(f"File size: {file_size_mb:.2f} MB")
|
logger.info(f"File size: {file_size_mb:.2f} MB")
|
||||||
|
|
||||||
return latest_installer
|
return latest_installer
|
||||||
|
|
||||||
|
|
||||||
def progress_callback(uploaded_bytes, total_bytes):
|
def progress_callback(uploaded_bytes, total_bytes):
|
||||||
"""Upload progress callback"""
|
"""Upload progress callback"""
|
||||||
if total_bytes > 0:
|
if total_bytes > 0:
|
||||||
percentage = (uploaded_bytes / total_bytes) * 100
|
percentage = (uploaded_bytes / total_bytes) * 100
|
||||||
uploaded_mb = uploaded_bytes / 1024 / 1024
|
uploaded_mb = uploaded_bytes / 1024 / 1024
|
||||||
total_mb = total_bytes / 1024 / 1024
|
total_mb = total_bytes / 1024 / 1024
|
||||||
logger.info(f"Upload progress: {percentage:.1f}% ({uploaded_mb:.1f}/{total_mb:.1f} MB)")
|
logger.info(f"Upload progress: {percentage:.1f}% ({uploaded_mb:.1f}/{total_mb:.1f} MB)")
|
||||||
|
|
||||||
|
|
||||||
def upload_installer(connection, installer_path):
|
def upload_installer(connection, installer_path):
|
||||||
"""Upload installer to KS3 with progress tracking"""
|
"""Upload installer to KS3 with progress tracking"""
|
||||||
try:
|
try:
|
||||||
bucket = connection.get_bucket(KS3_BUCKET)
|
bucket = connection.get_bucket(KS3_BUCKET)
|
||||||
ks3_key = f"{KS3_PREFIX}{installer_path.name}"
|
ks3_key = f"{KS3_PREFIX}{installer_path.name}"
|
||||||
|
|
||||||
file_size = installer_path.stat().st_size
|
file_size = installer_path.stat().st_size
|
||||||
file_size_mb = file_size / 1024 / 1024
|
file_size_mb = file_size / 1024 / 1024
|
||||||
|
|
||||||
logger.info(f"Starting upload to KS3...")
|
logger.info(f"Starting upload to KS3...")
|
||||||
logger.info(f"Target path: {ks3_key}")
|
logger.info(f"Target path: {ks3_key}")
|
||||||
logger.info(f"File size: {file_size_mb:.2f} MB")
|
logger.info(f"File size: {file_size_mb:.2f} MB")
|
||||||
logger.info(f"Estimated time: ~{int(file_size_mb / 2)} seconds (assuming 2MB/s)")
|
logger.info(f"Estimated time: ~{int(file_size_mb / 2)} seconds (assuming 2MB/s)")
|
||||||
logger.info("Please wait, this may take several minutes...")
|
logger.info("Please wait, this may take several minutes...")
|
||||||
|
|
||||||
key = bucket.new_key(ks3_key)
|
key = bucket.new_key(ks3_key)
|
||||||
|
|
||||||
# Upload file with public read permission and progress tracking
|
# Upload file with public read permission and progress tracking
|
||||||
# Use cb parameter for progress callback (called every 5% or every 10MB)
|
# Use cb parameter for progress callback (called every 5% or every 10MB)
|
||||||
key.set_contents_from_filename(
|
key.set_contents_from_filename(
|
||||||
str(installer_path),
|
str(installer_path),
|
||||||
headers={
|
headers={
|
||||||
'Content-Type': 'application/octet-stream',
|
'Content-Type': 'application/octet-stream',
|
||||||
'Content-Disposition': f'attachment; filename="{installer_path.name}"',
|
'Content-Disposition': f'attachment; filename="{installer_path.name}"',
|
||||||
'Cache-Control': 'public, max-age=3600',
|
'Cache-Control': 'public, max-age=3600',
|
||||||
'x-kss-storage-class': 'STANDARD',
|
'x-kss-storage-class': 'STANDARD',
|
||||||
'x-kss-acl': 'public-read' # Set public read permission in headers
|
'x-kss-acl': 'public-read' # Set public read permission in headers
|
||||||
},
|
},
|
||||||
policy='public-read', # Set ACL policy
|
policy='public-read', # Set ACL policy
|
||||||
cb=progress_callback, # Progress callback function
|
cb=progress_callback, # Progress callback function
|
||||||
num_cb=10 # Call callback 10 times during upload (every 10%)
|
num_cb=10 # Call callback 10 times during upload (every 10%)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Generate download URL (using KS3 third-level domain format)
|
# Generate download URL (using KS3 third-level domain format)
|
||||||
# Format: https://{bucket}.{endpoint}/{key}
|
# Format: https://{bucket}.{endpoint}/{key}
|
||||||
protocol = 'https' if KS3_IS_SECURE else 'http'
|
protocol = 'https' if KS3_IS_SECURE else 'http'
|
||||||
download_url = f"{protocol}://{KS3_BUCKET}.{KS3_ENDPOINT}/{ks3_key}"
|
download_url = f"{protocol}://{KS3_BUCKET}.{KS3_ENDPOINT}/{ks3_key}"
|
||||||
|
|
||||||
logger.info("")
|
logger.info("")
|
||||||
logger.info("=" * 70)
|
logger.info("=" * 70)
|
||||||
logger.info("Upload successful!")
|
logger.info("Upload successful!")
|
||||||
logger.info(f"Download URL: {download_url}")
|
logger.info(f"Download URL: {download_url}")
|
||||||
logger.info("=" * 70)
|
logger.info("=" * 70)
|
||||||
|
|
||||||
return download_url
|
return download_url
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("")
|
logger.error("")
|
||||||
logger.error("=" * 70)
|
logger.error("=" * 70)
|
||||||
logger.error(f"Upload failed: {e}")
|
logger.error(f"Upload failed: {e}")
|
||||||
logger.error("=" * 70)
|
logger.error("=" * 70)
|
||||||
import traceback
|
import traceback
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main function"""
|
"""Main function"""
|
||||||
logger.info("=" * 70)
|
logger.info("=" * 70)
|
||||||
logger.info("Starting GUI installer upload to KS3")
|
logger.info("Starting GUI installer upload to KS3")
|
||||||
logger.info(f"KS3 Endpoint: {KS3_ENDPOINT}")
|
logger.info(f"KS3 Endpoint: {KS3_ENDPOINT}")
|
||||||
logger.info(f"Bucket: {KS3_BUCKET}")
|
logger.info(f"Bucket: {KS3_BUCKET}")
|
||||||
logger.info(f"Target directory: {KS3_PREFIX}")
|
logger.info(f"Target directory: {KS3_PREFIX}")
|
||||||
logger.info("=" * 70)
|
logger.info("=" * 70)
|
||||||
|
|
||||||
installer_path = find_latest_installer()
|
installer_path = find_latest_installer()
|
||||||
if not installer_path:
|
if not installer_path:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
connection = get_ks3_connection()
|
connection = get_ks3_connection()
|
||||||
if not connection:
|
if not connection:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
download_url = upload_installer(connection, installer_path)
|
download_url = upload_installer(connection, installer_path)
|
||||||
if not download_url:
|
if not download_url:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
logger.info("=" * 70)
|
logger.info("=" * 70)
|
||||||
logger.info("Task completed successfully!")
|
logger.info("Task completed successfully!")
|
||||||
logger.info(f"Installer: {installer_path.name}")
|
logger.info(f"Installer: {installer_path.name}")
|
||||||
logger.info(f"Download URL: {download_url}")
|
logger.info(f"Download URL: {download_url}")
|
||||||
logger.info("=" * 70)
|
logger.info("=" * 70)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user