fix: resolve Supabase storage pdf URLs on client and server
Some checks failed
Staging Build / build (push) Has been cancelled
Some checks failed
Staging Build / build (push) Has been cancelled
This commit is contained in:
@@ -6,6 +6,7 @@ import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent } from '@/components/ui/card'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import type { Order } from '@/lib/types'
|
||||
import { resolveSupabaseUrl } from '@/lib/utils'
|
||||
|
||||
const statusLabel: Record<string, string> = {
|
||||
pending: 'Eingegangen',
|
||||
@@ -142,12 +143,12 @@ export default async function MyOrdersPage() {
|
||||
{o.pdf_url && (
|
||||
<>
|
||||
<Button variant="ghost" size="sm" asChild className="text-xs text-slate-400 hover:text-white">
|
||||
<a href={o.pdf_url} target="_blank" rel="noopener noreferrer">
|
||||
<a href={resolveSupabaseUrl(o.pdf_url)} target="_blank" rel="noopener noreferrer">
|
||||
<ExternalLink className="w-3 h-3 mr-1" /> Anfrage ansehen
|
||||
</a>
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" asChild className="text-xs text-slate-400 hover:text-white">
|
||||
<a href={o.pdf_url} download>
|
||||
<a href={resolveSupabaseUrl(o.pdf_url)} download>
|
||||
<Download className="w-3 h-3 mr-1" /> PDF
|
||||
</a>
|
||||
</Button>
|
||||
|
||||
@@ -7,6 +7,7 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Separator } from '@/components/ui/separator'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import type { Order } from '@/lib/types'
|
||||
import { resolveSupabaseUrl } from '@/lib/utils'
|
||||
|
||||
export default async function OrderSuccessPage({
|
||||
searchParams,
|
||||
@@ -150,12 +151,12 @@ export default async function OrderSuccessPage({
|
||||
{o.pdf_url && (
|
||||
<div className="flex gap-2 pt-2">
|
||||
<Button variant="outline" size="sm" asChild className="border-white/10 hover:bg-white/10">
|
||||
<a href={o.pdf_url} target="_blank" rel="noopener noreferrer">
|
||||
<a href={resolveSupabaseUrl(o.pdf_url)} target="_blank" rel="noopener noreferrer">
|
||||
<ExternalLink className="w-4 h-4 mr-2" /> Angebotsbestätigung ansehen
|
||||
</a>
|
||||
</Button>
|
||||
<Button variant="secondary" size="sm" asChild>
|
||||
<a href={o.pdf_url} download>
|
||||
<a href={resolveSupabaseUrl(o.pdf_url)} download>
|
||||
<Download className="w-4 h-4 mr-2" /> Herunterladen
|
||||
</a>
|
||||
</Button>
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { updateOrderStatus } from "@/lib/actions/orders";
|
||||
import { resolveSupabaseUrl } from "@/lib/utils";
|
||||
|
||||
interface OrdersTableProps {
|
||||
initialOrders: any[];
|
||||
@@ -225,7 +226,7 @@ export function OrdersTable({ initialOrders }: OrdersTableProps) {
|
||||
{order.pdf_url ? (
|
||||
<>
|
||||
<Button variant="outline" size="sm" asChild className="h-8 border-white/10 hover:bg-primary/20 text-xs">
|
||||
<a href={order.pdf_url} target="_blank" rel="noopener noreferrer">
|
||||
<a href={resolveSupabaseUrl(order.pdf_url)} target="_blank" rel="noopener noreferrer">
|
||||
<ExternalLink className="w-3.5 h-3.5 mr-1" /> PDF
|
||||
</a>
|
||||
</Button>
|
||||
|
||||
@@ -40,6 +40,22 @@ export function resolveSupabaseUrl(url: string | undefined): string | undefined
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
} else {
|
||||
// Server-Side fallback to localhost:8000 (for local development)
|
||||
try {
|
||||
const parsed = new URL(url);
|
||||
if (parsed.hostname === 'supabase-kong' || parsed.hostname === 'kong') {
|
||||
parsed.hostname = 'localhost';
|
||||
parsed.port = '8000';
|
||||
return parsed.toString().replace(/\/$/, '');
|
||||
}
|
||||
} catch {
|
||||
return url
|
||||
.replace('//supabase-kong:8000', '//localhost:8000')
|
||||
.replace('//kong:8000', '//localhost:8000')
|
||||
.replace('//supabase-kong', '//localhost:8000')
|
||||
.replace('//kong', '//localhost:8000');
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user