Files
LeoVasanko b5f4f67813 oosetup: return exit code, not the secret
The mediapreview setup_docker() return value (the JWT secret) was passed
through to main() and sys.exit(), printing it a second time on stderr
with a failure exit code. The secret is already printed to stdout in the
finally block; return 0 on success.
2026-08-13 07:16:17 +00:00

49 lines
1.3 KiB
Python

"""Cista-specific OnlyOffice setup.
The conversion client itself lives in `mediapreview.office`; this module
only bridges cista's config-derived JWT secret into it and wires the
`--oosetup` Docker bootstrap to cista's config.
"""
import os
import sys
from pathlib import Path
import mediapreview.office
from cista import config
def configure() -> None:
"""Point mediapreview's OnlyOffice client at cista's derived JWT secret."""
os.environ.setdefault(
"ONLYOFFICE_JWT_SECRET", config.derived_secret("onlyoffice", size=16).hex()
)
def setup_docker(confdir: Path | None = None) -> int:
"""Build and run the patched OnlyOffice Docker image (via mediapreview)."""
if confdir is not None:
os.environ["CISTA_HOME"] = confdir.as_posix()
config.init_confdir()
if config.conffile.exists():
config.load_config()
else:
config.update_config(
{
"listen": ":8989",
"path": Path.home() / "Downloads",
"public": False,
}
)
configure()
try:
mediapreview.office.setup_docker()
finally:
# Print regardless of build outcome: the secret is deterministic
# (derived from the config).
sys.stdout.write(
f"ONLYOFFICE_JWT_SECRET={os.environ['ONLYOFFICE_JWT_SECRET']}\n"
)
return 0