chore: zalozenie databazy a uloziska na novom serveri
- supabase/schema.sql: idempotentny skript (tabulky, RLS, bucket newsletter-assets) - supabase/assets + npm run db:upload-assets: staticke obrazky sablony - adresa uloziska sa sklada z NEXT_PUBLIC_SUPABASE_URL namiesto pevneho projektu - .env.example a navod na instalaciu v README Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eb92d30dc3
commit
5d1900740c
37 files changed
+178
-96
No files matched your search
@@ -0,0 +1,45 @@
|
||||
// Nahrá statické obrázky aplikácie (supabase/assets/) do Supabase Storage bucketu newsletter-assets.
|
||||
// Spustenie: npm run db:upload-assets (číta NEXT_PUBLIC_SUPABASE_URL a SUPABASE_SERVICE_ROLE_KEY z .env.local)
|
||||
// Existujúce súbory s rovnakým názvom sa prepíšu.
|
||||
import { createClient } from '@supabase/supabase-js';
|
||||
import { readdir, readFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
|
||||
const BUCKET = 'newsletter-assets';
|
||||
const ASSETS_DIR = path.join(process.cwd(), 'supabase', 'assets');
|
||||
const CONTENT_TYPES = {
|
||||
'.png': 'image/png',
|
||||
'.jpg': 'image/jpeg',
|
||||
'.jpeg': 'image/jpeg',
|
||||
'.gif': 'image/gif',
|
||||
'.svg': 'image/svg+xml',
|
||||
'.webp': 'image/webp'
|
||||
};
|
||||
|
||||
const url = process.env.NEXT_PUBLIC_SUPABASE_URL;
|
||||
const serviceKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
|
||||
if (!url || !serviceKey) {
|
||||
console.error('Chýba NEXT_PUBLIC_SUPABASE_URL alebo SUPABASE_SERVICE_ROLE_KEY v .env.local');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const supabase = createClient(url, serviceKey);
|
||||
const files = (await readdir(ASSETS_DIR)).filter((f) => CONTENT_TYPES[path.extname(f).toLowerCase()]);
|
||||
|
||||
let failed = 0;
|
||||
for (const file of files) {
|
||||
const body = await readFile(path.join(ASSETS_DIR, file));
|
||||
const { error } = await supabase.storage.from(BUCKET).upload(file, body, {
|
||||
contentType: CONTENT_TYPES[path.extname(file).toLowerCase()],
|
||||
upsert: true
|
||||
});
|
||||
if (error) {
|
||||
failed++;
|
||||
console.error(`✗ ${file}: ${error.message}`);
|
||||
} else {
|
||||
console.log(`✓ ${file}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`\nNahraté ${files.length - failed}/${files.length} súborov do bucketu ${BUCKET}.`);
|
||||
if (failed) process.exit(1);
|
||||
Reference in new issue
Block a user