Skip to content

Commit

Permalink
[core] Remove jvmBase: AbsoluteFolder
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Aug 12, 2023
1 parent fc62c32 commit dcb17c4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 212 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
* Copyright 2019-2023 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.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/

@file:JvmBlockingBridge

package net.mamoe.mirai.contact.file

import kotlinx.coroutines.flow.Flow
import me.him188.kotlin.jvm.blocking.bridge.JvmBlockingBridge
import net.mamoe.mirai.contact.PermissionDeniedException
import net.mamoe.mirai.utils.ExternalResource
import net.mamoe.mirai.utils.JavaFriendlyAPI
import net.mamoe.mirai.utils.NotStableForInheritance
import net.mamoe.mirai.utils.ProgressionCallback
import java.util.stream.Stream

/**
* 绝对目录标识. 精确表示一个远程目录. 不会受同名文件或目录的影响.
Expand All @@ -23,8 +28,9 @@ import net.mamoe.mirai.utils.ProgressionCallback
* @see AbsoluteFile
* @see AbsoluteFileFolder
*/
@Suppress("SEALED_INHERITOR_IN_DIFFERENT_MODULE")
@NotStableForInheritance
public expect interface AbsoluteFolder : AbsoluteFileFolder {
public interface AbsoluteFolder : AbsoluteFileFolder {
/**
* 当前快照中文件数量, 当有文件更新时(上传/删除文件) 该属性不会更新.
*
Expand All @@ -37,7 +43,7 @@ public expect interface AbsoluteFolder : AbsoluteFileFolder {
/**
* 当该目录为空时返回 `true`.
*/
public open fun isEmpty(): Boolean
public fun isEmpty(): Boolean = contentsCount == 0

/**
* 返回更新了文件或目录信息 ([lastModifiedTime] 等) 的, 指向相同文件的 [AbsoluteFileFolder].
Expand All @@ -58,18 +64,42 @@ public expect interface AbsoluteFolder : AbsoluteFileFolder {
*/
public suspend fun folders(): Flow<AbsoluteFolder>

/**
* 获取该目录下所有子目录列表.
*
* 实现细节: 为了适合 Java 调用, 实现类似为阻塞式的 [folders], 因此不建议在 Kotlin 使用. 在 Kotlin 请使用 [folders].
*/
@JavaFriendlyAPI
public suspend fun foldersStream(): Stream<AbsoluteFolder>


/**
* 获取该目录下所有文件列表.
*/
public suspend fun files(): Flow<AbsoluteFile>

/**
* 获取该目录下所有文件列表.
*
* 实现细节: 为了适合 Java 调用, 实现类似为阻塞式的 [files], 因此不建议在 Kotlin 使用. 在 Kotlin 请使用 [files].
*/
@JavaFriendlyAPI
public suspend fun filesStream(): Stream<AbsoluteFile>


/**
* 获取该目录下所有文件和子目录列表.
*/
public suspend fun children(): Flow<AbsoluteFileFolder>

/**
* 获取该目录下所有文件和子目录列表.
*
* 实现细节: 为了适合 Java 调用, 实现类似为阻塞式的 [children], 因此不建议在 Kotlin 使用. 在 Kotlin 请使用 [children].
*/
@JavaFriendlyAPI
public suspend fun childrenStream(): Stream<AbsoluteFileFolder>

///////////////////////////////////////////////////////////////////////////
// resolve and upload
///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -101,6 +131,8 @@ public expect interface AbsoluteFolder : AbsoluteFileFolder {
/**
* 精确获取 [AbsoluteFile.id] 为 [id] 的文件. 在目标文件不存在时返回 `null`. 当 [deep] 为 `true` 时还会深入子目录查找.
*/
@Suppress("OVERLOADS_INTERFACE", "ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") // Keep JVM ABI
@JvmOverloads
public suspend fun resolveFileById(
id: String,
deep: Boolean = false
Expand All @@ -113,13 +145,33 @@ public expect interface AbsoluteFolder : AbsoluteFileFolder {
path: String
): Flow<AbsoluteFile>

/**
* 根据路径获取指向的所有路径为 [path] 的文件列表. 同时支持相对路径和绝对路径. 支持获取子目录内的文件.
*
* 实现细节: 为了适合 Java 调用, 实现类似为阻塞式的 [resolveFiles], 因此不建议在 Kotlin 使用. 在 Kotlin 请使用 [resolveFiles].
*/
@JavaFriendlyAPI
public suspend fun resolveFilesStream(
path: String
): Stream<AbsoluteFile>

/**
* 根据路径获取指向的所有路径为 [path] 的文件和目录列表. 同时支持相对路径和绝对路径. 支持获取子目录内的文件和目录.
*/
public suspend fun resolveAll(
path: String
): Flow<AbsoluteFileFolder>

/**
* 根据路径获取指向的所有路径为 [path] 的文件和目录列表. 同时支持相对路径和绝对路径. 支持获取子目录内的文件和目录.
*
* 实现细节: 为了适合 Java 调用, 实现类似为阻塞式的 [resolveAll], 因此不建议在 Kotlin 使用. 在 Kotlin 请使用 [resolveAll].
*/
@JavaFriendlyAPI
public suspend fun resolveAllStream(
path: String
): Stream<AbsoluteFileFolder>

/**
* 上传一个文件到该目录, 返回上传成功的文件标识.
*
Expand All @@ -137,6 +189,8 @@ public expect interface AbsoluteFolder : AbsoluteFileFolder {
*
* @throws PermissionDeniedException 当无管理员权限时抛出 (若群仅允许管理员上传)
*/
@Suppress("OVERLOADS_INTERFACE", "ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") // Keep JVM ABI
@JvmOverloads
public suspend fun uploadNewFile(
filepath: String,
content: ExternalResource,
Expand All @@ -148,7 +202,6 @@ public expect interface AbsoluteFolder : AbsoluteFileFolder {
* 根目录 folder ID.
* @see id
*/
@Suppress("CONST_VAL_WITHOUT_INITIALIZER") // compiler bug
public const val ROOT_FOLDER_ID: String
public const val ROOT_FOLDER_ID: String = "/"
}
}
207 changes: 0 additions & 207 deletions mirai-core-api/src/jvmBaseMain/kotlin/contact/file/AbsoluteFolder.kt

This file was deleted.

0 comments on commit dcb17c4

Please sign in to comment.