mirror of
https://github.com/larksuite/cli.git
synced 2026-07-09 18:34:03 +08:00
fix: allow longer svglide manifests
This commit is contained in:
@@ -21,7 +21,7 @@ var SlidesCreateSVGlide = common.Shortcut{
|
||||
AuthTypes: []string{"user", "bot"},
|
||||
Scopes: []string{"slides:presentation:create", "slides:presentation:write_only", "docs:document.media:upload"},
|
||||
Flags: []common.Flag{
|
||||
{Name: "manifest", Desc: "SVGlide manifest JSON file; version=svglide.manifest.v1, max 10 pages", Required: true},
|
||||
{Name: "manifest", Desc: "SVGlide manifest JSON file; version=svglide.manifest.v1, max 50 pages", Required: true},
|
||||
{Name: "title", Desc: "presentation title override; defaults to manifest.title, then Untitled"},
|
||||
},
|
||||
Validate: func(ctx context.Context, runtime *common.RuntimeContext) error {
|
||||
|
||||
@@ -20,9 +20,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
svglideManifestVersion = "svglide.manifest.v1"
|
||||
svglideBundleProtocol = "svg-slides.v1"
|
||||
svglideSVGNamespace = "http://www.w3.org/2000/svg"
|
||||
svglideManifestVersion = "svglide.manifest.v1"
|
||||
svglideBundleProtocol = "svg-slides.v1"
|
||||
svglideSVGNamespace = "http://www.w3.org/2000/svg"
|
||||
maxSVGlideManifestPages = 50
|
||||
)
|
||||
|
||||
type svglideManifest struct {
|
||||
@@ -100,8 +101,8 @@ func prepareSVGlidePublishSpec(runtime *common.RuntimeContext, manifestPath stri
|
||||
if manifest.Size.Width != defaultPresentationWidth || manifest.Size.Height != defaultPresentationHeight {
|
||||
return nil, errs.NewValidationError(errs.SubtypeInvalidArgument, "--manifest size must be %dx%d", defaultPresentationWidth, defaultPresentationHeight).WithParam("--manifest")
|
||||
}
|
||||
if len(manifest.Pages) == 0 || len(manifest.Pages) > maxSlidesPerCreate {
|
||||
return nil, errs.NewValidationError(errs.SubtypeInvalidArgument, "--manifest pages must contain 1 to %d entries", maxSlidesPerCreate).WithParam("--manifest")
|
||||
if len(manifest.Pages) == 0 || len(manifest.Pages) > maxSVGlideManifestPages {
|
||||
return nil, errs.NewValidationError(errs.SubtypeInvalidArgument, "--manifest pages must contain 1 to %d entries", maxSVGlideManifestPages).WithParam("--manifest")
|
||||
}
|
||||
|
||||
baseDir := filepath.Dir(filepath.Clean(manifestPath))
|
||||
|
||||
@@ -64,6 +64,41 @@ func TestPrepareSVGlidePublishSpecReadsManifestAndPages(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrepareSVGlidePublishSpecAcceptsTwelvePageManifest(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
withSlidesTestWorkingDir(t, dir)
|
||||
mustWriteSVGlideTestFile(t, "receipts/validate_svg_deck.json", `{"totalErrors":0}`)
|
||||
mustWriteSVGlideRequiredNonValidateReceipts(t)
|
||||
|
||||
pages := make([]string, 0, 12)
|
||||
for i := 1; i <= 12; i++ {
|
||||
id := fmt.Sprintf("page-%03d", i)
|
||||
file := fmt.Sprintf("pages/%s.svg", id)
|
||||
page := fmt.Sprintf(`<svg xmlns="http://www.w3.org/2000/svg" xmlns:slide="https://slides.bytedance.com/ns" slide:role="slide" id="%s" viewBox="0 0 960 540"><rect slide:role="background" x="0" y="0" width="960" height="540" fill="rgba(255,255,255,1)"/></svg>`, id)
|
||||
mustWriteSVGlideTestFile(t, file, page)
|
||||
pages = append(pages, fmt.Sprintf(`{"id":%q,"index":%d,"file":%q,"sha256":%q}`, id, i, file, sha256Hex([]byte(page))))
|
||||
}
|
||||
mustWriteSVGlideTestFile(t, "manifest.json", withSVGlideRequiredReceipts(fmt.Sprintf(`{
|
||||
"version": "svglide.manifest.v1",
|
||||
"protocol": "svg-slides.v1",
|
||||
"title": "Twelve Page Deck",
|
||||
"size": {"width": 960, "height": 540},
|
||||
"publish_ready": true,
|
||||
"published": false,
|
||||
"pages": [%s],
|
||||
"receipts": {"validate_svg_deck": "receipts/validate_svg_deck.json"}
|
||||
}`, strings.Join(pages, ","))))
|
||||
|
||||
runtime, _ := newSVGlideTestRuntime(t)
|
||||
spec, err := prepareSVGlidePublishSpec(runtime, "manifest.json", "")
|
||||
if err != nil {
|
||||
t.Fatalf("prepareSVGlidePublishSpec() error = %v", err)
|
||||
}
|
||||
if len(spec.Pages) != 12 {
|
||||
t.Fatalf("Pages len = %d, want 12", len(spec.Pages))
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrepareSVGlidePublishSpecTitleOverride(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
withSlidesTestWorkingDir(t, dir)
|
||||
@@ -116,7 +151,7 @@ func TestPrepareSVGlidePublishSpecValidationErrors(t *testing.T) {
|
||||
name: "no pages",
|
||||
manifest: `{"version":"svglide.manifest.v1","protocol":"svg-slides.v1","title":"x","size":{"width":960,"height":540},"publish_ready":true,"published":false,"receipts":{"validate_svg_deck":"receipts/validate_svg_deck.json"},"pages":[]}`,
|
||||
pageFiles: map[string]string{"receipts/validate_svg_deck.json": `{"totalErrors":0}`},
|
||||
wantMessage: "--manifest pages must contain 1 to 10 entries",
|
||||
wantMessage: "--manifest pages must contain 1 to 50 entries",
|
||||
},
|
||||
{
|
||||
name: "unsafe child path",
|
||||
|
||||
Reference in New Issue
Block a user