chore: transfer supports custom type

This commit is contained in:
hstyi
2025-06-26 09:34:11 +08:00
committed by hstyi
parent 00dfb4ce39
commit 17082c5fb8
6 changed files with 43 additions and 14 deletions

View File

@@ -3,7 +3,7 @@ plugins {
}
project.version = "0.0.3"
project.version = "0.0.4"
dependencies {

View File

@@ -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<Throwable>()
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()
}
}
}

View File

@@ -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<String>,
) : BasePath<S3Path, S3FileSystem>(fileSystem, root, names) {
) : BasePath<S3Path, S3FileSystem>(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()
}

View File

@@ -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

View File

@@ -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() {

View File

@@ -0,0 +1,8 @@
package app.termora.transfer
interface WithPathAttributes {
/**
* 获取类型
*/
fun getCustomType(): String? = null
}