refactor: 移除飞书 API 的 field_names 参数及 configFieldNames 方法

This commit is contained in:
tigerenwork 2026-07-11 00:31:50 +08:00
parent a0b1fb8aa3
commit 7a2508a449
1 changed files with 3 additions and 30 deletions

View File

@ -58,15 +58,12 @@ final class FeishuService {
accessToken: String, accessToken: String,
userOpenId: String? userOpenId: String?
) async throws -> [RecordItem] { ) async throws -> [RecordItem] {
let fieldNames = configFieldNames(config)
// Tier 1: search endpoint with open_id (Person fields) // Tier 1: search endpoint with open_id (Person fields)
if let openId = userOpenId, !openId.isEmpty { if let openId = userOpenId, !openId.isEmpty {
do { do {
let records = try await searchRecords( let records = try await searchRecords(
config: config, config: config,
accessToken: accessToken, accessToken: accessToken,
fieldNames: fieldNames,
assigneeField: config.fieldMappings.assigneeField, assigneeField: config.fieldMappings.assigneeField,
openId: openId openId: openId
) )
@ -86,7 +83,6 @@ final class FeishuService {
let records = try await listAllRecords( let records = try await listAllRecords(
config: config, config: config,
accessToken: accessToken, accessToken: accessToken,
fieldNames: fieldNames,
filter: filterStr filter: filterStr
) )
if !records.isEmpty { if !records.isEmpty {
@ -98,31 +94,20 @@ final class FeishuService {
BuggerLog.debug("FeishuService: tier 2 failed (\(error.localizedDescription)), falling back") 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)") BuggerLog.debug("FeishuService: tier 3 (unfiltered list)")
return try await listAllRecords( return try await listAllRecords(
config: config, config: config,
accessToken: accessToken, accessToken: accessToken,
fieldNames: fieldNames,
filter: nil 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) // MARK: - List endpoint (GET /records)
private func listAllRecords( private func listAllRecords(
config: AppConfig, config: AppConfig,
accessToken: String, accessToken: String,
fieldNames: [String],
filter: String? filter: String?
) async throws -> [RecordItem] { ) async throws -> [RecordItem] {
var allRecords: [RecordItem] = [] var allRecords: [RecordItem] = []
@ -140,8 +125,7 @@ final class FeishuService {
tableId: config.tableId, tableId: config.tableId,
pageToken: pageToken, pageToken: pageToken,
accessToken: accessToken, accessToken: accessToken,
filter: filter, filter: filter
fieldNames: fieldNames
) )
allRecords.append(contentsOf: page.items) allRecords.append(contentsOf: page.items)
pageToken = page.hasMore ? page.pageToken : nil pageToken = page.hasMore ? page.pageToken : nil
@ -156,8 +140,7 @@ final class FeishuService {
pageToken: String?, pageToken: String?,
pageSize: Int = 500, pageSize: Int = 500,
accessToken: String, accessToken: String,
filter: String? = nil, filter: String? = nil
fieldNames: [String]? = nil
) async throws -> RecordListData { ) async throws -> RecordListData {
guard !appToken.isEmpty, !tableId.isEmpty else { guard !appToken.isEmpty, !tableId.isEmpty else {
throw FeishuError.invalidConfiguration("App token and table ID must not be empty.") throw FeishuError.invalidConfiguration("App token and table ID must not be empty.")
@ -174,10 +157,6 @@ final class FeishuService {
if let filter, !filter.isEmpty { if let filter, !filter.isEmpty {
queryItems.append(URLQueryItem(name: "filter", value: filter)) 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 components.queryItems = queryItems
guard let url = components.url else { guard let url = components.url else {
@ -221,7 +200,6 @@ final class FeishuService {
private func searchRecords( private func searchRecords(
config: AppConfig, config: AppConfig,
accessToken: String, accessToken: String,
fieldNames: [String],
assigneeField: String, assigneeField: String,
openId: String openId: String
) async throws -> [RecordItem] { ) async throws -> [RecordItem] {
@ -240,7 +218,6 @@ final class FeishuService {
tableId: config.tableId, tableId: config.tableId,
pageToken: pageToken, pageToken: pageToken,
accessToken: accessToken, accessToken: accessToken,
fieldNames: fieldNames,
assigneeField: assigneeField, assigneeField: assigneeField,
openId: openId openId: openId
) )
@ -256,7 +233,6 @@ final class FeishuService {
tableId: String, tableId: String,
pageToken: String?, pageToken: String?,
accessToken: String, accessToken: String,
fieldNames: [String],
assigneeField: String, assigneeField: String,
openId: String openId: String
) async throws -> RecordListData { ) async throws -> RecordListData {
@ -285,9 +261,6 @@ final class FeishuService {
if let pageToken, !pageToken.isEmpty { if let pageToken, !pageToken.isEmpty {
body["page_token"] = pageToken body["page_token"] = pageToken
} }
if !fieldNames.isEmpty {
body["field_names"] = fieldNames
}
var request = URLRequest(url: url) var request = URLRequest(url: url)
request.httpMethod = "POST" request.httpMethod = "POST"