|
|
"""文件系统配置服务"""
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
def init_app(app):
|
|
|
"""初始化文件系统配置(系统启动时自动执行)"""
|
|
|
with app.app_context():
|
|
|
# pass
|
|
|
_init_file_system_config()
|
|
|
|
|
|
|
|
|
def _init_file_system_config():
|
|
|
"""初始化文件系统配置"""
|
|
|
from iti.applications.extensions import db
|
|
|
from iti.applications.models import SysConfig
|
|
|
from iti.applications.common.enums import StatusEnum
|
|
|
|
|
|
configs = [
|
|
|
{
|
|
|
"type": "SYSTEM",
|
|
|
"name": "后端访问地址",
|
|
|
"code": "BACKEND_URL",
|
|
|
"value": "http://localhost:5000",
|
|
|
"desc": "后端访问地址。应配置为前端可访问的后端地址(通常是Nginx反向代理的公网地址)",
|
|
|
"sort": 90,
|
|
|
},
|
|
|
{
|
|
|
"type": "SYSTEM",
|
|
|
"name": "文件回收站功能",
|
|
|
"code": "FILE_RECYCLE_ENABLED",
|
|
|
"value": "true",
|
|
|
"desc": "是否启用文件回收站功能。启用后,删除文件会移动到回收站而不是直接删除",
|
|
|
"sort": 100,
|
|
|
},
|
|
|
{
|
|
|
"type": "SYSTEM",
|
|
|
"name": "回收站保留天数",
|
|
|
"code": "FILE_RECYCLE_DAYS",
|
|
|
"value": "30",
|
|
|
"desc": "回收站文件保留天数,超过此天数的文件将被自动清理",
|
|
|
"sort": 101,
|
|
|
},
|
|
|
{
|
|
|
"type": "SYSTEM",
|
|
|
"name": "文件分享功能",
|
|
|
"code": "FILE_SHARE_ENABLED",
|
|
|
"value": "true",
|
|
|
"desc": "是否启用文件分享功能",
|
|
|
"sort": 102,
|
|
|
},
|
|
|
{
|
|
|
"type": "SYSTEM",
|
|
|
"name": "分享默认过期时间",
|
|
|
"code": "FILE_SHARE_DEFAULT_EXPIRE_HOURS",
|
|
|
"value": "168",
|
|
|
"desc": "文件分享默认过期时间(小时),168小时=7天,0表示永久",
|
|
|
"sort": 103,
|
|
|
},
|
|
|
{
|
|
|
"type": "SYSTEM",
|
|
|
"name": "分片上传阈值",
|
|
|
"code": "FILE_CHUNK_THRESHOLD",
|
|
|
"value": "104857600",
|
|
|
"desc": "文件大小超过此阈值(字节)时使用分片上传,默认100MB。前端根据此值判断使用直接上传还是分片上传",
|
|
|
"sort": 104,
|
|
|
},
|
|
|
{
|
|
|
"type": "SYSTEM",
|
|
|
"name": "分片上传分片大小",
|
|
|
"code": "FILE_CHUNK_SIZE",
|
|
|
"value": "2097152",
|
|
|
"desc": "分片上传时每个分片的大小(字节),默认2MB",
|
|
|
"sort": 105,
|
|
|
},
|
|
|
]
|
|
|
|
|
|
for config_data in configs:
|
|
|
# 检查配置是否已存在
|
|
|
existing = SysConfig.query.filter_by(
|
|
|
type=config_data["type"], code=config_data["code"]
|
|
|
).first()
|
|
|
|
|
|
if not existing:
|
|
|
config = SysConfig(
|
|
|
type=config_data["type"],
|
|
|
name=config_data["name"],
|
|
|
code=config_data["code"],
|
|
|
value=config_data["value"],
|
|
|
desc=config_data["desc"],
|
|
|
sort=config_data["sort"],
|
|
|
status=StatusEnum.ENABLED,
|
|
|
)
|
|
|
db.session.add(config)
|
|
|
|
|
|
try:
|
|
|
db.session.commit()
|
|
|
except Exception as e:
|
|
|
db.session.rollback()
|
|
|
print(f"⚠️ 文件系统配置初始化失败: {e}")
|