mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-10 20:14:10 +08:00
Merge remote-tracking branch 'mirai/dev' into dev
This commit is contained in:
commit
841b94e9a7
@ -5922,11 +5922,11 @@ public abstract interface class net/mamoe/mirai/utils/RemoteFile {
|
||||
public fun toMessage ()Lnet/mamoe/mirai/message/data/FileMessage;
|
||||
public abstract fun toMessage (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public abstract fun toString ()Ljava/lang/String;
|
||||
public fun upload (Ljava/io/File;)Z
|
||||
public fun upload (Ljava/io/File;)Lnet/mamoe/mirai/message/data/FileMessage;
|
||||
public fun upload (Ljava/io/File;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public fun upload (Lnet/mamoe/mirai/utils/ExternalResource;)Z
|
||||
public fun upload (Lnet/mamoe/mirai/utils/ExternalResource;)Lnet/mamoe/mirai/message/data/FileMessage;
|
||||
public fun upload (Lnet/mamoe/mirai/utils/ExternalResource;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public fun upload (Lnet/mamoe/mirai/utils/ExternalResource;Lnet/mamoe/mirai/utils/RemoteFile$ProgressionCallback;)Z
|
||||
public fun upload (Lnet/mamoe/mirai/utils/ExternalResource;Lnet/mamoe/mirai/utils/RemoteFile$ProgressionCallback;)Lnet/mamoe/mirai/message/data/FileMessage;
|
||||
public abstract fun upload (Lnet/mamoe/mirai/utils/ExternalResource;Lnet/mamoe/mirai/utils/RemoteFile$ProgressionCallback;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun upload$default (Lnet/mamoe/mirai/utils/RemoteFile;Lnet/mamoe/mirai/utils/ExternalResource;Lnet/mamoe/mirai/utils/RemoteFile$ProgressionCallback;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public fun uploadAndSend (Ljava/io/File;)Lnet/mamoe/mirai/message/MessageReceipt;
|
||||
|
@ -5951,11 +5951,11 @@ public abstract interface class net/mamoe/mirai/utils/RemoteFile {
|
||||
public fun toMessage ()Lnet/mamoe/mirai/message/data/FileMessage;
|
||||
public abstract fun toMessage (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public abstract fun toString ()Ljava/lang/String;
|
||||
public fun upload (Ljava/io/File;)Z
|
||||
public fun upload (Ljava/io/File;)Lnet/mamoe/mirai/message/data/FileMessage;
|
||||
public fun upload (Ljava/io/File;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public fun upload (Lnet/mamoe/mirai/utils/ExternalResource;)Z
|
||||
public fun upload (Lnet/mamoe/mirai/utils/ExternalResource;)Lnet/mamoe/mirai/message/data/FileMessage;
|
||||
public fun upload (Lnet/mamoe/mirai/utils/ExternalResource;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public fun upload (Lnet/mamoe/mirai/utils/ExternalResource;Lnet/mamoe/mirai/utils/RemoteFile$ProgressionCallback;)Z
|
||||
public fun upload (Lnet/mamoe/mirai/utils/ExternalResource;Lnet/mamoe/mirai/utils/RemoteFile$ProgressionCallback;)Lnet/mamoe/mirai/message/data/FileMessage;
|
||||
public abstract fun upload (Lnet/mamoe/mirai/utils/ExternalResource;Lnet/mamoe/mirai/utils/RemoteFile$ProgressionCallback;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun upload$default (Lnet/mamoe/mirai/utils/RemoteFile;Lnet/mamoe/mirai/utils/ExternalResource;Lnet/mamoe/mirai/utils/RemoteFile$ProgressionCallback;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public fun uploadAndSend (Ljava/io/File;)Lnet/mamoe/mirai/message/MessageReceipt;
|
||||
|
@ -21,7 +21,6 @@ import net.mamoe.mirai.contact.FileSupported
|
||||
import net.mamoe.mirai.contact.Group
|
||||
import net.mamoe.mirai.message.MessageReceipt
|
||||
import net.mamoe.mirai.message.data.FileMessage
|
||||
import net.mamoe.mirai.message.data.sendTo
|
||||
import net.mamoe.mirai.utils.ExternalResource.Companion.toExternalResource
|
||||
import java.io.File
|
||||
|
||||
@ -291,11 +290,12 @@ public interface RemoteFile {
|
||||
* 而使用 [resolveById] 或 [listFiles] 获取到的总是覆盖旧文件, 当旧文件已在远程删除时上传一个新文件.
|
||||
*
|
||||
* @param resource 需要上传的文件资源. 无论上传是否成功, 本函数都不会关闭 [resource].
|
||||
* @throws IllegalStateException 该文件上传失败时抛出
|
||||
*/
|
||||
public suspend fun upload(
|
||||
resource: ExternalResource,
|
||||
callback: ProgressionCallback? = null
|
||||
): Boolean
|
||||
): FileMessage
|
||||
|
||||
/**
|
||||
* 上传文件到 [RemoteFile] 表示的路径. 当无权上传或其他原因失败时返回 `false`.
|
||||
@ -308,15 +308,16 @@ public interface RemoteFile {
|
||||
* 而使用 [resolveById] 或 [listFiles] 获取到的总是覆盖旧文件, 当旧文件已在远程删除时上传一个新文件.
|
||||
*
|
||||
* @param resource 需要上传的文件资源. 无论上传是否成功, 本函数都不会关闭 [resource].
|
||||
* @throws IllegalStateException 该文件上传失败时抛出
|
||||
* @see upload
|
||||
*/
|
||||
public suspend fun upload(resource: ExternalResource): Boolean = upload(resource, null)
|
||||
public suspend fun upload(resource: ExternalResource): FileMessage = upload(resource, null)
|
||||
|
||||
/**
|
||||
* 上传文件.
|
||||
* @see upload
|
||||
*/
|
||||
public suspend fun upload(file: File): Boolean = file.toExternalResource().use { upload(it) }
|
||||
public suspend fun upload(file: File): FileMessage = file.toExternalResource().use { upload(it) }
|
||||
|
||||
/**
|
||||
* 上传文件并发送文件消息.
|
||||
@ -381,9 +382,7 @@ public interface RemoteFile {
|
||||
*/
|
||||
@JvmStatic
|
||||
public suspend fun FileSupported.uploadFile(path: String, resource: ExternalResource): FileMessage {
|
||||
val file = this.filesRoot.resolve(path)
|
||||
if (!file.upload(resource)) error("Failed to upload file")
|
||||
return file.toMessage() ?: error("Failed to create FileMessage.")
|
||||
return this.filesRoot.resolve(path).upload(resource)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -396,11 +395,8 @@ public interface RemoteFile {
|
||||
path: String,
|
||||
resource: ExternalResource
|
||||
): MessageReceipt<C> {
|
||||
val file = this.filesRoot.resolve(path)
|
||||
if (!file.upload(resource)) {
|
||||
error("Failed to upload file")
|
||||
}
|
||||
return file.toMessage()?.sendTo(this) ?: error("Failed to create FileMessage.")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return this.filesRoot.resolve(path).uploadAndSend(resource) as MessageReceipt<C>
|
||||
}
|
||||
}
|
||||
}
|
@ -416,9 +416,12 @@ internal class RemoteFileImpl(
|
||||
.sendAndExpect(bot).toResult("RemoteFile.mkdir", checkResp = false).getOrThrow().int32RetCode == 0
|
||||
}
|
||||
|
||||
override suspend fun upload(resource: ExternalResource, callback: RemoteFile.ProgressionCallback?): Boolean {
|
||||
val parent = parent ?: return false
|
||||
val parentInfo = parent.getFileFolderInfo() ?: return false
|
||||
private suspend fun upload0(
|
||||
resource: ExternalResource,
|
||||
callback: RemoteFile.ProgressionCallback?
|
||||
): Oidb0x6d6.UploadFileRspBody? {
|
||||
val parent = parent ?: return null
|
||||
val parentInfo = parent.getFileFolderInfo() ?: return null
|
||||
val resp = FileManagement.RequestUpload(
|
||||
client,
|
||||
groupCode = contact.id,
|
||||
@ -427,7 +430,7 @@ internal class RemoteFileImpl(
|
||||
filename = this.name
|
||||
).sendAndExpect(bot).toResult("RemoteFile.upload").getOrThrow()
|
||||
if (resp.boolFileExist) {
|
||||
return true
|
||||
return resp
|
||||
}
|
||||
|
||||
val ext = GroupFileUploadExt(
|
||||
@ -495,12 +498,21 @@ internal class RemoteFileImpl(
|
||||
}
|
||||
)
|
||||
|
||||
return true
|
||||
return resp
|
||||
}
|
||||
|
||||
override suspend fun upload(
|
||||
resource: ExternalResource,
|
||||
callback: RemoteFile.ProgressionCallback?
|
||||
): FileMessage {
|
||||
val resp = upload0(resource, null) ?: error("Failed to upload file.")
|
||||
return FileMessageImpl(
|
||||
name, resp.fileId, resource.size, resp.busId
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun uploadAndSend(resource: ExternalResource): MessageReceipt<Contact> {
|
||||
if (!upload(resource)) error("Failed to upload file.")
|
||||
return toMessage()?.sendTo(contact) ?: error("Failed to create FileMessage")
|
||||
return upload(resource).sendTo(contact)
|
||||
}
|
||||
|
||||
// override suspend fun writeSession(resource: ExternalResource): FileUploadSession {
|
||||
@ -534,4 +546,4 @@ internal class RemoteFileImpl(
|
||||
if (!info.isFile) return null
|
||||
return FileMessageImpl(name, info.id, info.size, info.busId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user