Skip to content

Commit 39d60cb

Browse files
authored
feat: add slides replace-pages and xml-get shortcuts (#1585)
* feat: add slides replace-pages shortcut * feat: add slides xml get shortcut * fix: stop advertising slides screenshot scope * feat: expose slides presentation url
1 parent d9330b7 commit 39d60cb

15 files changed

Lines changed: 1241 additions & 29 deletions

shortcuts/slides/shortcuts.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ func Shortcuts() []common.Shortcut {
1111
SlidesCreate,
1212
SlidesMediaUpload,
1313
SlidesReplaceSlide,
14+
SlidesReplacePages,
1415
SlidesScreenshot,
16+
SlidesXMLGet,
1517
}
1618
}

shortcuts/slides/slides_create.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,11 @@ var SlidesCreate = common.Shortcut{
204204
}
205205
}
206206

207-
// Build the presentation URL locally from the token. The brand-standard
208-
// host transparently redirects to the tenant domain (same fallback used by
209-
// drive +upload / wiki +node-create). This avoids the prior best-effort
210-
// drive metas/batch_query call, which needed an extra drive scope and 403'd
211-
// for users who only authorized slides scopes — without ever blocking an
212-
// otherwise-successful creation.
213-
if url := common.BuildResourceURL(runtime.Config.Brand, "slides", presentationID); url != "" {
207+
// Prefer the URL returned by presentation.create. Fall back to a local
208+
// brand-standard URL only when the API omits it.
209+
if url := common.GetString(data, "url"); url != "" {
210+
result["url"] = url
211+
} else if url := common.BuildResourceURL(runtime.Config.Brand, "slides", presentationID); url != "" {
214212
result["url"] = url
215213
}
216214

shortcuts/slides/slides_create_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func TestSlidesCreateBasic(t *testing.T) {
3434
"data": map[string]interface{}{
3535
"xml_presentation_id": "pres_abc123",
3636
"revision_id": 1,
37+
"url": "https://tenant.example.com/slides/pres_abc123",
3738
},
3839
},
3940
})
@@ -54,10 +55,8 @@ func TestSlidesCreateBasic(t *testing.T) {
5455
if data["title"] != "项目汇报" {
5556
t.Fatalf("title = %v, want 项目汇报", data["title"])
5657
}
57-
// URL is built locally from the token (brand-standard host), not fetched from
58-
// drive metas, so it is deterministic and needs no drive scope.
59-
if data["url"] != "https://www.feishu.cn/slides/pres_abc123" {
60-
t.Fatalf("url = %v, want https://www.feishu.cn/slides/pres_abc123", data["url"])
58+
if data["url"] != "https://tenant.example.com/slides/pres_abc123" {
59+
t.Fatalf("url = %v, want https://tenant.example.com/slides/pres_abc123", data["url"])
6160
}
6261
if _, ok := data["permission_grant"]; ok {
6362
t.Fatalf("did not expect permission_grant in user mode")
@@ -647,12 +646,12 @@ func TestSlidesCreateWithoutSlidesUnchanged(t *testing.T) {
647646
}
648647
}
649648

650-
// TestSlidesCreateURLBuiltLocally verifies the presentation URL is constructed
651-
// locally from the token — no drive metas/batch_query call is made, so creation
652-
// works for users who only authorized slides scopes. The httpmock registry has no
653-
// batch_query stub registered; if the shortcut tried to call it, the request would
654-
// fail the test (unregistered stub), proving the URL is built without a drive call.
655-
func TestSlidesCreateURLBuiltLocally(t *testing.T) {
649+
// TestSlidesCreateURLFallsBackToLocalBuild verifies the presentation URL is
650+
// constructed locally from the token when presentation.create omits url — no
651+
// drive metas/batch_query call is made, so creation works for users who only
652+
// authorized slides scopes. The httpmock registry has no batch_query stub
653+
// registered; if the shortcut tried to call it, the request would fail the test.
654+
func TestSlidesCreateURLFallsBackToLocalBuild(t *testing.T) {
656655
t.Parallel()
657656

658657
f, stdout, _, reg := cmdutil.TestFactory(t, slidesTestConfig(t, ""))
@@ -665,6 +664,7 @@ func TestSlidesCreateURLBuiltLocally(t *testing.T) {
665664
"data": map[string]interface{}{
666665
"xml_presentation_id": "pres_local_url",
667666
"revision_id": 1,
667+
"url": "",
668668
},
669669
},
670670
})

0 commit comments

Comments
 (0)