From 7a2508a4490d42dbfa6b35a6f42e036e98f9cc66 Mon Sep 17 00:00:00 2001 From: tigerenwork Date: Sat, 11 Jul 2026 00:31:50 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E9=A3=9E?= =?UTF-8?q?=E4=B9=A6=20API=20=E7=9A=84=20field=5Fnames=20=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=8F=8A=20configFieldNames=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Services/Feishu/FeishuService.swift | 33 ++------------------- 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/Sources/Services/Feishu/FeishuService.swift b/Sources/Services/Feishu/FeishuService.swift index e533b40..b9ead7b 100644 --- a/Sources/Services/Feishu/FeishuService.swift +++ b/Sources/Services/Feishu/FeishuService.swift @@ -58,15 +58,12 @@ final class FeishuService { accessToken: String, userOpenId: String? ) async throws -> [RecordItem] { - let fieldNames = configFieldNames(config) - // Tier 1: search endpoint with open_id (Person fields) if let openId = userOpenId, !openId.isEmpty { do { let records = try await searchRecords( config: config, accessToken: accessToken, - fieldNames: fieldNames, assigneeField: config.fieldMappings.assigneeField, openId: openId ) @@ -86,7 +83,6 @@ final class FeishuService { let records = try await listAllRecords( config: config, accessToken: accessToken, - fieldNames: fieldNames, filter: filterStr ) if !records.isEmpty { @@ -98,31 +94,20 @@ final class FeishuService { BuggerLog.debug("FeishuService: tier 2 failed (\(error.localizedDescription)), falling back") } - // Tier 3: unfiltered list (current behavior) + // Tier 3: unfiltered list (original behavior) BuggerLog.debug("FeishuService: tier 3 (unfiltered list)") return try await listAllRecords( config: config, accessToken: accessToken, - fieldNames: fieldNames, filter: nil ) } - /// Build the list of field names to request from the Feishu API, to reduce - /// the per-record payload. Includes all mapped fields. - private func configFieldNames(_ config: AppConfig) -> [String] { - let m = config.fieldMappings - return [m.titleField, m.priorityField, m.statusField, m.assigneeField, - m.reporterField, m.customerField, m.createdAtField, m.updatedAtField] - .filter { !$0.isEmpty } - } - // MARK: - List endpoint (GET /records) private func listAllRecords( config: AppConfig, accessToken: String, - fieldNames: [String], filter: String? ) async throws -> [RecordItem] { var allRecords: [RecordItem] = [] @@ -140,8 +125,7 @@ final class FeishuService { tableId: config.tableId, pageToken: pageToken, accessToken: accessToken, - filter: filter, - fieldNames: fieldNames + filter: filter ) allRecords.append(contentsOf: page.items) pageToken = page.hasMore ? page.pageToken : nil @@ -156,8 +140,7 @@ final class FeishuService { pageToken: String?, pageSize: Int = 500, accessToken: String, - filter: String? = nil, - fieldNames: [String]? = nil + filter: String? = nil ) async throws -> RecordListData { guard !appToken.isEmpty, !tableId.isEmpty else { throw FeishuError.invalidConfiguration("App token and table ID must not be empty.") @@ -174,10 +157,6 @@ final class FeishuService { if let filter, !filter.isEmpty { queryItems.append(URLQueryItem(name: "filter", value: filter)) } - if let fieldNames, !fieldNames.isEmpty { - let jsonArray = "[\(fieldNames.map { "\"\($0)\"" }.joined(separator: ","))]" - queryItems.append(URLQueryItem(name: "field_names", value: jsonArray)) - } components.queryItems = queryItems guard let url = components.url else { @@ -221,7 +200,6 @@ final class FeishuService { private func searchRecords( config: AppConfig, accessToken: String, - fieldNames: [String], assigneeField: String, openId: String ) async throws -> [RecordItem] { @@ -240,7 +218,6 @@ final class FeishuService { tableId: config.tableId, pageToken: pageToken, accessToken: accessToken, - fieldNames: fieldNames, assigneeField: assigneeField, openId: openId ) @@ -256,7 +233,6 @@ final class FeishuService { tableId: String, pageToken: String?, accessToken: String, - fieldNames: [String], assigneeField: String, openId: String ) async throws -> RecordListData { @@ -285,9 +261,6 @@ final class FeishuService { if let pageToken, !pageToken.isEmpty { body["page_token"] = pageToken } - if !fieldNames.isEmpty { - body["field_names"] = fieldNames - } var request = URLRequest(url: url) request.httpMethod = "POST"