fixes to admin using client fetch
CI / test (push) Successful in 7s

This commit is contained in:
2026-01-29 21:52:12 -05:00
parent a13687635b
commit 45270f9b18
22 changed files with 828 additions and 52 deletions
+13 -16
View File
@@ -14,9 +14,6 @@ export type CreatePlatformDto = {
export type UpdatePlatformDto = Partial<CreatePlatformDto>;
const API_BASE =
process.env.NEXT_PUBLIC_API_BASE_URL ?? "";
function normalizePlatform(raw: any): Platform {
const id = Number(raw?.id);
const key = String(raw?.key ?? "").trim();
@@ -33,9 +30,9 @@ function normalizePlatform(raw: any): Platform {
return { id, key, label, isActive };
}
export async function fetchPlatforms(tokenHeaders: HeadersInit): Promise<Platform[]> {
const res = await fetch(`${API_BASE}/api/platforms`, {
headers: { ...tokenHeaders },
export async function fetchPlatforms(_tokenHeaders: HeadersInit): Promise<Platform[]> {
const res = await fetch('/api/admin/platforms', {
credentials: 'include',
});
if (!res.ok) {
@@ -48,15 +45,15 @@ export async function fetchPlatforms(tokenHeaders: HeadersInit): Promise<Platfor
}
export async function createPlatform(
tokenHeaders: HeadersInit,
_tokenHeaders: HeadersInit,
dto: CreatePlatformDto
): Promise<Platform> {
const res = await fetch(`${API_BASE}/api/platforms`, {
const res = await fetch('/api/admin/platforms', {
method: "POST",
headers: {
"Content-Type": "application/json",
...tokenHeaders,
},
credentials: 'include',
body: JSON.stringify(dto),
});
@@ -69,17 +66,17 @@ export async function createPlatform(
}
export async function updatePlatform(
tokenHeaders: HeadersInit,
_tokenHeaders: HeadersInit,
id: number,
dto: UpdatePlatformDto
): Promise<Platform> {
const res = await fetch(`${API_BASE}/api/platforms/${id}`, {
const res = await fetch(`/api/admin/platforms/${id}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
...tokenHeaders,
},
body: JSON.stringify({ isActive: dto.isActive }),
credentials: 'include',
body: JSON.stringify(dto),
});
if (!res.ok) {
@@ -90,10 +87,10 @@ export async function updatePlatform(
return normalizePlatform(await res.json());
}
export async function deletePlatform(tokenHeaders: HeadersInit, id: number): Promise<void> {
const res = await fetch(`${API_BASE}/api/platforms/${id}`, {
export async function deletePlatform(_tokenHeaders: HeadersInit, id: number): Promise<void> {
const res = await fetch(`/api/admin/platforms/${id}`, {
method: "DELETE",
headers: { ...tokenHeaders },
credentials: 'include',
});
if (!res.ok) {
+43
View File
@@ -0,0 +1,43 @@
/**
* Fix mixed content warnings by upgrading HTTP image URLs to HTTPS
* This handles image URLs stored in the database as http:// which cause
* browser warnings when loaded from HTTPS pages.
*/
export function fixImageUrl(url: string | null | undefined): string | null | undefined {
if (!url || typeof url !== 'string') return url;
return url.replace(/^http:\/\//i, 'https://');
}
/**
* Recursively fix all image URL fields in an object
* Common fields: imageUrl, mainImageUrl, coverImageUrl, thumbnailUrl, etc.
*/
export function fixImageUrls(data: any): any {
if (!data) return data;
if (Array.isArray(data)) {
return data.map(item => fixImageUrls(item));
}
if (typeof data === 'object') {
const fixed: any = {};
for (const [key, value] of Object.entries(data)) {
// Fix any field that looks like an image URL
if (
(key.toLowerCase().includes('image') ||
key.toLowerCase().includes('photo') ||
key.toLowerCase().includes('picture')) &&
typeof value === 'string'
) {
fixed[key] = fixImageUrl(value);
} else if (typeof value === 'object') {
fixed[key] = fixImageUrls(value);
} else {
fixed[key] = value;
}
}
return fixed;
}
return data;
}