use of io.minio.ListObjectsArgs in project fess by codelibs.
the class AdminStorageAction method getFileItems.
public static List<Map<String, Object>> getFileItems(final String prefix) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final ArrayList<Map<String, Object>> list = new ArrayList<>();
try {
final MinioClient minioClient = createClient(fessConfig);
final ListObjectsArgs args = ListObjectsArgs.builder().bucket(fessConfig.getStorageBucket()).prefix(prefix != null && prefix.length() > 0 ? prefix + "/" : prefix).recursive(false).includeUserMetadata(false).useApiVersion1(false).build();
for (final Result<Item> result : minioClient.listObjects(args)) {
final Map<String, Object> map = new HashMap<>();
final Item item = result.get();
final String objectName = item.objectName();
map.put("id", encodeId(objectName));
map.put("name", getName(objectName));
map.put("hashCode", item.hashCode());
map.put("size", item.size());
map.put("directory", item.isDir());
if (!item.isDir()) {
map.put("lastModified", item.lastModified());
}
list.add(map);
if (list.size() > fessConfig.getStorageMaxItemsInPageAsInteger()) {
break;
}
}
} catch (final ErrorResponseException e) {
final String code = e.errorResponse().code();
if ("NoSuchBucket".equals(code)) {
final MinioClient minioClient = createClient(fessConfig);
try {
final MakeBucketArgs args = MakeBucketArgs.builder().bucket(fessConfig.getStorageBucket()).build();
minioClient.makeBucket(args);
logger.info("Created bucket: {}", fessConfig.getStorageBucket());
} catch (final Exception e1) {
logger.warn("Failed to create bucket: {}", fessConfig.getStorageBucket(), e1);
}
} else if (logger.isDebugEnabled()) {
logger.debug("Failed to access {}", fessConfig.getStorageEndpoint(), e);
}
} catch (final Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to access {}", fessConfig.getStorageEndpoint(), e);
}
}
return list;
}
Aggregations