refactor: Update .gitignore and package.json, and add database functionality
This commit is contained in:
@@ -8,6 +8,7 @@ import { Form, FormField, FormItem, FormLabel } from "./ui/form";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { z } from 'zod';
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { addDownload } from "@/lib/db";
|
||||
|
||||
const BASE_URL = "https://github.com/zen-browser/desktop/releases/download/latest";
|
||||
|
||||
@@ -49,6 +50,7 @@ export default function DownloadPage() {
|
||||
|
||||
const onSubmit = async (data: any) => {
|
||||
const platform = data.platform;
|
||||
addDownload(platform);
|
||||
console.log("Data: ", data)
|
||||
console.log("Platform: ", platform)
|
||||
console.log("Releases: ", releases)
|
||||
@@ -56,7 +58,6 @@ export default function DownloadPage() {
|
||||
console.log("Releases for platform: ", releasesForPlatform)
|
||||
const url = `${BASE_URL}/${releasesForPlatform}`;
|
||||
console.log("URL: ", url)
|
||||
window.location.href = url;
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
31
src/lib/db.ts
Normal file
31
src/lib/db.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { sql } from '@vercel/postgres';
|
||||
import { config } from 'dotenv';
|
||||
|
||||
var hasLoadedEnv = false;
|
||||
function loadEnv() {
|
||||
if (hasLoadedEnv) {
|
||||
return;
|
||||
}
|
||||
config();
|
||||
}
|
||||
|
||||
async function createDownloadsTable() {
|
||||
loadEnv();
|
||||
await sql`
|
||||
CREATE TABLE IF NOT EXISTS downloads (
|
||||
id SERIAL PRIMARY KEY,
|
||||
platform TEXT NOT NULL,
|
||||
count INT NOT NULL
|
||||
);
|
||||
`;
|
||||
}
|
||||
|
||||
export async function addDownload(platform: string) {
|
||||
await createDownloadsTable();
|
||||
await sql`
|
||||
INSERT INTO downloads (platform, count)
|
||||
VALUES (${platform}, 1)
|
||||
ON CONFLICT (platform)
|
||||
DO UPDATE SET count = downloads.count + 1;
|
||||
`;
|
||||
}
|
||||
Reference in New Issue
Block a user