diff --git a/package.json b/package.json index ce846ce..d7ddff0 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "@radix-ui/react-select": "^2.1.1", "@radix-ui/react-slot": "^1.1.0", "@radix-ui/react-tabs": "^1.1.0", + "@supabase/supabase-js": "^2.45.1", "@vercel/postgres": "^0.9.0", "canvas-confetti": "^1.9.3", "class-variance-authority": "^0.7.0", diff --git a/src/components/download.tsx b/src/components/download.tsx index bc6018c..cf6863a 100644 --- a/src/components/download.tsx +++ b/src/components/download.tsx @@ -155,7 +155,7 @@ export default function DownloadPage() { console.log("Downloading: "); console.log("platform: ", selectedPlatform); console.log("compat: ", arch); - window.location.replace(`${BASE_URL}/${releases[releaseTarget]}`); + //window.location.replace(`${BASE_URL}/${releases[releaseTarget]}`); } setHasDownloaded(true); addDownload(releaseTarget); diff --git a/src/lib/db.ts b/src/lib/db.ts index 284cb60..5551339 100644 --- a/src/lib/db.ts +++ b/src/lib/db.ts @@ -1,32 +1,31 @@ "use server"; -import { sql } from '@vercel/postgres'; -import { releases } from './releases'; +import { createClient } from '@supabase/supabase-js' -async function createDownloadsTable() { - await sql` - CREATE TABLE IF NOT EXISTS downloads ( - platform TEXT NOT NULL PRIMARY KEY, - count INT NOT NULL DEFAULT 0 - ); - `; -} +const supabaseUrl = 'https://dmthyedfjzcysoekmyns.supabase.co' +const supabaseKey = process.env.SUPABASE_KEY as string; +const supabase = createClient(supabaseUrl, supabaseKey); export async function addDownload(platform: string) { - await createDownloadsTable(); - let hasPlatform: any = await sql` - SELECT COUNT(*) FROM downloads WHERE platform = ${platform}; - `; - if (hasPlatform.rows[0].count > 0) { - await sql` - UPDATE downloads - SET count = count + 1 - WHERE platform = ${platform}; - `; - return; + // Check if the download count for the platform exists + const { data, error } = await supabase + .from('downloads') + .select('count') + .eq('platform', platform) + // If it doesn't exist, create it + console.log(data) + if (data?.length === 0 || data === null) { + const {data, error} = await supabase + .from('downloads') + .insert([{ platform, count: 1 }]); + if (error) { + console.error(error) + } + } else { + // If it exists, increment the count + await supabase + .from('downloads') + .update({ count: data![0].count + 1 }) + .eq('platform', platform) } - await sql` - INSERT INTO downloads (platform, count) - VALUES (${platform}, 1); - `; }