From d0e1f5adfd2c510ce6b5b3d50030e8b3064a04f5 Mon Sep 17 00:00:00 2001 From: "juancarlos.cavero" Date: Thu, 20 Aug 2026 19:29:55 +0200 Subject: [PATCH] feat: raise the self-host job retention default to 24h and surface it in the UI Issue #46 round two: the 1h sweep kept deleting finished projects under self-hosters who never touched their env. The disk is already bounded by OUTPUT_MAX_GB / UPLOADS_MAX_GB, so age can afford to be generous. Cloud keeps the tight default because clips are archived to R2 on completion. The results panel now tells self-host users how long their clips live and which env var controls it, and the restorable-session window follows the new default. --- app.py | 10 +++++++++- dashboard/src/App.jsx | 20 ++++++++++++++++++-- dashboard/src/contexts/AuthContext.jsx | 1 + 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 209d679..e222316 100644 --- a/app.py +++ b/app.py @@ -47,7 +47,6 @@ MAX_FILE_SIZE_MB = 2048 # 2GB limit # where covers, sounds and hashtags actually get chosen. The UI must say so — # a user who expects a published post and finds a draft will read it as a bug. TIKTOK_POST_MODE = os.environ.get("TIKTOK_POST_MODE", "MEDIA_UPLOAD").strip() -JOB_RETENTION_SECONDS = int(os.environ.get("JOB_RETENTION_SECONDS", "3600")) # job/file retention (issue #46) # Ceiling for the working directory once it lives on a persistent volume: the # age-based sweep alone can't stop a burst of long videos from filling the disk. # 0 disables the cap. @@ -65,6 +64,14 @@ DISABLE_YOUTUBE_URL = os.environ.get("DISABLE_YOUTUBE_URL", "false").lower() in # when BILLING_ENABLED is set. With the flag off, the app behaves exactly as the # self-hosted BYOK app does today (no extra dependencies required). BILLING_ENABLED = os.environ.get("BILLING_ENABLED", "").lower() in ("1", "true", "yes") + +# Job/file retention (issue #46). Self-host defaults to 24h: the 1h sweep kept +# deleting finished projects under users who never touched their env, and the +# OUTPUT_MAX_GB / UPLOADS_MAX_GB caps below already bound the disk. Cloud keeps +# the tight default because clips are archived to R2 as soon as a job finishes. +JOB_RETENTION_SECONDS = int( + os.environ.get("JOB_RETENTION_SECONDS", "3600" if BILLING_ENABLED else "86400") +) # Force full pipeline logs to the client even under billing (local debugging). DEBUG_LOGS = os.environ.get("DEBUG_LOGS", "").lower() in ("1", "true", "yes") @@ -1391,6 +1398,7 @@ async def get_config(): "youtubeUrlEnabled": not DISABLE_YOUTUBE_URL, "billingEnabled": BILLING_ENABLED, "googleAuthEnabled": bool(BILLING_ENABLED and cloud.settings.google_auth_enabled), + "jobRetentionSeconds": JOB_RETENTION_SECONDS, } async def _probe_youtube_quality(url: str) -> dict: diff --git a/dashboard/src/App.jsx b/dashboard/src/App.jsx index 3972a53..3cfc1cb 100644 --- a/dashboard/src/App.jsx +++ b/dashboard/src/App.jsx @@ -75,6 +75,12 @@ const TikTokIcon = ({ size = 16, className = "" }) => ( // meaningless to the user, so the selector shows connected networks instead. const isAutoProfileId = (username) => /^os_[0-9a-f]/i.test(username || ""); +const formatRetention = (seconds) => { + if (seconds >= 86400) return `${Math.round(seconds / 86400)} day${seconds >= 172800 ? 's' : ''}`; + if (seconds >= 3600) return `${Math.round(seconds / 3600)} hour${seconds >= 7200 ? 's' : ''}`; + return `${Math.max(1, Math.round(seconds / 60))} min`; +}; + const ProfileNetworkIcons = ({ profile, size = 12 }) => ( @@ -163,7 +169,9 @@ const UserProfileSelector = ({ profiles, selectedUserId, onSelect }) => { }; const SESSION_KEY = 'openshorts_session'; -const SESSION_MAX_AGE = 3600000; // 1 hour (matches server job retention) +// Matches the self-host JOB_RETENTION_SECONDS default. A restore whose job was +// already purged server-side fails gracefully and clears the saved session. +const SESSION_MAX_AGE = 86400000; // 24 hours // Mock polling function const pollJob = async (jobId) => { @@ -174,7 +182,7 @@ const pollJob = async (jobId) => { function App() { // Cloud auth/billing session (inert when billing is disabled). - const { billingEnabled, isManaged, isSignedIn, me, plan, refreshMe } = useAuth(); + const { billingEnabled, isManaged, isSignedIn, me, plan, refreshMe, jobRetentionSeconds } = useAuth(); const [showLogin, setShowLogin] = useState(false); const [showTopUp, setShowTopUp] = useState(false); const [showPlanChoice, setShowPlanChoice] = useState(false); @@ -1451,6 +1459,14 @@ function App() { Keep them forever → )} + {/* Self-host only: cloud archives clips to the video library, + here they really are gone once the retention sweep runs. */} + {!billingEnabled && jobRetentionSeconds > 0 && ( +
+ Clips are kept for {formatRetention(jobRetentionSeconds)}, then deleted.{' '} + Download what you want to keep, or raise JOB_RETENTION_SECONDS in your env. +
+ )} )} diff --git a/dashboard/src/contexts/AuthContext.jsx b/dashboard/src/contexts/AuthContext.jsx index cf9939d..a2287a3 100644 --- a/dashboard/src/contexts/AuthContext.jsx +++ b/dashboard/src/contexts/AuthContext.jsx @@ -134,6 +134,7 @@ export function AuthProvider({ children }) { const value = { billingEnabled: config.billingEnabled, googleAuthEnabled: config.googleAuthEnabled, + jobRetentionSeconds: config.jobRetentionSeconds || null, loading, signingIn, user: me?.user || null,