Files
desa-darmasaba/src/app/api/[[...slugs]]/_lib/imgs.ts
nico 6fc79f7541 feat(storage): migrate file storage from local disk to MinIO
Replace local filesystem-based image storage with MinIO S3-compatible
object storage. All upload, serve, delete, and list operations now use
the MinIO bucket defined in MINIO_* env vars.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-23 11:40:43 +08:00

31 lines
731 B
TypeScript

import minio, { MINIO_BUCKET } from "@/lib/minio";
async function imgs({
search = "",
page = 1,
count = 20,
}: {
search?: string;
page?: number;
count?: number;
}) {
const objects: { name: string; url: string }[] = [];
const stream = minio.listObjects(MINIO_BUCKET, "image/", true);
for await (const obj of stream) {
if (!obj.name) continue;
const fileName = obj.name.replace("image/", "");
if (!fileName) continue;
if (search && !fileName.includes(search)) continue;
objects.push({ name: fileName, url: `/api/img/${fileName}` });
}
const total = objects.length;
return objects
.slice((page - 1) * count, page * count)
.map((o) => ({ ...o, total }));
}
export default imgs;