Fix KV to store only revenues, add GitHub Actions auto-deploy
Some checks are pending
Deploy to Cloudflare / deploy (push) Waiting to run
Some checks are pending
Deploy to Cloudflare / deploy (push) Waiting to run
- KV 'revenues' key now stores only {id: number} — names/labels/config
always come from code so code changes always take effect immediately
- Remove stale 'competitors' KV dependency
- Add .github/workflows/deploy.yml to auto-deploy to Cloudflare on push
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
9c8a2dbe2d
commit
8fc2cfce97
2 changed files with 32 additions and 10 deletions
19
.github/workflows/deploy.yml
vendored
Normal file
19
.github/workflows/deploy.yml
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
name: Deploy to Cloudflare
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
- run: npm install -g wrangler
|
||||
- run: wrangler deploy
|
||||
env:
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
CLOUDFLARE_ACCOUNT_ID: c29d5b5c11b67dc349843b8731e93b8f
|
||||
21
worker.js
21
worker.js
|
|
@ -20,24 +20,27 @@ export default {
|
|||
if (!secrets[competitor] || auth !== `Bearer ${secrets[competitor]}`) {
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
const comps = JSON.parse(await env.MILLY_METRICS.get('competitors') || '{}');
|
||||
if (comps[competitor]) comps[competitor].revenue = parseFloat(revenue) || 0;
|
||||
await env.MILLY_METRICS.put('competitors', JSON.stringify(comps));
|
||||
const revenues = JSON.parse(await env.MILLY_METRICS.get('revenues') || '{}');
|
||||
revenues[competitor] = parseFloat(revenue) || 0;
|
||||
await env.MILLY_METRICS.put('revenues', JSON.stringify(revenues));
|
||||
return new Response('Updated');
|
||||
}
|
||||
|
||||
const [compsRaw, metricsRaw, baselineRaw] = await Promise.all([
|
||||
env.MILLY_METRICS.get('competitors'),
|
||||
const [revenuesRaw, metricsRaw] = await Promise.all([
|
||||
env.MILLY_METRICS.get('revenues'),
|
||||
env.MILLY_METRICS.get('metrics'),
|
||||
env.MILLY_METRICS.get('baseline'),
|
||||
]);
|
||||
|
||||
const competitors = compsRaw ? JSON.parse(compsRaw) : defaultCompetitors();
|
||||
// Static config always comes from code — KV only stores revenue numbers
|
||||
const competitors = defaultCompetitors();
|
||||
const revenues = revenuesRaw ? JSON.parse(revenuesRaw) : {};
|
||||
const metrics = metricsRaw ? JSON.parse(metricsRaw) : {};
|
||||
|
||||
// Omar's revenue = live Stripe (minus baseline)
|
||||
if (competitors.omar) {
|
||||
// Omar's revenue = live Stripe
|
||||
competitors.omar.revenue = metrics.total_revenue || 0;
|
||||
// Others = self-reported via /update API
|
||||
for (const id of ['rhys', 'pussy', 'patty']) {
|
||||
if (revenues[id] != null) competitors[id].revenue = revenues[id];
|
||||
}
|
||||
|
||||
return new Response(render(competitors), {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue