|
|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Copyright 2019-2020 Mamoe Technologies and contributors.
|
|
|
+ * Copyright 2019-2021 Mamoe Technologies and contributors.
|
|
|
*
|
|
|
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
|
|
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
|
|
@@ -7,11 +7,15 @@
|
|
|
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
|
|
*/
|
|
|
|
|
|
+@file:Suppress("unused", "MemberVisibilityCanBePrivate")
|
|
|
+
|
|
|
package net.mamoe.mirai.utils
|
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
import net.mamoe.mirai.IMirai
|
|
|
+import net.mamoe.mirai.utils.ExternalResource.Companion.sendAsImageTo
|
|
|
import net.mamoe.mirai.utils.ExternalResource.Companion.toExternalResource
|
|
|
+import net.mamoe.mirai.utils.ExternalResource.Companion.uploadAsImage
|
|
|
import java.io.File
|
|
|
import java.io.IOException
|
|
|
import java.io.InputStream
|
|
|
@@ -21,12 +25,12 @@ import java.io.InputStream
|
|
|
*
|
|
|
* 由于上传资源时服务器要求提前给出 MD5 和文件大小等数据, 一些资源如 [InputStream] 需要首先缓存才能使用.
|
|
|
*
|
|
|
- * Mirai 全局都使用 [IMirai.FileCacheStrategy].
|
|
|
+ * Mirai 全局都使用 [IMirai.FileCacheStrategy]. 可以覆盖.
|
|
|
*
|
|
|
* ### 使用 [FileCacheStrategy] 的操作
|
|
|
* [ExternalResource.toExternalResource],
|
|
|
- * [InputStream.uploadAsImage],
|
|
|
- * [InputStream.sendAsImageTo]
|
|
|
+ * [ExternalResource.uploadAsImage],
|
|
|
+ * [ExternalResource.sendAsImageTo]
|
|
|
*
|
|
|
* @see ExternalResource
|
|
|
*/
|
|
|
@@ -66,12 +70,11 @@ public interface FileCacheStrategy {
|
|
|
/**
|
|
|
* 使用系统临时文件夹缓存图片文件. 在图片使用完毕后删除临时文件.
|
|
|
*/
|
|
|
- @MiraiExperimentalApi
|
|
|
public class TempCache @JvmOverloads constructor(
|
|
|
/**
|
|
|
- * 缓存图片存放位置. 为 `null` 时使用主机系统的临时文件夹
|
|
|
+ * 缓存图片存放位置. 为 `null` 时使用主机系统的临时文件夹: `File.createTempFile("tmp", null, directory)`
|
|
|
*/
|
|
|
- public val directory: File? = null
|
|
|
+ public val directory: File? = null,
|
|
|
) : FileCacheStrategy {
|
|
|
private fun createTempFile(): File {
|
|
|
return File.createTempFile("tmp", null, directory)
|