Skip to content

Commit

Permalink
fix: hot fix
Browse files Browse the repository at this point in the history
  • Loading branch information
akicool committed Jan 11, 2025
1 parent eaf2d47 commit 04d8888
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/app/api/upload/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ export async function POST(request: NextRequest) {
// .replace(/ /g, "-")
// .replace(/[^a-zA-Z0-9_.-]/g, "");

const validateFilename = file.name.replace(/\s/g, "_");
const validateFilename =
file.name.trim() === ""
? `empty-name${randomUUID().slice(0, 6)}`
: file.name.replace(/\s/g, "_");

const filename = validateFilename;

Expand Down
9 changes: 7 additions & 2 deletions src/app/image/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ export default async function ImagePage({ params }: Props) {

<p className="mb-1">
<span className="font-medium">Загружено: </span>
<span>{dayjs(imageData?.created_at).format("DD.MM.YYYY")} </span>в
<span> {dayjs(imageData?.created_at).format("HH:mm")}</span>
<span>
{dayjs(imageData?.created_at).locale("ru").format("DD.MM.YYYY")}
</span>
в
<span>
{dayjs(imageData?.created_at).locale("ru").format("HH:mm")}
</span>
</p>

<p className="mb-1">
Expand Down
35 changes: 27 additions & 8 deletions src/components/ImageGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@ async function getPublicImages(page: number) {
.order("uploaded_at", { ascending: false })
.range((page - 1) * IMAGES_PER_PAGE, page * IMAGES_PER_PAGE - 1);

const { data: allImages } = await supabase
.from("image_metadata")
.select("*", { count: "exact" })
.eq("is_private", false)
.order("uploaded_at", { ascending: false });

if (error) {
console.error("Error fetching images:", error);
return { images: [], totalPages: 0 };
return { images: [], totalPages: 0, allImages: [] };
}

const totalPages = Math.ceil((count || 0) / IMAGES_PER_PAGE);

return { images: data || [], totalPages };
return { images: data || [], totalPages, allImages };
}

//TODO: BOTH OF THESE FUNCTIONS SHOULD BE REDESIGNED INTO ONE. !
Expand All @@ -37,14 +43,19 @@ async function getAllImages(page: number) {
.order("uploaded_at", { ascending: false })
.range((page - 1) * IMAGES_PER_PAGE, page * IMAGES_PER_PAGE - 1);

const { data: allImages } = await supabase
.from("image_metadata")
.select("*", { count: "exact" })
.order("uploaded_at", { ascending: false });

if (error) {
console.error("Error fetching images:", error);
return { images: [], totalPages: 0 };
return { images: [], totalPages: 0, allImages: [] };
}

const totalPages = Math.ceil((count || 0) / IMAGES_PER_PAGE);

return { images: data || [], totalPages };
return { images: data || [], totalPages, allImages };
}

type TypePayload = { role?: string | JwtPayload } | void;
Expand All @@ -63,7 +74,7 @@ export async function ImageGallery({ page }: { page: number }) {
}

//TODO: BOTH OF THESE FUNCTIONS SHOULD BE REDESIGNED INTO ONE. !
const { images, totalPages } =
const { images, totalPages, allImages } =
payload?.role === "admin"
? await getAllImages(page)
: await getPublicImages(page);
Expand All @@ -72,7 +83,9 @@ export async function ImageGallery({ page }: { page: number }) {
<>
{images.length ? (
<div>
<h2 className="text-2xl font-semibold">Галерея изображений</h2>
<h2 className="text-2xl font-semibold">
Галерея изображений ({allImages?.length || 0} шт)
</h2>
<div className="space-y-6 py-4">
<div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
{images.map((image) => {
Expand Down Expand Up @@ -115,10 +128,16 @@ export async function ImageGallery({ page }: { page: number }) {

<div className="absolute bottom-0 left-0 right-0 bg-black bg-opacity-50 text-white text-xs p-1 rounded-b-lg flex justify-between">
<span>
{dayjs(image?.created_at).format("DD.MM.YYYY")}
{dayjs(image?.created_at)
.locale("ru")
.format("DD.MM.YYYY")}
</span>

<span>{dayjs(image?.created_at).format("HH:mm")}</span>
<span>
{dayjs(image?.created_at)
.locale("ru")
.format("HH:mm")}
</span>
</div>
</div>
</Link>
Expand Down

0 comments on commit 04d8888

Please sign in to comment.