Domain
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
package com.github.nullptroma.wallenc.domain.utils
|
||||
package com.github.nullptroma.wallenc.domain.datatypes
|
||||
|
||||
open class DataPackage<T>(
|
||||
val data: T,
|
||||
val hasNext: Boolean? = false,
|
||||
val isLoading: Boolean? = false,
|
||||
val isError: Boolean? = false
|
||||
)
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.github.nullptroma.wallenc.domain.utils
|
||||
package com.github.nullptroma.wallenc.domain.datatypes
|
||||
|
||||
class DataPage<T>(
|
||||
list: List<T>,
|
||||
val hasNext: Boolean? = false,
|
||||
val pageLength: Int,
|
||||
val pageNumber: Int
|
||||
) : DataPackage<List<T>>(list)
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.github.nullptroma.wallenc.domain.datatypes
|
||||
|
||||
class EncryptKey {
|
||||
val key: String
|
||||
|
||||
constructor(key: String) {
|
||||
this@EncryptKey.key = key
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.github.nullptroma.wallenc.domain.enums
|
||||
|
||||
enum class VaultType {
|
||||
LOCAL,
|
||||
YANDEX
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
package com.github.nullptroma.wallenc.domain.storage
|
||||
package com.github.nullptroma.wallenc.domain.models
|
||||
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import java.util.UUID
|
||||
|
||||
interface IStorage {
|
||||
val size: StateFlow<Int>
|
||||
val numberOfFiles: StateFlow<Int>
|
||||
val uuid: String
|
||||
val size: StateFlow<Int?>
|
||||
val numberOfFiles: StateFlow<Int?>
|
||||
val uuid: UUID
|
||||
val name: StateFlow<String>
|
||||
val totalSpace: StateFlow<Int?>
|
||||
val availableSpace: StateFlow<Int?>
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.github.nullptroma.wallenc.domain.models
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.datatypes.DataPackage
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import java.net.URI
|
||||
|
||||
interface IStorageAccessor {
|
||||
val isAvailable: StateFlow<Boolean>
|
||||
val filesUpdates: SharedFlow<DataPackage<IFile>>
|
||||
val dirsUpdates: SharedFlow<DataPackage<IDirectory>>
|
||||
|
||||
suspend fun getAllFiles(): List<IFile>
|
||||
suspend fun getFiles(path: URI): List<IFile>
|
||||
/**
|
||||
* Получение списка файлов в директории
|
||||
* @param path Путь к директории
|
||||
* @return Поток файлов
|
||||
*/
|
||||
fun getFilesFlow(path: URI): Flow<DataPackage<IFile>>
|
||||
|
||||
suspend fun getAllDirs(): List<IDirectory>
|
||||
suspend fun getDirs(path: URI): List<IDirectory>
|
||||
/**
|
||||
* Получение списка директорий в директории
|
||||
* @param path Путь к директории
|
||||
* @return Поток директорий
|
||||
*/
|
||||
fun getDirsFlow(path: URI): Flow<DataPackage<IDirectory>>
|
||||
|
||||
suspend fun touchFile(path: URI)
|
||||
suspend fun touchDir(path: URI)
|
||||
suspend fun delete(path: URI)
|
||||
suspend fun getFileInfo(path: URI)
|
||||
suspend fun getDirInfo(path: URI)
|
||||
suspend fun openWrite(path: URI): InputStream
|
||||
suspend fun openRead(path: URI): OutputStream
|
||||
suspend fun moveToTrash(path: URI)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.github.nullptroma.wallenc.domain.models
|
||||
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import java.net.URL
|
||||
|
||||
interface IStorageExplorer {
|
||||
val currentPath: StateFlow<URL>
|
||||
|
||||
// TODO
|
||||
// пока бесполезный интерфейс
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.github.nullptroma.wallenc.domain.models
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.datatypes.EncryptKey
|
||||
import java.util.UUID
|
||||
|
||||
interface IVault : IVaultInfo {
|
||||
suspend fun createStorage(name: String): IStorage
|
||||
suspend fun createStorage(name: String, key: EncryptKey): IStorage
|
||||
suspend fun createStorage(name: String, key: EncryptKey, uuid: UUID): IStorage
|
||||
suspend fun remove(storage: IStorage)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.github.nullptroma.wallenc.domain.models
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.enums.VaultType
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import java.util.UUID
|
||||
|
||||
interface IVaultInfo {
|
||||
val type: VaultType
|
||||
val uuid: UUID
|
||||
val storages: StateFlow<List<IStorage>>
|
||||
val isAvailable: StateFlow<Boolean>
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.github.nullptroma.wallenc.domain.models
|
||||
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
interface IVaultsManager {
|
||||
val localVault: StateFlow<IVault>
|
||||
val remoteVaults: StateFlow<List<IVault>>
|
||||
|
||||
fun addYandexVault(email: String, token: String)
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.github.nullptroma.wallenc.domain.storage
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.models.IDirectory
|
||||
import com.github.nullptroma.wallenc.domain.models.IFile
|
||||
import com.github.nullptroma.wallenc.domain.utils.DataPackage
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import java.net.URI
|
||||
|
||||
interface IStorageAccessor {
|
||||
val isAvailable: StateFlow<Boolean>
|
||||
val filesUpdates: SharedFlow<IFile>
|
||||
val dirsUpdates: SharedFlow<IDirectory>
|
||||
|
||||
suspend fun getAllFiles(): List<IFile>
|
||||
suspend fun getFiles(path: URI): List<IFile>
|
||||
fun getFilesStream(path: URI): Flow<DataPackage<IFile>>
|
||||
|
||||
suspend fun getAllDirs(): List<IDirectory>
|
||||
suspend fun getDirs(path: URI): List<IDirectory>
|
||||
fun getDirsStream(path: URI): Flow<DataPackage<IDirectory>>
|
||||
|
||||
suspend fun touchFile(path: URI)
|
||||
suspend fun touchDir(path: URI)
|
||||
suspend fun delete(path: URI)
|
||||
suspend fun getFileInfo(path: URI)
|
||||
suspend fun getDirInfo(path: URI)
|
||||
suspend fun openWrite(path: URI)
|
||||
suspend fun openRead(path: URI)
|
||||
suspend fun moveToTrash(path: URI)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.github.nullptroma.wallenc.domain.usecases
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.models.IVault
|
||||
import com.github.nullptroma.wallenc.domain.models.IVaultsManager
|
||||
import kotlinx.coroutines.flow.combine
|
||||
|
||||
class GetAllRawStoragesUseCase(val manager: IVaultsManager) {
|
||||
fun getStoragesFlow() = manager.remoteVaults.combine(manager.localVault) { remote, local ->
|
||||
mutableListOf<IVault>().apply {
|
||||
addAll(remote)
|
||||
add(local)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user