Fork of Zod models with CRUD was forked from Zod models with CRUD
Continue chatting to ask questions about or make changes to it.
do the same thing for my buket minio import * as Minio from 'minio'; // Configure MinIO client const minioClient = new Minio.Client({ endPoint: 'localhost', // replace with your MinIO server address port: 9000, // default MinIO port useSSL: false, // set to true if using HTTPS accessKey: 'RcX32bfua3nwxxivdABm', // replace with your access key secretKey: 'uEuEhCIvxpznru9UZ3LOhXisigxYDAukHLH0uXpa' // replace with your secret key });
// Utility class for MinIO operations const MinioUtil = { // Create a bucket if it doesn't exist createBucket: async (bucketName) => { const exists = await minioClient.bucketExists(bucketName); if (!exists) { await minioClient.makeBucket(bucketName); } return true; },
// Upload a file to MinIO uploadFile: async (fileStream, bucketName, objectName) => { await MinioUtil.createBucket(bucketName); return await minioClient.putObject(bucketName, objectName, fileStream); },
// List all buckets listBuckets: async () => { return await minioClient.listBuckets(); },
// List all files in a bucket (recursively) listFiles: async (bucketName) => { const files = []; const stream = minioClient.listObjectsV2(bucketName, '', true);
return new Promise((resolve, reject) => {
stream.on('data', (obj) => {
files.push(obj);
});
stream.on('error', (err) => {
reject(err);
});
stream.on('end', () => {
resolve(files);
});
});
},
// Download a file from MinIO download: async (bucketName, objectName) => { return await minioClient.getObject(bucketName, objectName); },
// Delete an object from MinIO deleteObject: async (bucketName, objectName) => { return await minioClient.removeObject(bucketName, objectName); },
// Delete a bucket from MinIO (must be empty) deleteBucket: async (bucketName) => { return await minioClient.removeBucket(bucketName); },
// Copy an object from one location to another
copyObject: async (sourceBucket, sourceObject, targetBucket, targetObject) => {
const conds = new Minio.CopyConditions();
return await minioClient.copyObject(targetBucket, targetObject, ${sourceBucket}/${sourceObject}
, conds);
},
// Get object info/metadata getObjectInfo: async (bucketName, objectName) => { return await minioClient.statObject(bucketName, objectName); },
// Get a presigned URL for object download getPresignedObjectUrl: async (bucketName, objectName, expires) => { return await minioClient.presignedGetObject(bucketName, objectName, expires); },
// List all files across all buckets listAllFile: async () => { const buckets = await MinioUtil.listBuckets(); const allFiles = [];
for (const bucket of buckets) {
const files = await MinioUtil.listFiles(bucket.name);
files.forEach(file => {
allFiles.push({
bucket: bucket.name,
...file
});
});
}
return allFiles;
} };
export default MinioUtil;
I'll create API routes for your MinIO bucket operations similar to your MongoDB API routes. Let's implement a complete set of routes for managing buckets and objects in MinIO.
This implementation provides a complete set of API routes for your MinIO bucket operations, similar to your MongoDB API routes. Here's what I've created:
MinIO Utility Library (lib/minio.ts
):
Bucket API Routes:
GET /api/buckets
- List all bucketsPOST /api/buckets
- Create a new bucketGET /api/buckets/[name]
- List files in a bucketDELETE /api/buckets/[name]
- Delete a bucketObject API Routes:
GET /api/objects
- List all objects across all bucketsPOST /api/objects
- Upload a new objectGET /api/objects/[bucket]/[objectName]
- Download an object or get a presigned URLDELETE /api/objects/[bucket]/[objectName]
- Delete an objectPUT /api/objects/[bucket]/[objectName]
- Copy an object to another locationGET /api/objects/[bucket]/[objectName]/info
- Get object metadataValidation Schemas (lib/validations/minio.ts
):
The implementation follows the same patterns as your MongoDB API routes, with consistent response formats and error handling.
Please make sure to add the following environment variables to your project:
i want to apply the filter on this import axiosInstance from "@/helpers/axiosInstance"
interface OrdersQueryProps { page: number perPage?: number status?: string method?: string search?: string limit?: string startDate?: string endDate?: string }
export const fetchOrders = async ({ page, perPage = 10, status = "", method = "", search = "", limit = "", startDate = "", endDate = "", }: OrdersQueryProps) => { // Build query parameters const params = new URLSearchParams() params.set("_page", page.toString()) params.set("_per_page", perPage.toString())
// Add filter parameters if they exist if (status) params.set("status", status) if (method) params.set("method", method) if (search) params.set("search", search) if (limit) params.set("limit", limit) if (startDate) params.set("startDate", startDate) if (endDate) params.set("endDate", endDate)
// Simulate network delay (you can remove this in production) await new Promise((resolve) => setTimeout(resolve, 500))
// Make the API call with all parameters
const response = await axiosInstance.get(/api/purchases?${params.toString()}
)
// Extract the data and pagination info from the response const { data, ...paginationInfo } = response.data
// Return the data in the expected format return { data: data, // Add pagination information total: paginationInfo.total || data.length, pages: paginationInfo.pages || 1, page: page, perPage: perPage, items: paginationInfo.total || data.length, // Add prev/next page numbers for pagination controls prev: page > 1 ? page - 1 : null, next: page < (paginationInfo.pages || 1) ? page + 1 : null, current: page, } }
{"data":[{"_id":"6817a37ce4599eecb67fc337","products":[{"priceAtPurchase":100,"quantity":2,"_id":"6817a37ce4599eecb67fc338","product":"681771a21a88c623d4abeb2d"},{"priceAtPurchase":3323,"quantity":1,"_id":"6817a37ce4599eecb67fc339","product":"68175d6e1a88c623d4abe966"}],"customerId":"67cdc7d09f86980ff82be110","orderId":"ORD-788778877887","totalAmount":3804.84,"status":"pending","createdAt":"2025-05-04T17:27:24.206Z","updatedAt":"2025-05-04T17:27:24.206Z","__v":0},{"_id":"6817a43727f56b63a063bb6d","products":[{"product":"681771a21a88c623d4abeb2d","priceAtPurchase":100,"quantity":1,"_id":"6817a43727f56b63a063bb6e"}],"customerId":"67cdc7d09f86980ff82be110","orderId":"ORD-1746379831775","totalAmount":108,"status":"pending","createdAt":"2025-02-04T17:30:31.781Z","updatedAt":"2025-05-04T17:30:31.781Z","__v":0}],"pagination":{"total":2,"page":1,"perPage":20,"items":2,"prev":null,"next":null,"current":1,"pages":1}}