Files
2026-10-09 13:43:27 +00:00

5.0 KiB

Policy collector operations

Production URL: https://code.knickqueue.win/deepseek-primetime/policy.json.

The collector fetches the official DeepSeek USD pricing page and the configured official Chinese holiday notices. It uses ETag/Last-Modified conditional requests, a 1 MiB source limit, bounded requests, and an explicit official-domain allowlist. If the host's local resolver cannot resolve an official source, the request uses Cloudflare DNS-over-HTTPS while preserving the original TLS hostname, SNI, and certificate verification. System DNS configuration is unchanged.

The HTML parser expands row/column spans, maps prices by token category and model column, and accepts only supported policy grammar. It checks table discounts against any explicitly stated percentage. Unknown wording or source contradictions publish reviewRequired with the last accepted rates. Network failures publish unavailable. Neither failure renews the source-verification timestamp or 48-hour expiry.

Installed layout

  • /opt/deepseek-primetime/: root-owned collector code and calendar configuration.
  • /var/lib/deepseek-primetime/: private signing key, downloaded sources, and last policy; mode 0700.
  • /var/www/deepseek-primetime/: signed public feed, public key, and revision history. Nginx exposes only policy.json and public-key.xml.
  • deepseek-primetime.service: bounded, unprivileged systemd oneshot.
  • deepseek-primetime.timer: hourly checks, enabled at boot.

RSA-3072/SHA-256 signs the exact UTF-8 payload bytes using PKCS#1 v1.5. The envelope contains base64 payload and signature plus a key identifier. The app pins the public key at build time; it does not download a replacement key. Keep the signing key out of Git and back it up using the server's private backup process. Loss/rotation of the key requires rebuilding clients with a newly pinned key.

Install on another server

Install Python 3.10+ and cryptography using your system package manager or an isolated environment. Place the explicitly listed collector, calendar, service, timer, Nginx snippet, and deployment script files under /opt/deepseek-primetime, then run sh deploy.sh as root after reviewing the paths. This script is specifically configured for the existing code-gitea Nginx site; adjust the insertion anchor and HTTPS hostname for another server.

The initial successful collection creates the private key. Obtain public-key.xml over a trusted administrative connection, put it in the project root, and rebuild the app. Configure PolicyClient.FeedUrl for another host. Never copy the private signing key into the client or repository.

Routine verification

Use systemctl status deepseek-primetime.timer, systemctl list-timers deepseek-primetime.timer, and journalctl -u deepseek-primetime.service. Trigger an immediate run with systemctl start deepseek-primetime.service. A network/review problem can still exit successfully because it publishes signed degraded health; inspect sourceStatus and sourceVerifiedAtUtc in the decoded payload as well as the process exit code.

The app shows an amber state for review-required data, missing calendar coverage, expired verification, or invalid updates. It keeps historical rates visible for reference without claiming they are current. Routine freshness revisions do not trigger repeated policy-change notifications.

Calendar and parser upkeep

calendars.json currently names the official 2026 State Council holiday notice republished by Beijing's government. Add the following year's official notice once published. The parser expects seven named holiday ranges, understands parenthesized lunar-date/weekday notes, and ignores compensatory working-day statements for weekend pricing. Tests cover year and structure mismatch.

For a page/policy change, save a focused official fixture, update parse_pricing or parse_calendar, and run the collector tests before deployment. Arbitrary natural-language rules are not automatically interpreted. Future notices are currently recognized in the explicit New prices take effect at YYYY-MM-DD HH:MM UTC. format; other formats request review. The signed schema supports scheduled/flat modes, per-model rates, cross-midnight windows, explicit calendar dates, and one pending policy.

Recovery

The feed and local accepted state are written atomically; every published envelope is retained in history/. Correct a source/configuration problem and run the collector again to issue a newer signed revision. Clients reject lower revisions and changed contents at the same revision, so recovery must publish a new revision rather than restoring an old public file.

Before changing the Nginx site, deploy.sh saves a timestamped backup. Test with nginx -t before reloading. To disable collection, use systemctl disable --now deepseek-primetime.timer; clients will progressively enter cached/expired status. Removing the Nginx include and reloading Nginx stops serving the feed. Preserve private state and the signing key when migrating or recovering.