~cytrogen/gstack

ref: 3b22fc39e61add9a3bfb8d2565d27c94acefc678 gstack/supabase/functions/update-check/index.ts -rw-r--r-- 1.1 KiB
3b22fc39 — Garry Tan feat: opt-in usage telemetry + community intelligence platform (v0.8.6) (#210) a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// gstack update-check edge function
// Logs an install ping and returns the current latest version.
// Called by bin/gstack-update-check as a parallel background request.

import { createClient } from "https://esm.sh/@supabase/supabase-js@2";

const CURRENT_VERSION = Deno.env.get("GSTACK_CURRENT_VERSION") || "0.6.4.1";

Deno.serve(async (req) => {
  if (req.method !== "POST") {
    return new Response(CURRENT_VERSION, { status: 200 });
  }

  try {
    const { version, os } = await req.json();

    if (!version || !os) {
      return new Response(CURRENT_VERSION, { status: 200 });
    }

    const supabase = createClient(
      Deno.env.get("SUPABASE_URL") ?? "",
      Deno.env.get("SUPABASE_SERVICE_ROLE_KEY") ?? ""
    );

    // Log the update check (fire-and-forget)
    await supabase.from("update_checks").insert({
      gstack_version: String(version).slice(0, 20),
      os: String(os).slice(0, 20),
    });

    return new Response(CURRENT_VERSION, { status: 200 });
  } catch {
    // Always return the version, even if logging fails
    return new Response(CURRENT_VERSION, { status: 200 });
  }
});