feat: improve Doris dashboard lead warrant controls
This commit is contained in:
@@ -20,6 +20,7 @@ PUBLIC = ROOT / 'public'
|
||||
DIGEST_ROOT = Path(os.environ.get('DORIS_DIGEST_DIR', '/home/fizzlepoof/.openclaw/workspace/doris-digest'))
|
||||
DIGEST_FEEDBACK = DIGEST_ROOT / 'data' / 'feedback.json'
|
||||
PAPERLESS_STATE = ROOT / 'data' / 'paperless_review_state.json'
|
||||
LEAD_WARRANT_STATE = ROOT / 'data' / 'lead_warrant_state.json'
|
||||
DONETICK_SECRET = Path('/home/fizzlepoof/.openclaw/workspace/.secrets/donetick_secrets.json.enc')
|
||||
DONETICK_KEY = Path('/home/fizzlepoof/.openclaw/workspace/.secrets/encryption.key')
|
||||
GENERATOR = ROOT / 'bin' / 'generate_dashboard.py'
|
||||
@@ -87,6 +88,26 @@ def refresh_dashboard() -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def load_lead_warrant_state() -> dict:
|
||||
state = load_json(LEAD_WARRANT_STATE, {})
|
||||
if not isinstance(state, dict):
|
||||
state = {}
|
||||
acknowledged = state.get('acknowledged', [])
|
||||
ignored_sources = state.get('ignored_sources', [])
|
||||
ignored_topics = state.get('ignored_topics', [])
|
||||
if not isinstance(acknowledged, list):
|
||||
acknowledged = []
|
||||
if not isinstance(ignored_sources, list):
|
||||
ignored_sources = []
|
||||
if not isinstance(ignored_topics, list):
|
||||
ignored_topics = []
|
||||
return {
|
||||
'acknowledged': [str(x).strip() for x in acknowledged if str(x).strip()][:250],
|
||||
'ignored_sources': [str(x).strip().lower() for x in ignored_sources if str(x).strip()][:100],
|
||||
'ignored_topics': [str(x).strip().lower() for x in ignored_topics if str(x).strip()][:100],
|
||||
}
|
||||
|
||||
|
||||
def parse_dt(value: str | None):
|
||||
if not value:
|
||||
return None
|
||||
@@ -167,6 +188,10 @@ class Handler(SimpleHTTPRequestHandler):
|
||||
return self._paperless_action(payload)
|
||||
if self.path == '/api/donetick-complete':
|
||||
return self._donetick_complete(payload)
|
||||
if self.path == '/api/lead-warrant-ack':
|
||||
return self._lead_warrant_ack(payload)
|
||||
if self.path == '/api/lead-warrant-ignore':
|
||||
return self._lead_warrant_ignore(payload)
|
||||
return self._json(HTTPStatus.NOT_FOUND, {'ok': False, 'error': 'not_found'})
|
||||
|
||||
def _topic_feedback(self, payload: dict):
|
||||
@@ -233,6 +258,58 @@ class Handler(SimpleHTTPRequestHandler):
|
||||
except Exception as e:
|
||||
return self._json(HTTPStatus.BAD_GATEWAY, {'ok': False, 'error': 'donetick_complete_failed', 'detail': str(e)})
|
||||
|
||||
def _lead_warrant_ack(self, payload: dict):
|
||||
key = str(payload.get('key') or '').strip()
|
||||
if not key:
|
||||
return self._json(HTTPStatus.BAD_REQUEST, {'ok': False, 'error': 'bad_payload', 'detail': 'expected key'})
|
||||
state = load_lead_warrant_state()
|
||||
acknowledged = [x for x in state.get('acknowledged', []) if x != key]
|
||||
acknowledged.append(key)
|
||||
save_json(LEAD_WARRANT_STATE, {
|
||||
'acknowledged': acknowledged[-250:],
|
||||
'ignored_sources': state.get('ignored_sources', []),
|
||||
'ignored_topics': state.get('ignored_topics', []),
|
||||
})
|
||||
refreshed = refresh_dashboard()
|
||||
return self._json(HTTPStatus.OK, {'ok': True, 'key': key, 'dashboard_refreshed': refreshed})
|
||||
|
||||
def _lead_warrant_ignore(self, payload: dict):
|
||||
key = str(payload.get('key') or '').strip()
|
||||
mode = str(payload.get('mode') or '').strip().lower()
|
||||
topic = str(payload.get('topic') or '').strip().lower()
|
||||
source = str(payload.get('source') or '').strip().lower()
|
||||
if not key or mode not in {'topic', 'source'}:
|
||||
return self._json(HTTPStatus.BAD_REQUEST, {'ok': False, 'error': 'bad_payload', 'detail': 'expected key and mode'})
|
||||
state = load_lead_warrant_state()
|
||||
acknowledged = [x for x in state.get('acknowledged', []) if x != key]
|
||||
acknowledged.append(key)
|
||||
ignored_sources = [x for x in state.get('ignored_sources', []) if x]
|
||||
ignored_topics = [x for x in state.get('ignored_topics', []) if x]
|
||||
if mode == 'topic':
|
||||
if not topic:
|
||||
return self._json(HTTPStatus.BAD_REQUEST, {'ok': False, 'error': 'bad_payload', 'detail': 'expected topic'})
|
||||
ignored_topics = [x for x in ignored_topics if x != topic]
|
||||
ignored_topics.append(topic)
|
||||
else:
|
||||
if not source:
|
||||
return self._json(HTTPStatus.BAD_REQUEST, {'ok': False, 'error': 'bad_payload', 'detail': 'expected source'})
|
||||
ignored_sources = [x for x in ignored_sources if x != source]
|
||||
ignored_sources.append(source)
|
||||
save_json(LEAD_WARRANT_STATE, {
|
||||
'acknowledged': acknowledged[-250:],
|
||||
'ignored_sources': ignored_sources[-100:],
|
||||
'ignored_topics': ignored_topics[-100:],
|
||||
})
|
||||
refreshed = refresh_dashboard()
|
||||
return self._json(HTTPStatus.OK, {
|
||||
'ok': True,
|
||||
'key': key,
|
||||
'mode': mode,
|
||||
'ignored_source': source if mode == 'source' else '',
|
||||
'ignored_topic': topic if mode == 'topic' else '',
|
||||
'dashboard_refreshed': refreshed,
|
||||
})
|
||||
|
||||
def _donetick_focus_state(self, parsed):
|
||||
current = urllib.parse.parse_qs(parsed.query).get('current', [''])[0]
|
||||
signature, urgent_count = fetch_donetick_focus_signature()
|
||||
|
||||
Reference in New Issue
Block a user