MCPcopy Create free account
hub / github.com/error311/FileRise / startCryptoRunner

Function startCryptoRunner

public/js/folderManager.js:3177–3262  ·  view source on GitHub ↗
({ jobId, folder, mode, minimized })

Source from the content-addressed store, hash-verified

3175}
3176
3177async function startCryptoRunner({ jobId, folder, mode, minimized }) {
3178 if (__cryptoRunner) {
3179 clearTimeout(__cryptoRunner);
3180 __cryptoRunner = null;
3181 }
3182
3183 ensureCryptoJobUi();
3184 ensureCryptoTransferUiJob(folder, mode, 0, 0);
3185 setCryptoUiMinimized(!!minimized);
3186
3187 const tickOnce = async () => {
3188 const resp = await fetchWithCsrf(withBase('/api/folder/encryptionJobTick.php'), {
3189 method: 'POST',
3190 headers: { 'Content-Type': 'application/json' },
3191 body: JSON.stringify({ jobId, maxFiles: 1 })
3192 });
3193 return safeJson(resp);
3194 };
3195
3196 const statusOnce = async () => {
3197 const resp = await fetch(withBase(`/api/folder/encryptionJobStatus.php?jobId=${encodeURIComponent(jobId)}`), { credentials: 'include' });
3198 return safeJson(resp);
3199 };
3200
3201 let latestJob = null;
3202 const tickWithHeartbeat = async () => {
3203 let hb = null;
3204 try {
3205 hb = setInterval(() => {
3206 if (!latestJob || String(latestJob.state || '').toLowerCase() !== 'running') return;
3207 renderCryptoJobUi({
3208 folder,
3209 mode,
3210 job: { ...latestJob, _tickPending: true }
3211 });
3212 }, 350);
3213 return await tickOnce();
3214 } finally {
3215 if (hb) clearInterval(hb);
3216 }
3217 };
3218
3219 const loop = async () => {
3220 try {
3221 const st = await statusOnce();
3222 const job = st?.job || null;
3223 latestJob = job;
3224 renderCryptoJobUi({ folder, mode, job });
3225
3226 if (!job || job.state === 'done') {
3227 finalizeCryptoJobUi({ folder, mode, jobId, ok: true });
3228 return;
3229 }
3230 if (job.state === 'error') {
3231 finalizeCryptoJobUi({ folder, mode, jobId, ok: false, error: job.error });
3232 return;
3233 }
3234

Callers 2

startFolderCryptoJobFlowFunction · 0.85

Calls 4

ensureCryptoJobUiFunction · 0.85
setCryptoUiMinimizedFunction · 0.85
loopFunction · 0.85

Tested by

no test coverage detected