From fa7e4ffede06789da6ba0a7ef57b8f8eb5d7feed Mon Sep 17 00:00:00 2001 From: xiongyuanwen-byted Date: Fri, 3 Jul 2026 11:14:21 +0800 Subject: [PATCH] feat(sheets): accept local_office_ token prefix for image parent_type The synthetic token prefix for imported office spreadsheets is being renamed from fake_office_ to local_office_. Accept either prefix when mapping a spreadsheet token to the drive media parent_type so image uploads keep working across the rename (main package and backward compat copy). --- .../backward/lark_sheets_float_images.go | 22 ++++++++++++++----- shortcuts/sheets/helpers.go | 17 ++++++++++---- .../sheets/sheet_media_parent_type_test.go | 16 +++++++++----- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/shortcuts/sheets/backward/lark_sheets_float_images.go b/shortcuts/sheets/backward/lark_sheets_float_images.go index a117bbc24..689b8ff67 100644 --- a/shortcuts/sheets/backward/lark_sheets_float_images.go +++ b/shortcuts/sheets/backward/lark_sheets_float_images.go @@ -17,20 +17,30 @@ import ( // Drive media parent_type values for uploading an image into a spreadsheet. // Native spreadsheets use "sheet_image"; imported "office" spreadsheets carry a -// synthetic token prefixed with "fake_office_" and the backend requires -// "office_sheet_file" instead. +// synthetic token prefixed with "fake_office_" (being renamed to +// "local_office_") and the backend requires "office_sheet_file" instead. const ( sheetImageParentType = "sheet_image" officeSheetFileParentType = "office_sheet_file" fakeOfficeTokenPrefix = "fake_office_" + localOfficeTokenPrefix = "local_office_" ) +// officeTokenPrefixes are the synthetic token prefixes an imported "office" +// spreadsheet may carry. The prefix is being renamed from "fake_office_" to +// "local_office_"; accept either so image uploads keep working across the +// rename. +var officeTokenPrefixes = []string{fakeOfficeTokenPrefix, localOfficeTokenPrefix} + // sheetMediaParentType returns the drive media parent_type to use when -// uploading an image whose parent_node is spreadsheetToken, mapping the -// "fake_office_" imported-spreadsheet token prefix to "office_sheet_file". +// uploading an image whose parent_node is spreadsheetToken, mapping either the +// "fake_office_" or "local_office_" imported-spreadsheet token prefix to +// "office_sheet_file". func sheetMediaParentType(spreadsheetToken string) string { - if strings.HasPrefix(spreadsheetToken, fakeOfficeTokenPrefix) { - return officeSheetFileParentType + for _, prefix := range officeTokenPrefixes { + if strings.HasPrefix(spreadsheetToken, prefix) { + return officeSheetFileParentType + } } return sheetImageParentType } diff --git a/shortcuts/sheets/helpers.go b/shortcuts/sheets/helpers.go index 5c2545c63..38a0bd9e0 100644 --- a/shortcuts/sheets/helpers.go +++ b/shortcuts/sheets/helpers.go @@ -52,21 +52,30 @@ func sheetsInputStatError(flag string, err error) error { // Drive media parent_type values for uploading an image into a spreadsheet. // Native spreadsheets use "sheet_image"; imported "office" spreadsheets carry a -// synthetic token prefixed with "fake_office_" and the backend requires -// "office_sheet_file" instead. +// synthetic token prefixed with "fake_office_" (being renamed to +// "local_office_") and the backend requires "office_sheet_file" instead. const ( sheetImageParentType = "sheet_image" officeSheetFileParentType = "office_sheet_file" fakeOfficeTokenPrefix = "fake_office_" + localOfficeTokenPrefix = "local_office_" ) +// officeTokenPrefixes are the synthetic token prefixes an imported "office" +// spreadsheet may carry. The prefix is being renamed from "fake_office_" to +// "local_office_"; accept either so image uploads keep working across the +// rename. +var officeTokenPrefixes = []string{fakeOfficeTokenPrefix, localOfficeTokenPrefix} + // sheetMediaParentType returns the drive media parent_type to use when // uploading an image whose parent_node is spreadsheetToken. It is the single // place that maps a spreadsheet token to its parent_type so every image-upload // entry point (and its dry-run preview) stays consistent. func sheetMediaParentType(spreadsheetToken string) string { - if strings.HasPrefix(spreadsheetToken, fakeOfficeTokenPrefix) { - return officeSheetFileParentType + for _, prefix := range officeTokenPrefixes { + if strings.HasPrefix(spreadsheetToken, prefix) { + return officeSheetFileParentType + } } return sheetImageParentType } diff --git a/shortcuts/sheets/sheet_media_parent_type_test.go b/shortcuts/sheets/sheet_media_parent_type_test.go index ebf03deca..55a7667ee 100644 --- a/shortcuts/sheets/sheet_media_parent_type_test.go +++ b/shortcuts/sheets/sheet_media_parent_type_test.go @@ -25,8 +25,8 @@ import ( // TestSheetMediaParentType pins the token→parent_type mapping that every // sheets image-upload entry point funnels through. Native spreadsheet tokens -// use "sheet_image"; imported "office" spreadsheets carry a "fake_office_" -// synthetic token and must upload with "office_sheet_file". +// use "sheet_image"; imported "office" spreadsheets carry a "fake_office_" or +// "local_office_" synthetic token and must upload with "office_sheet_file". func TestSheetMediaParentType(t *testing.T) { t.Parallel() cases := []struct { @@ -36,9 +36,12 @@ func TestSheetMediaParentType(t *testing.T) { }{ {"native spreadsheet token", "shtcnABC123", sheetImageParentType}, {"empty token", "", sheetImageParentType}, - {"office imported token", "fake_office_abc123", officeSheetFileParentType}, - {"office token, only the prefix", fakeOfficeTokenPrefix, officeSheetFileParentType}, - {"prefix mid-string is not matched", "shtfake_office_abc", sheetImageParentType}, + {"fake_office imported token", "fake_office_abc123", officeSheetFileParentType}, + {"fake_office token, only the prefix", fakeOfficeTokenPrefix, officeSheetFileParentType}, + {"local_office imported token", "local_office_abc123", officeSheetFileParentType}, + {"local_office token, only the prefix", localOfficeTokenPrefix, officeSheetFileParentType}, + {"fake_office prefix mid-string is not matched", "shtfake_office_abc", sheetImageParentType}, + {"local_office prefix mid-string is not matched", "shtlocal_office_abc", sheetImageParentType}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { @@ -62,7 +65,8 @@ func TestUploadSheetImage_ParentType(t *testing.T) { wantParentType string }{ {"native spreadsheet", "shtcnTOK123", sheetImageParentType}, - {"office imported spreadsheet", "fake_office_abc123", officeSheetFileParentType}, + {"fake_office imported spreadsheet", "fake_office_abc123", officeSheetFileParentType}, + {"local_office imported spreadsheet", "local_office_abc123", officeSheetFileParentType}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) {