Обновление времени при записи, StorageMetaInfo
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package com.github.nullptroma.wallenc.domain.common.impl
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.datatypes.StorageEncryptionInfo
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IMetaInfo
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IStorage
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IStorageMetaInfo
|
||||
import java.time.Clock
|
||||
import java.time.Instant
|
||||
|
||||
|
||||
data class CommonStorageMetaInfo(
|
||||
override val encInfo: StorageEncryptionInfo?,
|
||||
override val name: String?,
|
||||
override val lastModified: Instant = Clock.systemUTC().instant()
|
||||
) : IStorageMetaInfo
|
||||
@@ -2,9 +2,9 @@ package com.github.nullptroma.wallenc.domain.datatypes
|
||||
|
||||
class DataPage<T>(
|
||||
list: List<T>,
|
||||
isLoading: Boolean? = false,
|
||||
isError: Boolean? = false,
|
||||
val hasNext: Boolean? = false,
|
||||
isLoading: Boolean? = null,
|
||||
isError: Boolean? = null,
|
||||
val hasNext: Boolean? = null,
|
||||
val pageLength: Int,
|
||||
val pageIndex: Int
|
||||
) : DataPackage<List<T>>(data = list, isLoading = isLoading, isError = isError)
|
||||
@@ -1,38 +1,46 @@
|
||||
package com.github.nullptroma.wallenc.domain.encrypt
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.common.impl.CommonStorageMetaInfo
|
||||
import com.github.nullptroma.wallenc.domain.datatypes.EncryptKey
|
||||
import com.github.nullptroma.wallenc.domain.datatypes.StorageEncryptionInfo
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.ILogger
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IStorage
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IStorageMetaInfo
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.DisposableHandle
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import java.util.UUID
|
||||
|
||||
class EncryptedStorage(
|
||||
private val source: IStorage,
|
||||
private val _source: IStorage,
|
||||
key: EncryptKey,
|
||||
ioDispatcher: CoroutineDispatcher,
|
||||
private val ioDispatcher: CoroutineDispatcher,
|
||||
override val uuid: UUID = UUID.randomUUID()
|
||||
) : IStorage, DisposableHandle {
|
||||
override val size: StateFlow<Long?>
|
||||
get() = source.size
|
||||
get() = _source.size
|
||||
override val numberOfFiles: StateFlow<Int?>
|
||||
get() = source.numberOfFiles
|
||||
override val name: StateFlow<String>
|
||||
get() = TODO("Not yet implemented")
|
||||
override val isAvailable: StateFlow<Boolean>
|
||||
get() = source.isAvailable
|
||||
override val encInfo: StateFlow<StorageEncryptionInfo?>
|
||||
get() = MutableStateFlow(
|
||||
StorageEncryptionInfo(
|
||||
get() = _source.numberOfFiles
|
||||
|
||||
private val _metaInfo = MutableStateFlow<IStorageMetaInfo>(
|
||||
CommonStorageMetaInfo(
|
||||
encInfo = StorageEncryptionInfo(
|
||||
isEncrypted = false,
|
||||
encryptedTestData = null
|
||||
)
|
||||
),
|
||||
name = null
|
||||
)
|
||||
)
|
||||
override val metaInfo: StateFlow<IStorageMetaInfo>
|
||||
get() = _metaInfo
|
||||
|
||||
override val isAvailable: StateFlow<Boolean>
|
||||
get() = _source.isAvailable
|
||||
override val accessor: EncryptedStorageAccessor =
|
||||
EncryptedStorageAccessor(source.accessor, key, ioDispatcher)
|
||||
EncryptedStorageAccessor(_source.accessor, key, ioDispatcher)
|
||||
|
||||
override suspend fun rename(newName: String) {
|
||||
TODO("Not yet implemented")
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.github.nullptroma.wallenc.domain.datatypes.DataPackage
|
||||
import com.github.nullptroma.wallenc.domain.datatypes.EncryptKey
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IDirectory
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IFile
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.ILogger
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IMetaInfo
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IStorageAccessor
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
@@ -30,8 +29,8 @@ class EncryptedStorageAccessor(
|
||||
key: EncryptKey,
|
||||
ioDispatcher: CoroutineDispatcher
|
||||
) : IStorageAccessor, DisposableHandle {
|
||||
private val _job = Job()
|
||||
private val _scope = CoroutineScope(ioDispatcher + _job)
|
||||
private val job = Job()
|
||||
private val scope = CoroutineScope(ioDispatcher + job)
|
||||
|
||||
override val size: StateFlow<Long?> = source.size
|
||||
override val numberOfFiles: StateFlow<Int?> = source.numberOfFiles
|
||||
@@ -43,14 +42,14 @@ class EncryptedStorageAccessor(
|
||||
private val _dirsUpdates = MutableSharedFlow<DataPackage<List<IDirectory>>>()
|
||||
override val dirsUpdates: SharedFlow<DataPackage<List<IDirectory>>> = _dirsUpdates
|
||||
|
||||
private val _encryptor = Encryptor(key.toAesKey())
|
||||
private val encryptor = Encryptor(key.toAesKey())
|
||||
|
||||
init {
|
||||
collectSourceState()
|
||||
}
|
||||
|
||||
private fun collectSourceState() {
|
||||
_scope.launch {
|
||||
scope.launch {
|
||||
launch {
|
||||
source.filesUpdates.collect {
|
||||
val files = it.data.map(::decryptEntity)
|
||||
@@ -116,7 +115,7 @@ class EncryptedStorageAccessor(
|
||||
val path = Path(pathStr)
|
||||
val segments = mutableListOf<String>()
|
||||
for (segment in path)
|
||||
segments.add(_encryptor.encryptString(segment.pathString))
|
||||
segments.add(encryptor.encryptString(segment.pathString))
|
||||
val res = Path("/",*(segments.toTypedArray()))
|
||||
return res.pathString
|
||||
}
|
||||
@@ -125,7 +124,7 @@ class EncryptedStorageAccessor(
|
||||
val path = Path(pathStr)
|
||||
val segments = mutableListOf<String>()
|
||||
for (segment in path)
|
||||
segments.add(_encryptor.decryptString(segment.pathString))
|
||||
segments.add(encryptor.decryptString(segment.pathString))
|
||||
val res = Path("/",*(segments.toTypedArray()))
|
||||
return res.pathString
|
||||
}
|
||||
@@ -198,12 +197,12 @@ class EncryptedStorageAccessor(
|
||||
|
||||
override suspend fun openWrite(path: String): OutputStream {
|
||||
val stream = source.openWrite(encryptPath(path))
|
||||
return _encryptor.encryptStream(stream)
|
||||
return encryptor.encryptStream(stream)
|
||||
}
|
||||
|
||||
override suspend fun openRead(path: String): InputStream {
|
||||
val stream = source.openRead(encryptPath(path))
|
||||
return _encryptor.decryptStream(stream)
|
||||
return encryptor.decryptStream(stream)
|
||||
}
|
||||
|
||||
override suspend fun moveToTrash(path: String) {
|
||||
@@ -211,7 +210,8 @@ class EncryptedStorageAccessor(
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
_job.cancel()
|
||||
_encryptor.dispose()
|
||||
job.cancel()
|
||||
encryptor.dispose()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.github.nullptroma.wallenc.domain.interfaces
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.datatypes.StorageEncryptionInfo
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import java.util.UUID
|
||||
|
||||
@@ -9,6 +8,5 @@ sealed interface IStorageInfo {
|
||||
val isAvailable: StateFlow<Boolean>
|
||||
val size: StateFlow<Long?>
|
||||
val numberOfFiles: StateFlow<Int?>
|
||||
val encInfo: StateFlow<StorageEncryptionInfo?>
|
||||
val name: StateFlow<String?>
|
||||
val metaInfo: StateFlow<IStorageMetaInfo>
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.github.nullptroma.wallenc.domain.interfaces
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.datatypes.StorageEncryptionInfo
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import java.time.Clock
|
||||
import java.time.Instant
|
||||
|
||||
interface IStorageMetaInfo {
|
||||
val encInfo: StorageEncryptionInfo?
|
||||
val name: String?
|
||||
val lastModified: Instant
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user