| import { createClient } from '@supabase/supabase-js'; |
|
|
| const supabaseUrl = process.env.SUPABASE_URL || ''; |
| const supabaseKey = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || ''; |
|
|
| export const supabase = createClient(supabaseUrl, supabaseKey); |
|
|
| export interface WebDrop { |
| id: number; |
| user_id: string; |
| title: string; |
| description: string; |
| status: string; |
| is_external: number; |
| asset_id: string | null; |
| file_url: string | null; |
| image_url: string | null; |
| published_at: string; |
| category: string; |
| } |
|
|
| |
| export async function getAllWebDrops(): Promise<WebDrop[]> { |
| try { |
| const { data, error } = await supabase |
| .from('web_drops') |
| .select('*') |
| .order('published_at', { ascending: false }) |
| .limit(50); |
|
|
| if (error) throw error; |
| return (data || []) as WebDrop[]; |
| } catch (e) { |
| console.error("Supabase Fetch Error:", e); |
| return []; |
| } |
| } |
|
|
| export async function getWebDropsByCategory(category: string): Promise<WebDrop[]> { |
| try { |
| const { data, error } = await supabase |
| .from('web_drops') |
| .select('*') |
| .eq('category', category) |
| .order('published_at', { ascending: false }) |
| .limit(50); |
|
|
| if (error) throw error; |
| return (data || []) as WebDrop[]; |
| } catch (e) { |
| console.error(`Supabase Category Fetch Error (${category}):`, e); |
| return []; |
| } |
| } |
|
|
| export async function checkVipStatus(discordId: string): Promise<boolean> { |
| try { |
| const { data: user, error } = await supabase |
| .from('vip_users') |
| .select('*') |
| .eq('discord_id', discordId) |
| .single(); |
|
|
| if (error || !user) return false; |
|
|
| |
| if (user.expires_at) { |
| const expiresAt = new Date(user.expires_at).getTime(); |
| if (Date.now() > expiresAt) return false; |
| } |
|
|
| return true; |
| } catch (e) { |
| |
| return false; |
| } |
| } |
|
|
| |
| export function getDb() { |
| return supabase; |
| } |
|
|