MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / clear_files_api

Function clear_files_api

webapp_modern.py:16335–16392  ·  view source on GitHub ↗

Clear files from specified directories

()

Source from the content-addressed store, hash-verified

16333 totals['awarded_currency'] += int(body.get('awarded_currency') or 0)
16334 return {'ok': True, 'status': 200, 'mode': 'signals', 'response': totals}
16335
16336
16337def _upload_wardrift(csv_text):
16338 token = (shared_data.config.get('wardrift_session_token') or '').strip()
16339 key, bad = _clean_credential(shared_data.config.get('wardrift_api_key'))
16340 if bad:
16341 if not token:
16342 return {'ok': False, 'error': f'The saved Wardrift API key is invalid: {bad}', 'rejected': True}
16343 key = ''
16344 if not (token or key):
16345 return {'ok': False, 'error': 'Wardrift not configured (sign in or add an API key)', 'rejected': True}
16346 try:
16347 if token:
16348 res = _upload_wardrift_route(csv_text, token)
16349 # Expired session but a device key is on file -> still get the data in.
16350 if not res.get('ok') and res.get('status') == 401 and key:
16351 return _upload_wardrift_signals(csv_text, key)
16352 return res
16353 return _upload_wardrift_signals(csv_text, key)
16354 except Exception as e:
16355 return {'ok': False, 'error': str(e)}
16356
16357
16358UPLOAD_TARGETS = ('wigle', 'wdgwars', 'wardrift')
16359_UPLOADERS = {'wigle': _upload_wigle, 'wdgwars': _upload_wdgwars, 'wardrift': _upload_wardrift}
16360
16361
16362def _upload_target_list(target):
16363 """'both' (legacy = WiGLE+WDGWars), 'all', or a comma list -> [targets];
16364 None if any name is unknown."""
16365 t = (target or 'wdgwars').lower().strip()
16366 if t == 'both':
16367 return ['wigle', 'wdgwars']
16368 if t == 'all':
16369 return list(UPLOAD_TARGETS)
16370 out = [x.strip() for x in t.split(',') if x.strip()]
16371 if not out or any(x not in UPLOAD_TARGETS for x in out):
16372 return None
16373 return out
16374
16375
16376# ---------------------------------------------------------------------------
16377# Auto-upload: when a wardrive finishes, queue it and push it to the services
16378# ticked in the Auto-upload card (WiGLE / WDGWars / Wardrift).
16379#
16380# * Every stop path queues the drive: the engine calls SESSION_FINISHED_HOOKS
16381# from stop(), whoever stopped it (web UI, CYD, display keys, diagnostic
16382# mode) and whichever engine instance ran it (webapp or the boot engine).
16383# * A drive cut off by power loss has no end_time; once the box is back up,
16384# unfinished sessions started after auto-upload was switched on are queued.
16385# * The queue is persisted, so an offline box retries every 60 s until it has
16386# connectivity again, and only retries the services that failed.
16387# * Wardrift processes route uploads asynchronously (202 "pending", decided
16388# seconds to minutes later), so its uploads are followed to the final
16389# succeeded/failed result. Every outcome lands in upload_history.json, which
16390# the Auto-upload card shows as "Recent uploads".
16391# ---------------------------------------------------------------------------
16392_AUTO_UPLOAD_SAVE_LOCK = threading.Lock()

Callers

nothing calls this directly

Calls 4

warningMethod · 0.80
infoMethod · 0.80
errorMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected