AbsoluteFile.kt 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright 2019-2021 Mamoe Technologies and contributors.
  3. *
  4. * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
  5. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  6. *
  7. * https://github.com/mamoe/mirai/blob/dev/LICENSE
  8. */
  9. @file:JvmBlockingBridge
  10. @file:Suppress("OVERLOADS_INTERFACE")
  11. package net.mamoe.mirai.contact.file
  12. import kotlinx.io.errors.IOException
  13. import net.mamoe.kjbb.JvmBlockingBridge
  14. import net.mamoe.mirai.contact.PermissionDeniedException
  15. import net.mamoe.mirai.message.data.FileMessage
  16. import net.mamoe.mirai.utils.NotStableForInheritance
  17. /**
  18. * 绝对文件标识. 精确表示一个远程文件. 不会受同名文件或目录的影响.
  19. *
  20. * @since 2.8
  21. * @see RemoteFiles
  22. * @see AbsoluteFolder
  23. * @see AbsoluteFileFolder
  24. */
  25. @NotStableForInheritance
  26. public interface AbsoluteFile : AbsoluteFileFolder {
  27. /**
  28. * 文件到期时间戳, 单位秒.
  29. */
  30. public val expiryTime: Long
  31. /**
  32. * 文件大小 (占用空间), 单位 byte.
  33. */
  34. public val size: Long
  35. /**
  36. * 文件内容 SHA-1.
  37. */
  38. public val sha1: ByteArray
  39. /**
  40. * 文件内容 MD5.
  41. */
  42. public val md5: ByteArray
  43. /**
  44. * 移动远程文件到 [folder] 目录下. 成功时返回 `true`, 当远程文件不存在时返回 `false`.
  45. *
  46. * 注意该操作有可能产生同名文件或目录 (当 [folder] 中已经存在一个名称为 [name] 的文件或目录时).
  47. *
  48. * @throws IOException 当发生网络错误时可能抛出
  49. * @throws IllegalStateException 当发生已知的协议错误时抛出
  50. * @throws PermissionDeniedException 当无管理员权限时抛出 (若群仅允许管理员上传)
  51. */
  52. public suspend fun moveTo(folder: AbsoluteFolder): Boolean
  53. /**
  54. * 获得下载链接 URL 字符串. 当远程文件不存在时返回 `null`.
  55. */
  56. public suspend fun getUrl(): String?
  57. /**
  58. * 得到 [AbsoluteFile] 所对应的 [FileMessage].
  59. *
  60. * 注: 在 [上传文件][RemoteFiles.uploadNewFile] 时就已经发送了文件消息, [FileMessage] 不可手动发送
  61. */
  62. public fun toMessage(): FileMessage
  63. /**
  64. * 返回更新了文件或目录信息 ([lastModifiedTime] 等) 的, 指向相同文件的 [AbsoluteFileFolder].
  65. * 不会更新当前 [AbsoluteFileFolder] 对象.
  66. *
  67. * 当远程文件或目录不存在时返回 `null`.
  68. *
  69. * 该函数会遍历上级目录的所有文件并匹配当前文件, 因此可能会非常慢, 请不要频繁使用.
  70. */
  71. override suspend fun refreshed(): AbsoluteFile?
  72. }