Content Scanner Service (#5826)

* implemented the content scanner service with caching and a way to use in the state store context

* fix swiftformat comment enforcing

* pr suggestions
This commit is contained in:
Mauro
2026-07-02 17:12:39 +02:00
committed by GitHub
parent f2d08c23a3
commit 5ea4b46604
15 changed files with 480 additions and 7 deletions
@@ -0,0 +1,34 @@
//
// Copyright 2026 Element Creations Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Foundation
@preconcurrency import MatrixRustSDK
nonisolated struct ContentScannerProxy: ContentScannerProxyProtocol {
private let contentScanner: ContentScanner
/// The client is held weakly for the same reason as in `MediaLoader` - to avoid keeping the
/// underlying `MatrixRustSDK.Client` alive longer than the owning `ClientProxy`.
private weak var client: Client?
init(contentScanner: ContentScanner, client: Client) {
self.contentScanner = contentScanner
self.client = client
}
func scan(mediaSource: MediaSourceProxy) async -> Result<Bool, ContentScannerProxyError> {
guard let client else { return .failure(.missingClient) }
do {
let response = try await contentScanner.scan(client: client, mediaSource: mediaSource.underlyingSource)
return .success(response.clean)
} catch {
MXLog.error("Failed scanning media content: \(error)")
return .failure(.sdkError(error))
}
}
}