fix: get images endpoint
This commit is contained in:
parent
3cbb366a9d
commit
e0924f9c4b
|
|
@ -427,26 +427,43 @@ export class MinioStorageService implements StorageService {
|
||||||
|
|
||||||
const files: FileMetadata[] = [];
|
const files: FileMetadata[] = [];
|
||||||
|
|
||||||
|
console.log(`[MinIO listFiles] Starting list for prefix: ${searchPrefix}`);
|
||||||
|
const startTime = Date.now();
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const stream = this.client.listObjects(this.bucketName, searchPrefix, true);
|
const stream = this.client.listObjects(this.bucketName, searchPrefix, true);
|
||||||
|
|
||||||
stream.on('data', async (obj) => {
|
let dataCount = 0;
|
||||||
|
|
||||||
|
stream.on('data', (obj) => {
|
||||||
if (!obj.name || !obj.size) return;
|
if (!obj.name || !obj.size) return;
|
||||||
|
|
||||||
|
dataCount++;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const pathParts = obj.name.split('/');
|
const pathParts = obj.name.split('/');
|
||||||
const filename = pathParts[pathParts.length - 1];
|
const filename = pathParts[pathParts.length - 1];
|
||||||
|
|
||||||
if (!filename) return;
|
if (!filename) return;
|
||||||
|
|
||||||
const metadata = await this.client.statObject(this.bucketName, obj.name);
|
// Infer content type from file extension (more efficient than statObject)
|
||||||
|
const ext = filename.toLowerCase().split('.').pop();
|
||||||
|
const contentType =
|
||||||
|
{
|
||||||
|
png: 'image/png',
|
||||||
|
jpg: 'image/jpeg',
|
||||||
|
jpeg: 'image/jpeg',
|
||||||
|
gif: 'image/gif',
|
||||||
|
webp: 'image/webp',
|
||||||
|
svg: 'image/svg+xml',
|
||||||
|
}[ext || ''] || 'application/octet-stream';
|
||||||
|
|
||||||
files.push({
|
files.push({
|
||||||
filename,
|
filename,
|
||||||
size: obj.size,
|
size: obj.size,
|
||||||
contentType: metadata.metaData?.['content-type'] || 'application/octet-stream',
|
contentType,
|
||||||
lastModified: obj.lastModified || new Date(),
|
lastModified: obj.lastModified || new Date(),
|
||||||
etag: metadata.etag,
|
etag: obj.etag,
|
||||||
path: obj.name,
|
path: obj.name,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -454,9 +471,17 @@ export class MinioStorageService implements StorageService {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
stream.on('end', () => resolve(files));
|
stream.on('end', () => {
|
||||||
|
const elapsed = Date.now() - startTime;
|
||||||
|
console.log(
|
||||||
|
`[MinIO listFiles] Stream ended. Processed ${dataCount} objects, collected ${files.length} files in ${elapsed}ms`,
|
||||||
|
);
|
||||||
|
resolve(files);
|
||||||
|
});
|
||||||
|
|
||||||
stream.on('error', (error) => {
|
stream.on('error', (error) => {
|
||||||
console.error('[MinIO listFiles] Stream error:', error);
|
const elapsed = Date.now() - startTime;
|
||||||
|
console.error(`[MinIO listFiles] Stream error after ${elapsed}ms:`, error);
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue