Add live search to macOS popover

This commit is contained in:
2026-06-09 16:40:02 -04:00
parent 4666000ca3
commit 632621b226
5 changed files with 262 additions and 1 deletions

View File

@@ -209,6 +209,24 @@ public actor APIClient {
return try await perform(request)
}
public func searchDocuments(query: String) async throws -> [SearchResult] {
var components = URLComponents(url: baseURL.appendingPathComponent("api/search"), resolvingAgainstBaseURL: false)
components?.queryItems = [URLQueryItem(name: "q", value: query)]
guard let url = components?.url else {
throw APIError(error: "invalid search URL")
}
var request = URLRequest(url: url)
if let token = apiToken {
request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
}
request.setValue("application/json", forHTTPHeaderField: "Accept")
let response: SearchResponse = try await perform(request)
return response.results
}
// MARK: - Sync

View File

@@ -52,6 +52,12 @@ public struct DocumentSaveResponse: Codable {
public let hash: String
}
public struct SearchResult: Codable, Identifiable {
public var id: String { path }
public let path: String
public let title: String
}
public struct SyncInitRequest: Codable {
public let deviceId: String
public let rootPath: String
@@ -178,6 +184,10 @@ public struct DocumentsListResponse: Codable {
public let documents: [DocumentRecord]
}
public struct SearchResponse: Codable {
public let results: [SearchResult]
}
public enum UploadDuplicateAction: String {
case overwrite
case rename