tambahannya

This commit is contained in:
bipproduction
2025-02-19 17:41:56 +08:00
parent 0d4a8329d7
commit 9bde6a2a06
74 changed files with 1079 additions and 186 deletions

View File

@@ -0,0 +1,30 @@
import fs from "fs/promises";
async function imgs({
search = "",
page = 1,
count = 20,
UPLOAD_DIR_IMAGE,
}: {
search?: string;
page?: number;
count?: number;
UPLOAD_DIR_IMAGE: string;
}) {
const files = await fs.readdir(UPLOAD_DIR_IMAGE);
return files
.filter(
(file) =>
file.endsWith(".jpg") || file.endsWith(".png") || file.endsWith(".jpeg")
)
.filter((file) => file.includes(search))
.slice((page - 1) * count, page * count)
.map((file) => ({
name: file,
url: `/api/img/${file}`,
total: files.length,
}));
}
export default imgs;