Commit ee317285 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: emoji uploads not reflecting — add group_name, kill API cache, add debug logging

Three issues fixed:
1. platform_assets insert was missing group_name (likely NOT NULL column, same
   bug as platform_theme had in 18d0e512)
2. API had Cache-Control: max-age=60 so browser served stale theme data
3. theme.load() silently swallowed errors — added console logging and
   cache-bust param to diagnose failures
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent a032b00e
...@@ -95,12 +95,23 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['asset'])) { ...@@ -95,12 +95,23 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['asset'])) {
$publicUrl = SUPABASE_URL . '/storage/v1/object/public/profile-images/' . $fileName . '?apikey=' . $anonKey . '&v=' . time(); $publicUrl = SUPABASE_URL . '/storage/v1/object/public/profile-images/' . $fileName . '?apikey=' . $anonKey . '&v=' . time();
$theme['assets'][$slot] = $publicUrl; $theme['assets'][$slot] = $publicUrl;
// Save asset URL to Supabase platform_assets table // Save asset URL to Supabase platform_assets table (upsert)
$assetData = [
'id' => $slot,
'category' => 'custom',
'group_name' => 'player_app',
'label' => $slot,
'asset_url' => $publicUrl,
'dimensions' => $expectedW . 'x' . $expectedH
];
$existing = $sdb->get('platform_assets', ['id' => 'eq.' . $slot, 'select' => 'id', 'limit' => 1]); $existing = $sdb->get('platform_assets', ['id' => 'eq.' . $slot, 'select' => 'id', 'limit' => 1]);
if (!empty($existing) && !isset($existing['error'])) { if (!empty($existing) && !isset($existing['error'])) {
$sdb->update('platform_assets', ['asset_url' => $publicUrl, 'dimensions' => $expectedW . 'x' . $expectedH], ['id' => 'eq.' . $slot]); $result = $sdb->update('platform_assets', ['asset_url' => $publicUrl, 'dimensions' => $expectedW . 'x' . $expectedH], ['id' => 'eq.' . $slot]);
} else { } else {
$sdb->insert('platform_assets', ['id' => $slot, 'category' => 'custom', 'label' => $slot, 'asset_url' => $publicUrl, 'dimensions' => $expectedW . 'x' . $expectedH]); $result = $sdb->insert('platform_assets', $assetData);
}
if (isset($result['error'])) {
error_log('[branding] platform_assets save failed: ' . json_encode($result));
} }
// Also save locally for immediate preview // Also save locally for immediate preview
......
...@@ -4,7 +4,7 @@ header('Content-Type: application/json'); ...@@ -4,7 +4,7 @@ header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS'); header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization'); header('Access-Control-Allow-Headers: Content-Type, Authorization');
header('Cache-Control: public, max-age=60'); header('Cache-Control: no-cache, must-revalidate');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(200); exit; } if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(200); exit; }
......
...@@ -5,12 +5,13 @@ let themeData = null; ...@@ -5,12 +5,13 @@ let themeData = null;
export async function load() { export async function load() {
try { try {
const res = await fetch(THEME_API); const res = await fetch(THEME_API + '?_t=' + Date.now());
if (!res.ok) return; if (!res.ok) { console.warn('[theme] API responded', res.status); return; }
themeData = await res.json(); themeData = await res.json();
applyColors(); applyColors();
applyAnimations(); applyAnimations();
} catch (e) {} if (themeData?.assets) console.log('[theme] loaded', Object.keys(themeData.assets).length, 'assets');
} catch (e) { console.warn('[theme] load failed', e); }
} }
export function getAsset(slot, fallback) { export function getAsset(slot, fallback) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment