use of io.datarouter.storage.node.op.raw.read.DirectoryDto in project datarouter by hotpads.
the class S3BucketHandler method index.
@Handler(defaultHandler = true)
public Mav index(@Param(P_client) String client, @Param(P_bucket) String bucket, @Param(P_prefix) OptionalString prefix, @Param(P_after) OptionalString after, @Param(P_offset) OptionalInteger offset, @Param(P_limit) OptionalInteger limit, @Param(P_currentDirectory) OptionalBoolean currentDirectory, @Param(P_delimiter) OptionalString delimiter) {
var form = new HtmlForm().withMethod("get");
form.addTextField().withDisplay("Client").withName(P_client).withPlaceholder("theClientName").withValue(client);
form.addTextField().withDisplay("Bucket").withName(P_bucket).withPlaceholder("the.bucket.name").withValue(bucket);
form.addTextField().withDisplay("Prefix").withName(P_prefix).withValue(prefix.orElse(""));
form.addTextField().withDisplay("After").withName(P_after).withValue(after.orElse(""));
form.addTextField().withDisplay("Offset").withName(P_offset).withValue(offset.orElse(0) + "");
form.addTextField().withDisplay("Limit").withName(P_limit).withValue(limit.orElse(100) + "");
form.addTextField().withDisplay("Delimiter").withName(P_delimiter).withValue(delimiter.orElse(""));
form.addCheckboxField().withDisplay("currentDirectory").withName(P_currentDirectory).withChecked(currentDirectory.orElse(false));
form.addButton().withDisplay("Submit").withValue("");
var htmlForm = Bootstrap4FormHtml.render(form).withClass("card card-body bg-light");
ClientId clientId = clients.getClientId(client);
DatarouterS3Client s3Client = s3ClientManager.getClient(clientId);
List<DirectoryDto> objects = s3Client.scanSubdirectories(bucket, prefix.orElse(null), after.orElse(null), delimiter.orElse(null), limit.orElse(100), currentDirectory.orElse(false)).list();
int sizePadding = sizePadding(objects);
ContainerTag<?> table = new J2HtmlTable<DirectoryDto>().withClasses("sortable table table-sm table-striped my-4 border").withHtmlColumn("Key", object -> {
String name = object.name;
if (object.isDirectory) {
return td(makePrefixLink(client, bucket, name, "/"));
}
return td(name);
}).withHtmlColumn("Directory", object -> {
boolean isDirectory = object.isDirectory;
if (isDirectory) {
String href = new URIBuilder().setPath(request.getContextPath() + paths.datarouter.clients.awsS3.countObjects.toSlashedString()).addParameter(P_client, client).addParameter(P_bucket, bucket).addParameter(P_prefix, object.name).toString();
return td(a("true, view count").withHref(href));
}
return td(String.valueOf(isDirectory));
}).withHtmlColumn("Size", object -> {
String commas = NumberFormatter.addCommas(object.size);
String padded = StringTool.pad(commas, ' ', sizePadding);
String escaped = padded.replaceAll(" ", " ");
return td(rawHtml(escaped));
}).withColumn("Last Modified", object -> object.lastModified).withColumn("Storage Class", object -> object.storageClass).build(objects);
ContainerTag<?> tableWrapper = table.withStyle("font-family:monospace; font-size:.9em;");
var content = div(htmlForm, h4(bucket), tableWrapper).withClass("container-fluid my-4");
return pageFactory.startBuilder(request).withTitle("S3 Bucket").withRequires(DatarouterWebRequireJsV2.SORTTABLE).withContent(content).buildMav();
}
use of io.datarouter.storage.node.op.raw.read.DirectoryDto in project datarouter by hotpads.
the class BaseDatarouterS3Client method scanSubdirectories.
@Override
public Scanner<DirectoryDto> scanSubdirectories(String bucket, String prefix, String startAfter, String delimiter, int pageSize, boolean currentDirectory) {
ListObjectsV2Request request = ListObjectsV2Request.builder().bucket(bucket).prefix(prefix).startAfter(startAfter).delimiter(delimiter).maxKeys(pageSize).build();
ListObjectsV2Iterable pages;
try (var $ = TracerTool.startSpan("S3 listObjectsV2Paginator", TraceSpanGroupType.CLOUD_STORAGE)) {
pages = getS3ClientForBucket(bucket).listObjectsV2Paginator(request);
}
return Scanner.of(pages).map(res -> {
Scanner<DirectoryDto> objects = Scanner.of(res.contents()).map(object -> new DirectoryDto(object.key(), false, object.size(), object.lastModified(), object.storageClass().name()));
Scanner<DirectoryDto> prefixes = Scanner.of(res.commonPrefixes()).map(commonPrefix -> new DirectoryDto(commonPrefix.prefix(), true, 0L, null, null));
return Scanner.concat(objects, prefixes);
}).concat(Function.identity());
}
Aggregations