mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 13:02:59 +00:00
The baseUrl variable was declared inside an IIFE that skips re-execution on HTMX reloads, so it became undefined when the fonts tab was reloaded. Since baseUrl was just window.location.origin prepended to absolute paths like /api/v3/fonts/upload, it was unnecessary — fetch() with a leading slash already resolves against the current origin. Remove baseUrl entirely and use relative URLs in all 7 fetch calls. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -215,9 +215,6 @@
|
|||||||
var fontOverrides = window.fontOverrides;
|
var fontOverrides = window.fontOverrides;
|
||||||
var selectedFontFiles = window.selectedFontFiles;
|
var selectedFontFiles = window.selectedFontFiles;
|
||||||
|
|
||||||
// Base URL for API calls (shared scope)
|
|
||||||
var baseUrl = window.location.origin;
|
|
||||||
|
|
||||||
// Retry counter for initialization
|
// Retry counter for initialization
|
||||||
var initRetryCount = 0;
|
var initRetryCount = 0;
|
||||||
var MAX_INIT_RETRIES = 50; // 5 seconds max (50 * 100ms)
|
var MAX_INIT_RETRIES = 50; // 5 seconds max (50 * 100ms)
|
||||||
@@ -384,9 +381,9 @@ async function loadFontData() {
|
|||||||
try {
|
try {
|
||||||
// Use absolute URLs to ensure they work when loaded via HTMX
|
// Use absolute URLs to ensure they work when loaded via HTMX
|
||||||
const [catalogRes, tokensRes, overridesRes] = await Promise.all([
|
const [catalogRes, tokensRes, overridesRes] = await Promise.all([
|
||||||
fetch(`${baseUrl}/api/v3/fonts/catalog`),
|
fetch(`/api/v3/fonts/catalog`),
|
||||||
fetch(`${baseUrl}/api/v3/fonts/tokens`),
|
fetch(`/api/v3/fonts/tokens`),
|
||||||
fetch(`${baseUrl}/api/v3/fonts/overrides`)
|
fetch(`/api/v3/fonts/overrides`)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Check if all responses are successful
|
// Check if all responses are successful
|
||||||
@@ -558,7 +555,7 @@ async function deleteFont(fontFamily) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${baseUrl}/api/v3/fonts/${encodeURIComponent(fontFamily)}`, {
|
const response = await fetch(`/api/v3/fonts/${encodeURIComponent(fontFamily)}`, {
|
||||||
method: 'DELETE'
|
method: 'DELETE'
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -667,7 +664,7 @@ async function addFontOverride() {
|
|||||||
if (sizePx) overrideData.size_px = sizePx;
|
if (sizePx) overrideData.size_px = sizePx;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(`${baseUrl}/api/v3/fonts/overrides`, {
|
const response = await fetch(`/api/v3/fonts/overrides`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@@ -712,7 +709,7 @@ async function deleteFontOverride(elementKey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${baseUrl}/api/v3/fonts/overrides/${elementKey}`, {
|
const response = await fetch(`/api/v3/fonts/overrides/${elementKey}`, {
|
||||||
method: 'DELETE'
|
method: 'DELETE'
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -860,7 +857,7 @@ async function updateFontPreview() {
|
|||||||
fg: 'ffffff'
|
fg: 'ffffff'
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await fetch(`${baseUrl}/api/v3/fonts/preview?${params}`);
|
const response = await fetch(`/api/v3/fonts/preview?${params}`);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const text = await response.text();
|
const text = await response.text();
|
||||||
@@ -990,7 +987,7 @@ async function uploadSelectedFonts() {
|
|||||||
formData.append('font_file', file);
|
formData.append('font_file', file);
|
||||||
formData.append('font_family', i === 0 ? fontFamily : `${fontFamily}_${i + 1}`);
|
formData.append('font_family', i === 0 ? fontFamily : `${fontFamily}_${i + 1}`);
|
||||||
|
|
||||||
const response = await fetch(`${baseUrl}/api/v3/fonts/upload`, {
|
const response = await fetch(`/api/v3/fonts/upload`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData
|
body: formData
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user