mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-15 18:02:58 +08:00
chore: transfer supports custom type
This commit is contained in:
@@ -3,7 +3,7 @@ plugins {
|
||||
}
|
||||
|
||||
|
||||
project.version = "0.0.3"
|
||||
project.version = "0.0.4"
|
||||
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user