127 lines
3.1 KiB
Python
Executable File
127 lines
3.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
路径修复脚本 - 确保所有文件路径正确
|
|
"""
|
|
import os
|
|
import re
|
|
from pathlib import Path
|
|
|
|
def fix_html_paths():
|
|
"""修复HTML中的静态资源路径"""
|
|
html_file = Path("static/index.html")
|
|
|
|
if not html_file.exists():
|
|
print(f"❌ 文件不存在: {html_file}")
|
|
return False
|
|
|
|
print("🔧 修复HTML中的静态资源路径...")
|
|
|
|
with open(html_file, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
# 修复CSS路径
|
|
content = re.sub(
|
|
r'<link rel="stylesheet" href="(?!/)([^"]+\.css)"',
|
|
r'<link rel="stylesheet" href="/static/\1"',
|
|
content
|
|
)
|
|
|
|
# 修复JS路径
|
|
content = re.sub(
|
|
r'<script src="(?!/)([^"]+\.js)"',
|
|
r'<script src="/static/\1"',
|
|
content
|
|
)
|
|
|
|
# 修复图片路径(如果有的话)
|
|
content = re.sub(
|
|
r'<img src="(?!/)(?!http)([^"]+\.(png|jpg|jpeg|gif|svg))"',
|
|
r'<img src="/static/\1"',
|
|
content
|
|
)
|
|
|
|
with open(html_file, 'w', encoding='utf-8') as f:
|
|
f.write(content)
|
|
|
|
print("✅ HTML路径修复完成")
|
|
return True
|
|
|
|
def check_file_structure():
|
|
"""检查文件结构是否正确"""
|
|
print("📁 检查文件结构...")
|
|
|
|
required_files = [
|
|
"app.py",
|
|
"cli.py",
|
|
"requirements.txt",
|
|
"static/index.html",
|
|
"static/style.css",
|
|
"static/app.js"
|
|
]
|
|
|
|
missing_files = []
|
|
|
|
for file_path in required_files:
|
|
if not Path(file_path).exists():
|
|
missing_files.append(file_path)
|
|
print(f"❌ 缺少文件: {file_path}")
|
|
else:
|
|
print(f"✅ 文件存在: {file_path}")
|
|
|
|
if missing_files:
|
|
print(f"\n⚠️ 缺少 {len(missing_files)} 个文件")
|
|
return False
|
|
else:
|
|
print("\n🎉 所有必需文件都存在")
|
|
return True
|
|
|
|
def create_missing_directories():
|
|
"""创建缺失的目录"""
|
|
print("📂 创建必需目录...")
|
|
|
|
directories = [
|
|
"static",
|
|
"uploads",
|
|
"data",
|
|
"data/uploads",
|
|
"data/logs"
|
|
]
|
|
|
|
for dir_path in directories:
|
|
Path(dir_path).mkdir(parents=True, exist_ok=True)
|
|
print(f"✅ 目录已确保存在: {dir_path}")
|
|
|
|
def main():
|
|
"""主函数"""
|
|
print("🔧 文件传输服务路径修复工具")
|
|
print("=" * 50)
|
|
|
|
# 检查当前目录
|
|
if not Path("app.py").exists():
|
|
print("❌ 请在fileshare目录中运行此脚本")
|
|
print("💡 cd fileshare && python fix_paths.py")
|
|
return False
|
|
|
|
# 创建目录
|
|
create_missing_directories()
|
|
|
|
# 检查文件结构
|
|
if not check_file_structure():
|
|
print("\n❌ 文件结构不完整,请检查")
|
|
return False
|
|
|
|
# 修复HTML路径
|
|
if not fix_html_paths():
|
|
return False
|
|
|
|
print("\n" + "=" * 50)
|
|
print("✅ 路径修复完成!")
|
|
print("\n🚀 现在可以启动服务:")
|
|
print(" python app.py")
|
|
print("\n🧪 或运行测试:")
|
|
print(" python test_server.py")
|
|
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
main() |