chore: display shared vault file usage (#2399)

* chore: display shared vault file usage

* fix: specs

* fix: reshape filtering result

* fix: resolving invalid server items

* fix: get revisions specs

* fix: processing issue

* fix: tests

---------

Co-authored-by: Mo <mo@standardnotes.com>
This commit is contained in:
Karol Sójko
2023-08-11 08:59:16 +02:00
committed by GitHub
parent 05f3672526
commit 5bca53736b
87 changed files with 505 additions and 169 deletions

View File

@@ -12,14 +12,38 @@ function CreateFilteredServerItem(item: ServerItemResponse): FilteredServerItem
}
}
export function FilterDisallowedRemotePayloadsAndMap(payloads: ServerItemResponse[]): FilteredServerItem[] {
return payloads.filter(isRemotePayloadAllowed).map(CreateFilteredServerItem)
}
export function isRemotePayloadAllowed(payload: ServerItemResponse): boolean {
if (isCorruptTransferPayload(payload)) {
return false
export function FilterDisallowedRemotePayloadsAndMap(payloads: ServerItemResponse[]): {
filtered: FilteredServerItem[]
disallowed: ServerItemResponse[]
} {
const filtered = []
const disallowed = []
for (const payload of payloads) {
const result = checkRemotePayloadAllowed(payload)
if (result.allowed === undefined) {
disallowed.push(payload)
} else {
filtered.push(CreateFilteredServerItem(result.allowed))
}
}
return isEncryptedTransferPayload(payload) || payload.content == undefined
return {
filtered,
disallowed,
}
}
export function checkRemotePayloadAllowed(payload: ServerItemResponse): {
allowed?: ServerItemResponse
disallowed?: ServerItemResponse
} {
if (isCorruptTransferPayload(payload)) {
return { disallowed: payload }
}
if (isEncryptedTransferPayload(payload) || payload.content == undefined) {
return { allowed: payload }
} else {
return { disallowed: payload }
}
}

View File

@@ -1,4 +1,4 @@
import { ProtocolVersion } from '@standardnotes/common'
import { ProtocolVersion } from '../../../Local/Protocol/ProtocolVersion'
import { EncryptedPayloadInterface } from '../../Payload/Interfaces/EncryptedPayload'
import { ItemInterface } from './ItemInterface'

View File

@@ -1,4 +1,5 @@
import { ProtocolVersion, protocolVersionFromEncryptedString } from '@standardnotes/common'
import { ProtocolVersion } from '../../../Local/Protocol/ProtocolVersion'
import { ProtocolVersionFromEncryptedString } from '../../../Local/Protocol/ProtocolVersionFromEncryptedString'
import { SyncResolvedParams, SyncResolvedPayload } from '../../../Runtime/Deltas/Utilities/SyncResolvedPayload'
import { EncryptedTransferPayload } from '../../TransferPayload/Interfaces/EncryptedTransferPayload'
import { EncryptedPayloadInterface } from '../Interfaces/EncryptedPayload'
@@ -18,13 +19,18 @@ export class EncryptedPayload extends PurePayload<EncryptedTransferPayload> impl
constructor(rawPayload: EncryptedTransferPayload, source = PayloadSource.Constructor) {
super(rawPayload, source)
const versionResult = ProtocolVersionFromEncryptedString(rawPayload.content)
if (versionResult.isFailed()) {
throw new Error('EncryptedPayload constructor versionResult is failed')
}
this.auth_hash = rawPayload.auth_hash
this.content = rawPayload.content
this.deleted = false
this.enc_item_key = rawPayload.enc_item_key
this.errorDecrypting = rawPayload.errorDecrypting
this.items_key_id = rawPayload.items_key_id
this.version = protocolVersionFromEncryptedString(this.content)
this.version = versionResult.getValue()
this.waitingForKey = rawPayload.waitingForKey
}

View File

@@ -1,4 +1,4 @@
import { ProtocolVersion } from '@standardnotes/common'
import { ProtocolVersion } from '../../../Local/Protocol/ProtocolVersion'
import { EncryptedTransferPayload } from '../../TransferPayload/Interfaces/EncryptedTransferPayload'
import { PayloadInterface } from './PayloadInterface'

View File

@@ -42,7 +42,7 @@ describe('type check', () => {
expect(
isCorruptTransferPayload({
uuid: '123',
content_type: ContentType.TYPES.Unknown,
content_type: 'Unknown',
content: '123',
...PayloadTimestampDefaults(),
}),

View File

@@ -26,5 +26,7 @@ export function isDeletedTransferPayload(payload: TransferPayload): payload is D
export function isCorruptTransferPayload(payload: TransferPayload): boolean {
const invalidDeletedState = payload.deleted === true && payload.content != undefined
return payload.uuid == undefined || invalidDeletedState || payload.content_type === ContentType.TYPES.Unknown
const contenTypeOrError = ContentType.create(payload.content_type)
return payload.uuid == undefined || invalidDeletedState || contenTypeOrError.isFailed()
}