Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加了更多存储 #79

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

incubator4
Copy link

从原来的File存储增加了S3/OSS的支持

给存储的层面做了一个抽象

abstract class AbstractImageStorage {
    abstract suspend fun load(url: String) : ByteArray
    abstract suspend fun save(url: String, bytes: ByteArray)
    suspend fun getImageWithCache(url: String) : InputStream {
        val bytes = if (PluginConfig.cache) {
            try {
                load(url)
            } catch (e: Exception) {
                // 如果没有缓存,则下载图片
                downloadImage(url)
            }
        } else {
            downloadImage(url)
        }

        if (PluginConfig.save) {
            save(url, bytes)
        }
        return bytes.inputStream()
    }
}

增加了一个StorageConfig的内容,用于判断存储类型和保存OSS/S3的AK/SK

object StorageConfig : AutoSavePluginConfig("StorageConfig") {
    /**
     * 存储类型
     */
    @ValueDescription("可选:FILE/S3/OSS")
    val type: String by value("FILE")

    val accessKey: String by value("")
    val secretKey: String by value("")
    val bucket: String by value("")
    val endpoint: String by value("")
    val region: String by value("")
}

其中 accesskeysecretkey是用于访问对象存储的工具,对于minio和阿里云ossendpointbucket是必要的,endpoint是一个url地址用于访问,bucket是具体的桶

对于AWS S3 来说,可以使用region代替 endpoint

@Samarium150
Copy link
Owner

感谢pr,我其实有想在V6支持mirai-android的(虽然它好久没更了),新引入的依赖支持android端吗

@Samarium150 Samarium150 added the enhancement New feature or request label May 10, 2022
@incubator4
Copy link
Author

感谢pr,我其实有想在V6支持mirai-android的(虽然它好久没更了),新引入的依赖支持android端吗

原则上来讲是支持的,引用了AWS S3的SDK和Aliyun OSS的SDK,阿里云的是作为Android 依赖的版本存在的,至于aws的s3,由于它是一套通用的对象存储协议,所以基于对云厂商的信任,认为它应该是支持Android的,不过没有做进一步的测试,不能得出一定的结论

@Samarium150
Copy link
Owner

ci为什么会裂开 Details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants