website refactor
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { proxyMediaRequest, getMediaContentType, getMediaCacheControl } from '@/lib/adapters/MediaProxyAdapter';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
@@ -6,32 +7,16 @@ export async function GET(
|
||||
) {
|
||||
const { driverId } = params;
|
||||
|
||||
// In test environment, proxy to the mock API
|
||||
const apiBaseUrl = process.env.API_BASE_URL || 'http://localhost:3000';
|
||||
const result = await proxyMediaRequest(`/media/avatar/${driverId}`);
|
||||
|
||||
try {
|
||||
const response = await fetch(`${apiBaseUrl}/media/avatar/${driverId}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'image/png',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
// Return a fallback image or 404
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
|
||||
const buffer = await response.arrayBuffer();
|
||||
|
||||
return new NextResponse(buffer, {
|
||||
headers: {
|
||||
'Content-Type': 'image/png',
|
||||
'Cache-Control': 'public, max-age=3600',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching avatar:', error);
|
||||
return new NextResponse(null, { status: 500 });
|
||||
if (result.isErr()) {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
|
||||
return new NextResponse(result.unwrap(), {
|
||||
headers: {
|
||||
'Content-Type': getMediaContentType('/media/avatar'),
|
||||
'Cache-Control': getMediaCacheControl(),
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { proxyMediaRequest, getMediaContentType, getMediaCacheControl } from '@/lib/adapters/MediaProxyAdapter';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
@@ -6,27 +7,16 @@ export async function GET(
|
||||
) {
|
||||
const { categoryId } = params;
|
||||
|
||||
const apiBaseUrl = process.env.API_BASE_URL || 'http://localhost:3000';
|
||||
const result = await proxyMediaRequest(`/media/categories/${categoryId}/icon`);
|
||||
|
||||
try {
|
||||
const response = await fetch(`${apiBaseUrl}/media/categories/${categoryId}/icon`, {
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
|
||||
const buffer = await response.arrayBuffer();
|
||||
|
||||
return new NextResponse(buffer, {
|
||||
headers: {
|
||||
'Content-Type': 'image/png',
|
||||
'Cache-Control': 'public, max-age=3600',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching category icon:', error);
|
||||
return new NextResponse(null, { status: 500 });
|
||||
if (result.isErr()) {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
|
||||
return new NextResponse(result.unwrap(), {
|
||||
headers: {
|
||||
'Content-Type': getMediaContentType('/media/categories'),
|
||||
'Cache-Control': getMediaCacheControl(),
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { proxyMediaRequest, getMediaContentType, getMediaCacheControl } from '@/lib/adapters/MediaProxyAdapter';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
@@ -6,27 +7,16 @@ export async function GET(
|
||||
) {
|
||||
const { leagueId } = params;
|
||||
|
||||
const apiBaseUrl = process.env.API_BASE_URL || 'http://localhost:3000';
|
||||
const result = await proxyMediaRequest(`/media/leagues/${leagueId}/cover`);
|
||||
|
||||
try {
|
||||
const response = await fetch(`${apiBaseUrl}/media/leagues/${leagueId}/cover`, {
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
|
||||
const buffer = await response.arrayBuffer();
|
||||
|
||||
return new NextResponse(buffer, {
|
||||
headers: {
|
||||
'Content-Type': 'image/png',
|
||||
'Cache-Control': 'public, max-age=3600',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching league cover:', error);
|
||||
return new NextResponse(null, { status: 500 });
|
||||
if (result.isErr()) {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
|
||||
return new NextResponse(result.unwrap(), {
|
||||
headers: {
|
||||
'Content-Type': getMediaContentType('/media/leagues'),
|
||||
'Cache-Control': getMediaCacheControl(),
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { proxyMediaRequest, getMediaContentType, getMediaCacheControl } from '@/lib/adapters/MediaProxyAdapter';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
@@ -6,27 +7,16 @@ export async function GET(
|
||||
) {
|
||||
const { leagueId } = params;
|
||||
|
||||
const apiBaseUrl = process.env.API_BASE_URL || 'http://localhost:3000';
|
||||
const result = await proxyMediaRequest(`/media/leagues/${leagueId}/logo`);
|
||||
|
||||
try {
|
||||
const response = await fetch(`${apiBaseUrl}/media/leagues/${leagueId}/logo`, {
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
|
||||
const buffer = await response.arrayBuffer();
|
||||
|
||||
return new NextResponse(buffer, {
|
||||
headers: {
|
||||
'Content-Type': 'image/png',
|
||||
'Cache-Control': 'public, max-age=3600',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching league logo:', error);
|
||||
return new NextResponse(null, { status: 500 });
|
||||
if (result.isErr()) {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
|
||||
return new NextResponse(result.unwrap(), {
|
||||
headers: {
|
||||
'Content-Type': getMediaContentType('/media/leagues'),
|
||||
'Cache-Control': getMediaCacheControl(),
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { proxyMediaRequest, getMediaContentType, getMediaCacheControl } from '@/lib/adapters/MediaProxyAdapter';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
@@ -6,27 +7,16 @@ export async function GET(
|
||||
) {
|
||||
const { sponsorId } = params;
|
||||
|
||||
const apiBaseUrl = process.env.API_BASE_URL || 'http://localhost:3000';
|
||||
const result = await proxyMediaRequest(`/media/sponsors/${sponsorId}/logo`);
|
||||
|
||||
try {
|
||||
const response = await fetch(`${apiBaseUrl}/media/sponsors/${sponsorId}/logo`, {
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
|
||||
const buffer = await response.arrayBuffer();
|
||||
|
||||
return new NextResponse(buffer, {
|
||||
headers: {
|
||||
'Content-Type': 'image/png',
|
||||
'Cache-Control': 'public, max-age=3600',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching sponsor logo:', error);
|
||||
return new NextResponse(null, { status: 500 });
|
||||
if (result.isErr()) {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
|
||||
return new NextResponse(result.unwrap(), {
|
||||
headers: {
|
||||
'Content-Type': getMediaContentType('/media/sponsors'),
|
||||
'Cache-Control': getMediaCacheControl(),
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { proxyMediaRequest, getMediaContentType, getMediaCacheControl } from '@/lib/adapters/MediaProxyAdapter';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
@@ -6,33 +7,16 @@ export async function GET(
|
||||
) {
|
||||
const { teamId } = params;
|
||||
|
||||
// In test environment, proxy to the mock API
|
||||
// In production, this would fetch from the actual API
|
||||
const apiBaseUrl = process.env.API_BASE_URL || 'http://localhost:3000';
|
||||
const result = await proxyMediaRequest(`/media/teams/${teamId}/logo`);
|
||||
|
||||
try {
|
||||
const response = await fetch(`${apiBaseUrl}/media/teams/${teamId}/logo`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'image/png',
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
// Return a fallback image or 404
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
|
||||
const buffer = await response.arrayBuffer();
|
||||
|
||||
return new NextResponse(buffer, {
|
||||
headers: {
|
||||
'Content-Type': 'image/png',
|
||||
'Cache-Control': 'public, max-age=3600',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching team logo:', error);
|
||||
return new NextResponse(null, { status: 500 });
|
||||
if (result.isErr()) {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
|
||||
return new NextResponse(result.unwrap(), {
|
||||
headers: {
|
||||
'Content-Type': getMediaContentType('/media/teams'),
|
||||
'Cache-Control': getMediaCacheControl(),
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { proxyMediaRequest, getMediaContentType, getMediaCacheControl } from '@/lib/adapters/MediaProxyAdapter';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
@@ -6,27 +7,16 @@ export async function GET(
|
||||
) {
|
||||
const { trackId } = params;
|
||||
|
||||
const apiBaseUrl = process.env.API_BASE_URL || 'http://localhost:3000';
|
||||
const result = await proxyMediaRequest(`/media/tracks/${trackId}/image`);
|
||||
|
||||
try {
|
||||
const response = await fetch(`${apiBaseUrl}/media/tracks/${trackId}/image`, {
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
|
||||
const buffer = await response.arrayBuffer();
|
||||
|
||||
return new NextResponse(buffer, {
|
||||
headers: {
|
||||
'Content-Type': 'image/png',
|
||||
'Cache-Control': 'public, max-age=3600',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching track image:', error);
|
||||
return new NextResponse(null, { status: 500 });
|
||||
if (result.isErr()) {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
|
||||
return new NextResponse(result.unwrap(), {
|
||||
headers: {
|
||||
'Content-Type': getMediaContentType('/media/tracks'),
|
||||
'Cache-Control': getMediaCacheControl(),
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user