File size: 5,299 Bytes
6711fd5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | -- =====================================================
-- إنشاء Storage Buckets في Supabase لرفع ملفات الإضافات
-- قم بتشغيل هذا SQL في Supabase Dashboard > SQL Editor
-- =====================================================
-- 1. إنشاء Bucket للإضافات (mods)
INSERT INTO storage.buckets (id, name, public, file_size_limit, allowed_mime_types)
VALUES (
'mods',
'mods',
true,
104857600, -- 100 MB
ARRAY[
'application/zip',
'application/java-archive',
'application/octet-stream',
'application/x-zip-compressed'
]
)
ON CONFLICT (id) DO UPDATE SET
public = true,
file_size_limit = 104857600;
-- 2. إنشاء Bucket للصور المصغرة (thumbnails)
INSERT INTO storage.buckets (id, name, public, file_size_limit, allowed_mime_types)
VALUES (
'thumbnails',
'thumbnails',
true,
5242880, -- 5 MB
ARRAY[
'image/jpeg',
'image/png',
'image/webp',
'image/gif'
]
)
ON CONFLICT (id) DO UPDATE SET
public = true,
file_size_limit = 5242880;
-- 3. إنشاء Bucket للقطات الشاشة (screenshots)
INSERT INTO storage.buckets (id, name, public, file_size_limit, allowed_mime_types)
VALUES (
'screenshots',
'screenshots',
true,
10485760, -- 10 MB
ARRAY[
'image/jpeg',
'image/png',
'image/webp'
]
)
ON CONFLICT (id) DO UPDATE SET
public = true,
file_size_limit = 10485760;
-- =====================================================
-- إعداد سياسات RLS للـ Storage Buckets
-- =====================================================
-- سياسات Bucket: mods
DROP POLICY IF EXISTS "Public can read mods" ON storage.objects;
CREATE POLICY "Public can read mods"
ON storage.objects FOR SELECT
USING (bucket_id = 'mods');
DROP POLICY IF EXISTS "Authenticated users can upload mods" ON storage.objects;
CREATE POLICY "Authenticated users can upload mods"
ON storage.objects FOR INSERT
WITH CHECK (bucket_id = 'mods' AND auth.role() = 'authenticated');
DROP POLICY IF EXISTS "Users can delete own mods" ON storage.objects;
CREATE POLICY "Users can delete own mods"
ON storage.objects FOR DELETE
USING (bucket_id = 'mods' AND auth.uid()::text = (storage.foldername(name))[1]);
-- سياسات Bucket: thumbnails
DROP POLICY IF EXISTS "Public can read thumbnails" ON storage.objects;
CREATE POLICY "Public can read thumbnails"
ON storage.objects FOR SELECT
USING (bucket_id = 'thumbnails');
DROP POLICY IF EXISTS "Authenticated users can upload thumbnails" ON storage.objects;
CREATE POLICY "Authenticated users can upload thumbnails"
ON storage.objects FOR INSERT
WITH CHECK (bucket_id = 'thumbnails' AND auth.role() = 'authenticated');
-- سياسات Bucket: screenshots
DROP POLICY IF EXISTS "Public can read screenshots" ON storage.objects;
CREATE POLICY "Public can read screenshots"
ON storage.objects FOR SELECT
USING (bucket_id = 'screenshots');
DROP POLICY IF EXISTS "Authenticated users can upload screenshots" ON storage.objects;
CREATE POLICY "Authenticated users can upload screenshots"
ON storage.objects FOR INSERT
WITH CHECK (bucket_id = 'screenshots' AND auth.role() = 'authenticated');
-- =====================================================
-- التأكد من أن جدول mods يستخدم user_id (وليس developer_id)
-- =====================================================
ALTER TABLE IF EXISTS public.mods
ADD COLUMN IF NOT EXISTS user_id UUID REFERENCES auth.users(id) ON DELETE SET NULL;
-- إصلاح سياسات RLS لجدول mods (تستخدم user_id)
ALTER TABLE public.mods ENABLE ROW LEVEL SECURITY;
DROP POLICY IF EXISTS "Mods are viewable by everyone" ON public.mods;
CREATE POLICY "Mods are viewable by everyone"
ON public.mods FOR SELECT USING (true);
DROP POLICY IF EXISTS "Users can insert their own mods" ON public.mods;
CREATE POLICY "Users can insert their own mods"
ON public.mods FOR INSERT
WITH CHECK (auth.uid()::text = user_id::text);
DROP POLICY IF EXISTS "Users can update their own mods" ON public.mods;
CREATE POLICY "Users can update their own mods"
ON public.mods FOR UPDATE
USING (auth.uid()::text = user_id::text);
DROP POLICY IF EXISTS "Users can delete their own mods" ON public.mods;
CREATE POLICY "Users can delete their own mods"
ON public.mods FOR DELETE
USING (auth.uid()::text = user_id::text);
-- =====================================================
-- جدول سجل التحميلات (إذا لم يكن موجوداً)
-- =====================================================
CREATE TABLE IF NOT EXISTS public.download_history (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
mod_id UUID REFERENCES public.mods(id) ON DELETE CASCADE,
user_id UUID REFERENCES auth.users(id) ON DELETE SET NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
ALTER TABLE public.download_history ENABLE ROW LEVEL SECURITY;
DROP POLICY IF EXISTS "Anyone can insert download history" ON public.download_history;
CREATE POLICY "Anyone can insert download history"
ON public.download_history FOR INSERT WITH CHECK (true);
DROP POLICY IF EXISTS "Users can view own download history" ON public.download_history;
CREATE POLICY "Users can view own download history"
ON public.download_history FOR SELECT
USING (auth.uid() = user_id OR auth.role() = 'service_role');
|