Files
ctms/scripts/onlyoffice-dev-up.sh
T
Cheng Zhou 1d26646a96
Client Quality Gates / Shared client and Web (push) Has been cancelled
Client Quality Gates / macOS Desktop (push) Has been cancelled
feat(collaboration): 完善在线文档协作与通知闭环
- 新增协作文件夹、文件、不可变修订、成员、会话、回调回执、编辑申请与分享链接数据模型。

- 补齐新建、导入、复制、下载、回收站、恢复、成员授权、所有权转让及文件级权限接口。

- 接入 ONLYOFFICE 共同编辑、历史版本预览与恢复、修订另存副本、导出下载审计和幂等回调保存。

- 增加编辑权限申请、审批通知、项目提醒聚合、通知 Feed、已读处理及历史待办数据回填。

- 支持公开分享的查看或编辑模式、有效期、密码哈希、失败锁定、短时访问凭证与固定分享地址。

- 增加协作者导出、申请编辑、工作表结构保护和所有权管理策略,并纳入项目接口权限矩阵。

- 新增协作文件库、编辑工作区、公开分享页、下载与另存为对话框,以及导航、路由和权限入口。

- 统一网页端与桌面端通知布局,增加沉浸式工作区和浏览器、Tauri 双端全屏能力。

- 扩展运行时文件下载适配、Tauri 环境识别和原生全屏命令,继续保持业务代码运行时边界。

- 加固 ONLYOFFICE 消息桥的同源下载、签名地址隔离和保存为能力校验,并更新桌面发布检查。

- 增加连续数据库迁移、50MB 上传限制、OnlyOffice 中文文案与开发启动路由校验。

- 补充协作、通知、权限、路由、运行时、布局和 OnlyOffice 相关测试及模块说明文档。
2026-07-16 14:14:54 +08:00

127 lines
4.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/common.sh
source "$SCRIPT_DIR/common.sh"
ROTATE_SECRET=0
if [[ "${1:-}" == "--rotate-secret" ]]; then
ROTATE_SECRET=1
shift
fi
if [[ $# -gt 0 ]]; then
ctms_fail "未知参数: $1(支持的参数仅有 --rotate-secret"
fi
generate_random_hex() {
local bytes="${1:-32}"
if command -v openssl >/dev/null 2>&1; then
openssl rand -hex "$bytes"
return
fi
od -An -N "$bytes" -tx1 /dev/urandom | tr -d ' \n'
}
prepare_onlyoffice_environment() {
local secret current_login_secret instance_id generated=0
secret="$(ctms_read_env_value ONLYOFFICE_JWT_SECRET || true)"
current_login_secret="$(ctms_read_env_value JWT_SECRET_KEY || true)"
instance_id="$(ctms_read_env_value ONLYOFFICE_INSTANCE_ID || true)"
if [[ "$ROTATE_SECRET" -eq 1 || ${#secret} -lt 32 || "$secret" == "$current_login_secret" ]]; then
secret="$(generate_random_hex 32)"
ctms_upsert_env_value ONLYOFFICE_JWT_SECRET "$secret"
generated=1
fi
if [[ -z "$instance_id" ]]; then
instance_id="ctms-dev-$(generate_random_hex 8)"
ctms_upsert_env_value ONLYOFFICE_INSTANCE_ID "$instance_id"
fi
ctms_upsert_env_value ONLYOFFICE_ENABLED true
ctms_upsert_env_value ONLYOFFICE_INTERNAL_URL http://onlyoffice
ctms_upsert_env_value ONLYOFFICE_STORAGE_BASE_URL http://backend:8000
ctms_upsert_env_value ONLYOFFICE_CONFIG_TTL_SECONDS 300
chmod 600 "$CTMS_ENV_FILE"
if [[ "$generated" -eq 1 ]]; then
ctms_ok "已生成新的 ONLYOFFICE 开发密钥并写入 .env(内容不会回显)"
else
ctms_ok "已复用 .env 中现有的 ONLYOFFICE 开发密钥"
fi
ctms_ok "ONLYOFFICE 开发实例标识已就绪: $instance_id"
}
wait_for_url() {
local label="$1" url="$2" attempts="${3:-90}" attempt=1
while [[ "$attempt" -le "$attempts" ]]; do
if curl -fsS "$url" >/dev/null 2>&1; then
ctms_ok "$label 已就绪"
return 0
fi
sleep 2
attempt=$(( attempt + 1 ))
done
ctms_fail "$label 未在预期时间内就绪: $url"
}
main() {
cd "$CTMS_ROOT_DIR"
ctms_require_docker_compose
ctms_require_command curl "macOS 通常已预装;Linux 可执行 apt-get install curl" \
|| ctms_fail "缺少 curl,无法执行启动健康检查"
ctms_step "准备 ONLYOFFICE 开发环境"
prepare_onlyoffice_environment
local -a compose=(
docker compose
-f "$CTMS_ROOT_DIR/docker-compose.dev.yaml"
-p ctms_dev
--profile office
)
ctms_step "校验开发 Compose 配置"
"${compose[@]}" config --quiet
ctms_ok "Compose 配置有效"
ctms_step "构建并启动 Office 预览服务"
"${compose[@]}" up -d --build --force-recreate backend onlyoffice nginx
ctms_step "验证运行状态"
wait_for_url "CTMS 后端" "http://127.0.0.1:8888/readyz" 60
wait_for_url "ONLYOFFICE Document Server" "http://127.0.0.1:8888/onlyoffice/healthcheck" 120
"${compose[@]}" exec -T backend python -c '
from app.core.config import settings
from app.main import app
paths = {route.path for route in app.routes}
required = {
"/api/v1/onlyoffice/attachments/{attachment_id}/config",
"/api/v1/onlyoffice/versions/{version_id}/config",
"/api/v1/studies/{study_id}/collaboration/files/{file_id}/editor-config",
"/api/v1/studies/{study_id}/collaboration/files/{file_id}/share-link",
"/api/v1/collaboration/shares/metadata",
"/api/v1/collaboration/shares/access",
"/api/v1/collaboration/shares/editor-config",
"/internal/onlyoffice/collaboration/sessions/{session_id}/content",
"/internal/onlyoffice/collaboration/sessions/{session_id}/callback",
}
if not settings.ONLYOFFICE_ENABLED:
raise SystemExit("ONLYOFFICE_ENABLED 未生效")
if len(settings.ONLYOFFICE_JWT_SECRET or "") < 32:
raise SystemExit("ONLYOFFICE_JWT_SECRET 未生效")
if not settings.ONLYOFFICE_INSTANCE_ID:
raise SystemExit("ONLYOFFICE_INSTANCE_ID 未生效")
missing = required - paths
if missing:
raise SystemExit(f"后端缺少 ONLYOFFICE 路由: {sorted(missing)}")
print("ONLYOFFICE backend configuration and routes are ready")
'
ctms_ok "ONLYOFFICE 开发预览环境启动完成"
}
main