Fix MinIO connection by disabling SSL and add debugging
- Change MinIO configuration to use non-SSL connection (useSSL: false) - Add test-connection endpoint to verify MinIO connectivity - Add comprehensive logging to track connection issues - Enhance error messages in list files API for better debugging
This commit is contained in:
@@ -5,6 +5,15 @@ import type { BucketItem } from 'minio';
|
||||
export const getMinioClient = () => {
|
||||
const config = useRuntimeConfig().minio;
|
||||
|
||||
console.log('MinIO Config:', {
|
||||
endPoint: config.endPoint,
|
||||
port: config.port,
|
||||
useSSL: config.useSSL,
|
||||
bucketName: config.bucketName,
|
||||
hasAccessKey: !!config.accessKey,
|
||||
hasSecretKey: !!config.secretKey,
|
||||
});
|
||||
|
||||
return new Client({
|
||||
endPoint: config.endPoint,
|
||||
port: config.port,
|
||||
@@ -19,59 +28,87 @@ export const listFiles = async (prefix: string = '', recursive: boolean = false)
|
||||
const client = getMinioClient();
|
||||
const bucketName = useRuntimeConfig().minio.bucketName;
|
||||
|
||||
console.log(`Listing files from bucket: ${bucketName}, prefix: ${prefix}, recursive: ${recursive}`);
|
||||
|
||||
const files: any[] = [];
|
||||
const folders = new Set<string>();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const stream = client.listObjectsV2(bucketName, prefix, recursive);
|
||||
|
||||
stream.on('data', (obj) => {
|
||||
if (!recursive && prefix) {
|
||||
// Extract folder structure when not recursive
|
||||
const relativePath = obj.name.substring(prefix.length);
|
||||
const firstSlash = relativePath.indexOf('/');
|
||||
|
||||
if (firstSlash > -1) {
|
||||
// This is a folder
|
||||
const folderName = relativePath.substring(0, firstSlash);
|
||||
folders.add(prefix + folderName + '/');
|
||||
} else if (relativePath) {
|
||||
// This is a file in the current folder
|
||||
files.push({
|
||||
name: obj.name,
|
||||
size: obj.size,
|
||||
lastModified: obj.lastModified,
|
||||
etag: obj.etag,
|
||||
isFolder: false,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// When recursive or at root, include all files
|
||||
if (!obj.name.endsWith('/')) {
|
||||
files.push({
|
||||
name: obj.name,
|
||||
size: obj.size,
|
||||
lastModified: obj.lastModified,
|
||||
etag: obj.etag,
|
||||
isFolder: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
stream.on('error', reject);
|
||||
stream.on('end', () => {
|
||||
// Add folders to the result
|
||||
const folderItems = Array.from(folders).map(folder => ({
|
||||
name: folder,
|
||||
size: 0,
|
||||
lastModified: new Date(),
|
||||
etag: '',
|
||||
isFolder: true,
|
||||
}));
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
// First check if bucket exists
|
||||
const bucketExists = await client.bucketExists(bucketName);
|
||||
console.log(`Bucket ${bucketName} exists:`, bucketExists);
|
||||
|
||||
resolve([...folderItems, ...files]);
|
||||
});
|
||||
if (!bucketExists) {
|
||||
console.error(`Bucket ${bucketName} does not exist`);
|
||||
reject(new Error(`Bucket ${bucketName} does not exist`));
|
||||
return;
|
||||
}
|
||||
|
||||
const stream = client.listObjectsV2(bucketName, prefix, recursive);
|
||||
let objectCount = 0;
|
||||
|
||||
stream.on('data', (obj) => {
|
||||
objectCount++;
|
||||
console.log('Object found:', obj.name);
|
||||
|
||||
if (!recursive && prefix) {
|
||||
// Extract folder structure when not recursive
|
||||
const relativePath = obj.name.substring(prefix.length);
|
||||
const firstSlash = relativePath.indexOf('/');
|
||||
|
||||
if (firstSlash > -1) {
|
||||
// This is a folder
|
||||
const folderName = relativePath.substring(0, firstSlash);
|
||||
folders.add(prefix + folderName + '/');
|
||||
} else if (relativePath) {
|
||||
// This is a file in the current folder
|
||||
files.push({
|
||||
name: obj.name,
|
||||
size: obj.size,
|
||||
lastModified: obj.lastModified,
|
||||
etag: obj.etag,
|
||||
isFolder: false,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// When recursive or at root, include all files
|
||||
if (!obj.name.endsWith('/')) {
|
||||
files.push({
|
||||
name: obj.name,
|
||||
size: obj.size,
|
||||
lastModified: obj.lastModified,
|
||||
etag: obj.etag,
|
||||
isFolder: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
stream.on('error', (error) => {
|
||||
console.error('Stream error:', error);
|
||||
reject(error);
|
||||
});
|
||||
|
||||
stream.on('end', () => {
|
||||
console.log(`Stream ended. Total objects processed: ${objectCount}`);
|
||||
|
||||
// Add folders to the result
|
||||
const folderItems = Array.from(folders).map(folder => ({
|
||||
name: folder,
|
||||
size: 0,
|
||||
lastModified: new Date(),
|
||||
etag: '',
|
||||
isFolder: true,
|
||||
}));
|
||||
|
||||
console.log(`Returning ${folderItems.length} folders and ${files.length} files`);
|
||||
resolve([...folderItems, ...files]);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error in listFiles:', error);
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user