Merge pull request #51 from BharathxD/refactor/download-page
refactor: Improved platform detection, UI enhancements, and overall code quality
This commit is contained in:
@@ -1,31 +1,49 @@
|
||||
"use server";
|
||||
|
||||
import { createClient } from '@supabase/supabase-js'
|
||||
import { createClient } from "@supabase/supabase-js";
|
||||
import { releases } from "./releases";
|
||||
|
||||
const supabaseUrl = 'https://dmthyedfjzcysoekmyns.supabase.co'
|
||||
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) {
|
||||
// Check if the download count for the platform exists
|
||||
const DOWNLOADS_TABLE = "downloads";
|
||||
const PLATFORM_COLUMN = "platform";
|
||||
const COUNT_COLUMN = "count";
|
||||
|
||||
export async function incrementDownloadCount(platform: keyof typeof releases) {
|
||||
try {
|
||||
//? 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)
|
||||
}
|
||||
.from(DOWNLOADS_TABLE)
|
||||
.select(COUNT_COLUMN)
|
||||
.eq(PLATFORM_COLUMN, platform);
|
||||
|
||||
if (error) throw new Error("Error fetching download count");
|
||||
|
||||
if (!data || data.length === 0) {
|
||||
//? If it doesn't exist, create it
|
||||
const { data: insertData, error: insertError } = await supabase
|
||||
.from(DOWNLOADS_TABLE)
|
||||
.insert([{ platform, count: 1 }]);
|
||||
|
||||
if (insertError) throw new Error("Error inserting download count");
|
||||
|
||||
return insertData;
|
||||
} else {
|
||||
// If it exists, increment the count
|
||||
await supabase
|
||||
.from('downloads')
|
||||
.update({ count: data![0].count + 1 })
|
||||
.eq('platform', platform)
|
||||
//? If it exists, increment the count
|
||||
const newCount = data![0][COUNT_COLUMN] + 1;
|
||||
const { data: updateData, error: updateError } = await supabase
|
||||
.from(DOWNLOADS_TABLE)
|
||||
.update({ count: newCount })
|
||||
.eq(PLATFORM_COLUMN, platform);
|
||||
|
||||
if (updateError) throw new Error("Error updating download count");
|
||||
|
||||
return updateData;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Unexpected error in addDownload:", err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +1,54 @@
|
||||
export const releases: any = {
|
||||
WindowsInstaller: "zen.installer.exe",
|
||||
WindowsInstallerGeneric: "zen.installer-generic.exe",
|
||||
|
||||
WindowsZip: "zen.win-specific.zip",
|
||||
WindowsZipGeneric: "zen.win-generic.zip",
|
||||
export const releases = {
|
||||
WindowsInstaller: "zen.installer.exe",
|
||||
WindowsInstallerGeneric: "zen.installer-generic.exe",
|
||||
|
||||
MacOS: "zen.macos-aarch64.dmg",
|
||||
MacOSIntel: "zen.macos-x64.dmg",
|
||||
WindowsZip: "zen.win-specific.zip",
|
||||
WindowsZipGeneric: "zen.win-generic.zip",
|
||||
|
||||
Linux: "zen.linux-specific.tar.bz2",
|
||||
LinuxGeneric: "zen.linux-generic.tar.bz2",
|
||||
MacOS: "zen.macos-aarch64.dmg",
|
||||
MacOSIntel: "zen.macos-x64.dmg",
|
||||
|
||||
LinuxAppImage: "zen-specific.AppImage",
|
||||
LinuxAppImageGeneric: "zen-generic.AppImage",
|
||||
};
|
||||
Linux: "zen.linux-specific.tar.bz2",
|
||||
LinuxGeneric: "zen.linux-generic.tar.bz2",
|
||||
|
||||
LinuxAppImage: "zen-specific.AppImage",
|
||||
LinuxAppImageGeneric: "zen-generic.AppImage",
|
||||
} as const;
|
||||
|
||||
// platform
|
||||
// -> arch
|
||||
// -> file
|
||||
export const releaseTree: any = {
|
||||
windows: {
|
||||
specific: {
|
||||
installer: "WindowsInstaller",
|
||||
portable: "WindowsZip",
|
||||
},
|
||||
generic: {
|
||||
installer: "WindowsInstallerGeneric",
|
||||
portable: "WindowsZipGeneric",
|
||||
},
|
||||
windows: {
|
||||
specific: {
|
||||
installer: "WindowsInstaller",
|
||||
portable: "WindowsZip",
|
||||
},
|
||||
macos: {
|
||||
generic: "MacOSIntel",
|
||||
specific: "MacOS",
|
||||
generic: {
|
||||
installer: "WindowsInstallerGeneric",
|
||||
portable: "WindowsZipGeneric",
|
||||
},
|
||||
linux: {
|
||||
specific: {
|
||||
portable: "Linux",
|
||||
appimage: "LinuxAppImage",
|
||||
},
|
||||
generic: {
|
||||
portable: "LinuxGeneric",
|
||||
appimage: "LinuxAppImageGeneric",
|
||||
},
|
||||
},
|
||||
macos: {
|
||||
generic: "MacOSIntel",
|
||||
specific: "MacOS",
|
||||
},
|
||||
linux: {
|
||||
specific: {
|
||||
portable: "Linux",
|
||||
appimage: "LinuxAppImage",
|
||||
},
|
||||
generic: {
|
||||
portable: "LinuxGeneric",
|
||||
appimage: "LinuxAppImageGeneric",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
type Platform = "Windows" | "MacOS" | "Linux";
|
||||
type Architecture = "specific" | "generic";
|
||||
|
||||
type WindowsDownloadType = "installer" | "portable";
|
||||
type LinuxDownloadType = "portable" | "appimage" | "flatpak";
|
||||
|
||||
export type { Platform, Architecture, WindowsDownloadType, LinuxDownloadType };
|
||||
|
||||
Reference in New Issue
Block a user