refactor: 移除飞书 API 的 field_names 参数及 configFieldNames 方法
This commit is contained in:
parent
a0b1fb8aa3
commit
7a2508a449
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue