Add live search to macOS popover
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user