Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/isekai-frontend/src/components/DraftTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useState, useRef, useEffect } from 'react';
import { createPortal } from 'react-dom';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { FileImage, Send, X } from 'lucide-react';
import { thumb, ImageSize } from '@/lib/image';
import { Button } from '@/components/ui/button';
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
import { Textarea } from '@/components/ui/textarea';
Expand Down Expand Up @@ -219,7 +220,7 @@ export function DraftTableRow({ draft, isSelected, onSelect }: DraftTableRowProp
>
{draft.files && draft.files.length > 0 && draft.files[0].storageUrl ? (
<img
src={draft.files[0].storageUrl}
src={thumb(draft.files[0].storageUrl, ImageSize.XS)}
alt={draft.title}
className="w-full h-full object-cover object-center"
/>
Expand Down
3 changes: 2 additions & 1 deletion apps/isekai-frontend/src/components/ReviewDetailPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import { useState, useRef, useEffect } from 'react';
import { Check, X, FileImage } from 'lucide-react';
import { thumb, ImageSize } from '@/lib/image';
import { Card, CardContent } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Label } from '@/components/ui/label';
Expand Down Expand Up @@ -147,7 +148,7 @@ export function ReviewDetailPanel({
>
{deviation.files?.[0]?.storageUrl ? (
<img
src={deviation.files[0].storageUrl}
src={thumb(deviation.files[0].storageUrl, ImageSize.LG)}
alt={deviation.title}
className="max-w-full max-h-full object-contain"
/>
Expand Down
5 changes: 3 additions & 2 deletions apps/isekai-frontend/src/components/ReviewGridItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { FileImage } from 'lucide-react';
import { Badge } from '@/components/ui/badge';
import { Checkbox } from '@/components/ui/checkbox';
import { cn } from '@/lib/utils';
import { thumb, ImageSize } from '@/lib/image';
import type { Deviation } from '@isekai/shared';

interface ReviewGridItemProps {
Expand Down Expand Up @@ -69,7 +70,7 @@ export function ReviewGridItem({
<div className="flex-shrink-0 w-16 h-16 rounded overflow-hidden bg-muted">
{deviation.files?.[0]?.storageUrl ? (
<img
src={deviation.files[0].storageUrl}
src={thumb(deviation.files[0].storageUrl, ImageSize.XS)}
alt={deviation.title}
className="w-full h-full object-cover"
loading="lazy"
Expand Down Expand Up @@ -116,7 +117,7 @@ export function ReviewGridItem({
{/* Thumbnail image */}
{deviation.files?.[0]?.storageUrl ? (
<img
src={deviation.files[0].storageUrl}
src={thumb(deviation.files[0].storageUrl, ImageSize.MD)}
alt={deviation.title}
className="w-full h-full object-cover absolute inset-0"
loading="lazy"
Expand Down
37 changes: 37 additions & 0 deletions apps/isekai-frontend/src/lib/image.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Generate optimized image URL with resize parameters.
*
* When served through vault-proxy, these params trigger server-side resizing.
* When served directly from R2/S3, params are ignored (graceful degradation).
*/
export function thumb(
url: string | undefined | null,
width: number = 400,
options?: {
format?: 'webp' | 'jpeg' | 'png';
quality?: number;
}
): string {
if (!url) return '';

const params = new URLSearchParams();
params.set('w', width.toString());

if (options?.format) {
params.set('f', options.format);
}
if (options?.quality) {
params.set('q', options.quality.toString());
}

const separator = url.includes('?') ? '&' : '?';
return `${url}${separator}${params.toString()}`;
}

export const ImageSize = {
XS: 128, // Table thumbnails (56-64px display)
SM: 256, // Small grids
MD: 400, // Medium grids, cards
LG: 800, // Large previews
XL: 1200, // Detail views
} as const;
7 changes: 4 additions & 3 deletions apps/isekai-frontend/src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import { Link } from 'react-router-dom';
import { useQuery } from '@tanstack/react-query';
import { thumb, ImageSize } from '@/lib/image';
import {
ClipboardCheck,
FileImage,
Expand Down Expand Up @@ -271,7 +272,7 @@ export function Dashboard() {
{item.files?.[0]?.storageUrl ? (
<>
<img
src={item.files[0].storageUrl}
src={thumb(item.files[0].storageUrl, ImageSize.SM)}
alt={item.title}
className="h-full w-full object-cover group-hover:scale-105 transition-transform duration-300"
/>
Expand Down Expand Up @@ -330,7 +331,7 @@ export function Dashboard() {
{item.files?.[0]?.storageUrl ? (
<>
<img
src={item.files[0].storageUrl}
src={thumb(item.files[0].storageUrl, ImageSize.SM)}
alt={item.title}
className="h-full w-full object-cover group-hover:scale-105 transition-transform duration-300"
/>
Expand Down Expand Up @@ -420,7 +421,7 @@ export function Dashboard() {
</div>
{item.files?.[0]?.storageUrl ? (
<img
src={item.files[0].storageUrl}
src={thumb(item.files[0].storageUrl, ImageSize.XS)}
alt={item.title}
className="h-8 w-8 rounded-sm object-cover"
/>
Expand Down
3 changes: 2 additions & 1 deletion apps/isekai-frontend/src/pages/EditDeviation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { useState, useEffect } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { thumb, ImageSize } from '@/lib/image';
import { Calendar, Clock, Send, Save, Trash2, X } from 'lucide-react';
import { deviations } from '@/lib/api';
import { formatScheduleDateTime } from '@/lib/timezone';
Expand Down Expand Up @@ -316,7 +317,7 @@ export function EditDeviation() {
className="relative aspect-square rounded-lg overflow-hidden border"
>
<img
src={file.storageUrl}
src={thumb(file.storageUrl, ImageSize.MD)}
alt={file.originalFilename}
className="w-full h-full object-cover"
/>
Expand Down
3 changes: 2 additions & 1 deletion apps/isekai-frontend/src/pages/Published.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { useState, useEffect, useRef, useCallback } from 'react';
import { createPortal } from 'react-dom';
import { useInfiniteQuery, useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { thumb, ImageSize } from '@/lib/image';
import {
DollarSign,
ExternalLink,
Expand Down Expand Up @@ -484,7 +485,7 @@ function PublishedTableRow({
>
{deviation.files && deviation.files.length > 0 && deviation.files[0].storageUrl ? (
<img
src={deviation.files[0].storageUrl}
src={thumb(deviation.files[0].storageUrl, ImageSize.XS)}
alt={deviation.title}
className="w-full h-full object-cover object-center"
/>
Expand Down
7 changes: 4 additions & 3 deletions apps/isekai-frontend/src/pages/Schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { useState } from 'react';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { useNavigate } from 'react-router-dom';
import { thumb, ImageSize } from '@/lib/image';
import { Calendar, Clock, AlertCircle, CheckCircle2, XCircle, Upload, Eye } from 'lucide-react';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
Expand Down Expand Up @@ -334,7 +335,7 @@ function ScheduledDeviationCard({
{/* Thumbnail */}
{deviation.files && deviation.files.length > 0 && deviation.files[0].storageUrl ? (
<img
src={deviation.files[0].storageUrl}
src={thumb(deviation.files[0].storageUrl, ImageSize.XS)}
alt={deviation.title}
className="w-16 h-16 object-cover rounded"
/>
Expand Down Expand Up @@ -389,7 +390,7 @@ function PublishingDeviationCard({ deviation }: { deviation: Deviation }) {
{/* Thumbnail */}
{deviation.files && deviation.files.length > 0 && deviation.files[0].storageUrl ? (
<img
src={deviation.files[0].storageUrl}
src={thumb(deviation.files[0].storageUrl, ImageSize.XS)}
alt={deviation.title}
className="w-16 h-16 object-cover rounded"
/>
Expand Down Expand Up @@ -431,7 +432,7 @@ function FailedDeviationCard({
{/* Thumbnail */}
{deviation.files && deviation.files.length > 0 && deviation.files[0].storageUrl ? (
<img
src={deviation.files[0].storageUrl}
src={thumb(deviation.files[0].storageUrl, ImageSize.XS)}
alt={deviation.title}
className="w-16 h-16 object-cover rounded"
/>
Expand Down
3 changes: 2 additions & 1 deletion apps/isekai-frontend/src/pages/Scheduled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useState, useEffect, useRef, useCallback } from 'react';
import { createPortal } from 'react-dom';
import { useInfiniteQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { useNavigate } from 'react-router-dom';
import { thumb, ImageSize } from '@/lib/image';
import {
Clock,
X,
Expand Down Expand Up @@ -817,7 +818,7 @@ function ScheduledTableRow({
>
{deviation.files && deviation.files.length > 0 && deviation.files[0].storageUrl ? (
<img
src={deviation.files[0].storageUrl}
src={thumb(deviation.files[0].storageUrl, ImageSize.XS)}
alt={deviation.title}
className="w-full h-full object-cover object-center"
/>
Expand Down