refactor: Update next.config.mjs to allow specific origins for server actions and update download.tsx to open download link in a new tab

This commit is contained in:
mauro 🤙
2024-07-04 10:54:11 +00:00
parent a1149838e6
commit 26dd892f21
4 changed files with 35 additions and 27 deletions

View File

@@ -1,31 +1,32 @@
"use server";
import { sql } from '@vercel/postgres';
import { config } from 'dotenv';
var hasLoadedEnv = false;
function loadEnv() {
if (hasLoadedEnv) {
return;
}
config();
}
import { releases } from './releases';
async function createDownloadsTable() {
loadEnv();
await sql`
CREATE TABLE IF NOT EXISTS downloads (
id SERIAL PRIMARY KEY,
platform TEXT NOT NULL,
count INT NOT NULL
platform TEXT NOT NULL PRIMARY KEY CONSTRAINT platform_check CHECK (platform IN ('WindowsZip', 'Linux')),
count INT NOT NULL DEFAULT 0
);
`;
}
}
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;
}
await sql`
INSERT INTO downloads (platform, count)
VALUES (${platform}, 1)
ON CONFLICT (platform)
DO UPDATE SET count = downloads.count + 1;
VALUES (${platform}, 1);
`;
}