2025年7月7日17:11:20
parent
2a4583d6e0
commit
d13072c819
|
|
@ -8,6 +8,7 @@ import com.zhangmeng.minio.utils.AlertUtils;
|
|||
import com.zhangmeng.minio.utils.MinioUtils;
|
||||
import com.zhangmeng.minio.utils.ResourceUtils;
|
||||
import io.minio.messages.Bucket;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
|
|
@ -24,6 +25,7 @@ import javafx.scene.input.KeyCombination;
|
|||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
|
|
@ -37,6 +39,7 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -101,7 +104,7 @@ public class MinioController {
|
|||
public TableColumn<BucketFile, String> file_bucket;
|
||||
public ImageView preview;
|
||||
public TextField upload_path_dir;
|
||||
|
||||
public Button connect_server;
|
||||
|
||||
|
||||
private File upload_file;
|
||||
|
|
@ -256,9 +259,9 @@ public class MinioController {
|
|||
return;
|
||||
}
|
||||
String uri = MinioUtils.upload_file(upload_file, upload_path_dir.getText());
|
||||
if (uri != null){
|
||||
if (uri != null) {
|
||||
String bucketName = backet_list.getSelectionModel().getSelectedItem();
|
||||
loadPreview(bucketName,uri);
|
||||
loadPreview(bucketName, uri);
|
||||
reload();
|
||||
}
|
||||
|
||||
|
|
@ -298,6 +301,10 @@ public class MinioController {
|
|||
}
|
||||
});
|
||||
backet_list.setItems(backet_item_list);
|
||||
|
||||
connect_server.setOnAction(event -> {
|
||||
load_property();
|
||||
});
|
||||
}
|
||||
|
||||
public void save_properties() {
|
||||
|
|
@ -354,7 +361,7 @@ public class MinioController {
|
|||
}
|
||||
}
|
||||
|
||||
private void loadPreview(String bucketName, String objectName){
|
||||
private void loadPreview(String bucketName, String objectName) {
|
||||
String objectUrl = MinioUtils.getPresignedObjectUrl(bucketName, objectName);
|
||||
preview.setImage(new javafx.scene.image.Image(objectUrl));
|
||||
}
|
||||
|
|
@ -364,12 +371,17 @@ public class MinioController {
|
|||
//获取所有储存桶
|
||||
backet_item_list.clear();
|
||||
List<Bucket> buckets = MinioUtils.getAllBuckets();
|
||||
if (buckets.size() > 0) {
|
||||
for (Bucket bucket : buckets) {
|
||||
backet_item_list.add(bucket.name());
|
||||
}
|
||||
|
||||
if (buckets != null) {
|
||||
Platform.runLater(() -> {
|
||||
if (buckets.size() > 0) {
|
||||
for (Bucket bucket : buckets) {
|
||||
backet_item_list.add(bucket.name());
|
||||
}
|
||||
}
|
||||
this.backet_list.getSelectionModel().select(bucket_name.getText());
|
||||
});
|
||||
}
|
||||
this.backet_list.getSelectionModel().select(bucket_name.getText());
|
||||
}
|
||||
|
||||
public void load_property() {
|
||||
|
|
@ -388,7 +400,25 @@ public class MinioController {
|
|||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
load_bucket_list();
|
||||
|
||||
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
load_bucket_list();
|
||||
return "success";
|
||||
} catch (Exception e) {
|
||||
return "failure";
|
||||
}
|
||||
});
|
||||
|
||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||
alert.initModality(Modality.APPLICATION_MODAL);
|
||||
alert.setContentText("正在尝试连接服务器...");
|
||||
alert.setHeaderText(null);
|
||||
alert.show();
|
||||
|
||||
future.whenComplete((result, ex) -> {
|
||||
Platform.runLater(alert::close);
|
||||
});
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
|
|
|||
|
|
@ -60,7 +60,6 @@ public class MinioUtils {
|
|||
return null;
|
||||
}
|
||||
minioClient = MinioClient.builder().endpoint(endpoint.toString()).credentials(accessKey.toString(), secretKey.toString()).build();
|
||||
|
||||
}
|
||||
return minioClient;
|
||||
}
|
||||
|
|
@ -74,7 +73,10 @@ public class MinioUtils {
|
|||
try {
|
||||
return getDefault().listBuckets();
|
||||
} catch (ErrorResponseException | InsufficientDataException | InvalidKeyException | InternalException | InvalidResponseException | IOException | NoSuchAlgorithmException | ServerException | XmlParserException e) {
|
||||
e.printStackTrace();
|
||||
// e.printStackTrace();
|
||||
Platform.runLater(()->{
|
||||
AlertUtils.alert_warning("获取Bucket列表失败,请核对配置信息");
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
<AnchorPane prefHeight="649" prefWidth="1200" stylesheets="@../css/main.css" xmlns="http://javafx.com/javafx/23.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.zhangmeng.minio.controller.MinioController">
|
||||
<children>
|
||||
<AnchorPane fx:id="center" layoutY="25.0" prefHeight="623.0" prefWidth="1200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="25.0">
|
||||
<AnchorPane fx:id="center" layoutY="13.0" prefHeight="623.0" prefWidth="1200.0" AnchorPane.bottomAnchor="12.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="13.0">
|
||||
<children>
|
||||
<TableView fx:id="tableview" layoutX="378.0" layoutY="191.0" prefHeight="433.0" prefWidth="1200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="191.0">
|
||||
<columns>
|
||||
|
|
@ -39,6 +39,7 @@
|
|||
<Button fx:id="bucket_btn" layoutX="484.0" layoutY="11.0" mnemonicParsing="false" text="创建bucket" />
|
||||
<TextField fx:id="upload_path_dir" layoutX="112.0" layoutY="135.0" prefHeight="27.0" prefWidth="346.0" />
|
||||
<Label layoutX="15.0" layoutY="141.0" text="服务器相对路径:" />
|
||||
<Button fx:id="connect_server" layoutX="609.0" layoutY="75.0" mnemonicParsing="false" prefHeight="43.0" prefWidth="117.0" text="连接服务器" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<MenuBar prefHeight="25.0" prefWidth="240.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
|
||||
|
|
|
|||
Loading…
Reference in New Issue