Browse Source

Remove use of deprecated RemoteFile

Him188 4 years ago
parent
commit
bb9c9d7aa4

+ 2 - 3
mirai-core-api/src/commonMain/kotlin/contact/FileSupported.kt

@@ -12,7 +12,6 @@ package net.mamoe.mirai.contact
 
 import net.mamoe.mirai.contact.file.RemoteFiles
 import net.mamoe.mirai.utils.NotStableForInheritance
-import net.mamoe.mirai.utils.RemoteFile
 
 /**
  * 支持文件操作的 [Contact]. 目前仅 [Group].
@@ -26,13 +25,13 @@ import net.mamoe.mirai.utils.RemoteFile
 @NotStableForInheritance
 public interface FileSupported : Contact {
     /**
-     * 文件根目录. 可通过 [RemoteFile.listFiles] 获取目录下文件列表.
+     * 文件根目录. 可通过 [net.mamoe.mirai.utils.RemoteFile.listFiles] 获取目录下文件列表.
      *
      * @since 2.5
      */
     @Suppress("DEPRECATION")
     @Deprecated("Please use files instead.", replaceWith = ReplaceWith("files.root")) // deprecated since 2.8.0-RC
-    public val filesRoot: RemoteFile
+    public val filesRoot: net.mamoe.mirai.utils.RemoteFile
 
     /**
      * 获取远程文件列表 (管理器).

+ 12 - 6
mirai-core-api/src/commonMain/kotlin/utils/ExternalResource.kt

@@ -29,8 +29,6 @@ import net.mamoe.mirai.message.data.sendTo
 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 net.mamoe.mirai.utils.RemoteFile.Companion.sendFile
-import net.mamoe.mirai.utils.RemoteFile.Companion.uploadFile
 import java.io.*
 import kotlin.contracts.InvocationKind
 import kotlin.contracts.contract
@@ -385,7 +383,9 @@ public interface ExternalResource : Closeable {
             contact: FileSupported,
             path: String,
             callback: RemoteFile.ProgressionCallback? = null,
-        ): FileMessage = toExternalResource().use { contact.uploadFile(path, it, callback) }
+        ): FileMessage = toExternalResource().use {
+            contact.filesRoot.resolve(path).upload(it, callback)
+        }
 
         /**
          * 上传文件并获取文件消息.
@@ -419,7 +419,9 @@ public interface ExternalResource : Closeable {
             contact: FileSupported,
             path: String,
             callback: RemoteFile.ProgressionCallback? = null,
-        ): FileMessage = contact.uploadFile(path, this, callback)
+        ): FileMessage {
+            return contact.filesRoot.resolve(path).upload(this, callback)
+        }
 
         // endregion
 
@@ -449,7 +451,9 @@ public interface ExternalResource : Closeable {
             contact: C,
             path: String,
             callback: RemoteFile.ProgressionCallback? = null,
-        ): MessageReceipt<C> = toExternalResource().use { contact.sendFile(path, it, callback) }
+        ): MessageReceipt<C> = toExternalResource().use {
+            contact.filesRoot.resolve(path).upload(it, callback).sendTo(contact)
+        }
 
         /**
          * 上传文件并发送件消息.  如果要上传的文件格式是图片或者语音, 也会将它们作为文件上传而不会调整消息类型.
@@ -474,7 +478,9 @@ public interface ExternalResource : Closeable {
             contact: C,
             path: String,
             callback: RemoteFile.ProgressionCallback? = null,
-        ): MessageReceipt<C> = contact.sendFile(path, this, callback)
+        ): MessageReceipt<C> {
+            return contact.filesRoot.resolve(path).upload(this, callback).sendTo(contact)
+        }
 
         // endregion