diff --git a/plugins/s3/build.gradle.kts b/plugins/s3/build.gradle.kts index 5257ba7..c963d55 100644 --- a/plugins/s3/build.gradle.kts +++ b/plugins/s3/build.gradle.kts @@ -3,7 +3,7 @@ plugins { } -project.version = "0.0.3" +project.version = "0.0.4" dependencies { diff --git a/plugins/s3/src/main/kotlin/app/termora/plugins/s3/S3FileSystemProvider.kt b/plugins/s3/src/main/kotlin/app/termora/plugins/s3/S3FileSystemProvider.kt index 8dc404c..6ba483a 100644 --- a/plugins/s3/src/main/kotlin/app/termora/plugins/s3/S3FileSystemProvider.kt +++ b/plugins/s3/src/main/kotlin/app/termora/plugins/s3/S3FileSystemProvider.kt @@ -13,6 +13,7 @@ import java.nio.channels.SeekableByteChannel import java.nio.file.* import java.nio.file.attribute.* import java.nio.file.spi.FileSystemProvider +import java.util.concurrent.atomic.AtomicReference import kotlin.io.path.absolutePathString import kotlin.io.path.name @@ -63,25 +64,33 @@ class S3FileSystemProvider(private val minioClient: MinioClient) : FileSystemPro private fun createStreamer(path: S3Path): OutputStream { val pis = PipedInputStream() val pos = PipedOutputStream(pis) + val exception = AtomicReference() val thread = Thread.ofVirtual().start { - minioClient.putObject( - PutObjectArgs.builder() - .bucket(path.bucketName) - .stream(pis, -1, 32 * 1024 * 1024) - .`object`(path.objectName).build() - ) - IOUtils.closeQuietly(pis) + try { + minioClient.putObject( + PutObjectArgs.builder() + .bucket(path.bucketName) + .stream(pis, -1, 32 * 1024 * 1024) + .`object`(path.objectName).build() + ) + } catch (e: Exception) { + exception.set(e) + } finally { + IOUtils.closeQuietly(pis) + } } return object : OutputStream() { override fun write(b: Int) { + val exception = exception.get() + if (exception != null) throw exception pos.write(b) } override fun close() { pos.close() - thread.join() + if (thread.isAlive) thread.join() } } } diff --git a/plugins/s3/src/main/kotlin/app/termora/plugins/s3/S3Path.kt b/plugins/s3/src/main/kotlin/app/termora/plugins/s3/S3Path.kt index 8a3dca9..a639b89 100644 --- a/plugins/s3/src/main/kotlin/app/termora/plugins/s3/S3Path.kt +++ b/plugins/s3/src/main/kotlin/app/termora/plugins/s3/S3Path.kt @@ -1,5 +1,6 @@ package app.termora.plugins.s3 +import app.termora.transfer.WithPathAttributes import org.apache.sshd.common.file.util.BasePath import java.nio.file.LinkOption import java.nio.file.Path @@ -9,7 +10,7 @@ class S3Path( fileSystem: S3FileSystem, root: String?, names: List, -) : BasePath(fileSystem, root, names) { +) : BasePath(fileSystem, root, names), WithPathAttributes { private val separator get() = fileSystem.separator @@ -41,6 +42,11 @@ class S3Path( */ val objectName: String get() = names.subList(1, names.size).joinToString(separator) + override fun getCustomType(): String? { + if (isBucket) return "Bucket" + return null + } + override fun toRealPath(vararg options: LinkOption): Path { return toAbsolutePath() } diff --git a/plugins/s3/src/main/kotlin/app/termora/plugins/s3/S3Plugin.kt b/plugins/s3/src/main/kotlin/app/termora/plugins/s3/S3Plugin.kt index 050face..cfc7ff9 100644 --- a/plugins/s3/src/main/kotlin/app/termora/plugins/s3/S3Plugin.kt +++ b/plugins/s3/src/main/kotlin/app/termora/plugins/s3/S3Plugin.kt @@ -1,8 +1,5 @@ package app.termora.plugins.s3 -import app.termora.DynamicIcon -import app.termora.I18n -import app.termora.Icons import app.termora.plugin.Extension import app.termora.plugin.ExtensionSupport import app.termora.plugin.PaidPlugin diff --git a/src/main/kotlin/app/termora/transfer/TransportPanel.kt b/src/main/kotlin/app/termora/transfer/TransportPanel.kt index 2f1f325..1d1fab9 100644 --- a/src/main/kotlin/app/termora/transfer/TransportPanel.kt +++ b/src/main/kotlin/app/termora/transfer/TransportPanel.kt @@ -1115,7 +1115,7 @@ class TransportPanel( var text = when (column) { TransportTableModel.COLUMN_NAME -> attributes.name - TransportTableModel.COLUMN_TYPE -> attributes.type + TransportTableModel.COLUMN_TYPE -> getType(row, attributes) TransportTableModel.COLUMN_FILE_SIZE -> formatBytes(attributes.fileSize) // @formatter:off TransportTableModel.COLUMN_LAST_MODIFIED_TIME -> DateFormatUtils.format(Date(attributes.lastModifiedTime), I18n.getString("termora.date-format")) @@ -1164,6 +1164,15 @@ class TransportPanel( return c } + + private fun getType(row: Int, attributes: Attributes): String { + val path = model.getPath(sorter.convertRowIndexToModel(row)) + if (path is WithPathAttributes) { + val type = path.getCustomType() + if (type != null) return type + } + return attributes.type + } } private inner class MyUndoManager : UndoManager() { diff --git a/src/main/kotlin/app/termora/transfer/WithPathAttributes.kt b/src/main/kotlin/app/termora/transfer/WithPathAttributes.kt new file mode 100644 index 0000000..bd326aa --- /dev/null +++ b/src/main/kotlin/app/termora/transfer/WithPathAttributes.kt @@ -0,0 +1,8 @@ +package app.termora.transfer + +interface WithPathAttributes { + /** + * 获取类型 + */ + fun getCustomType(): String? = null +} \ No newline at end of file