From 3f6656d97e52dab0cf19585508e2d36393c8b784 Mon Sep 17 00:00:00 2001 From: Rogee Date: Wed, 4 Sep 2024 13:25:53 +0800 Subject: [PATCH] fix: publish --- .vscode/launch.json | 7 ++++--- internal/cmd_publish.go | 11 ++++++++--- pkg/memos/memos.go | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 15793d5..81338d3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,8 @@ "mode": "auto", "program": "${workspaceFolder}/main.go", "args": [ - "export", + "publish", + // "export", // https://t.me/yunpanshare/26640 // "--alias", "yunpanshare", // https://t.me/Aliyun_4K_Movies/26640 @@ -37,8 +38,8 @@ // https://t.me/c/2023304596/2277 // "--channel", "2023304596", // https://t.me/cgblz/25220 - "--alias", "cgblz", - "--history", + // "--alias", "cgblz", + // "--history", ] } ] diff --git a/internal/cmd_publish.go b/internal/cmd_publish.go index 75f191d..73587de 100644 --- a/internal/cmd_publish.go +++ b/internal/cmd_publish.go @@ -78,14 +78,19 @@ func publish(_ context.Context, msg publishMsg) error { var file string if media.Photo != nil { - res.Type = "image/jpg" - res.Name = *media.Photo + res.Type = "image/jpeg" + res.Filename = *media.Photo file = fmt.Sprintf("%d/%s", data.ChannelID, *media.Photo) } else if media.Document != nil { res.Type = media.Document.MimeType - res.Name = media.Document.Filename + res.Filename = media.Document.Filename file = fmt.Sprintf("%d/%d%s", data.ChannelID, media.AssetID, media.Document.Ext) + } else if media.WebPage != nil { + data.Content += fmt.Sprintf("\n\n[%s](%s)", media.WebPage.Title, media.WebPage.URL) + } else { + return errors.New("unknown media type") } + filepath := filepath.Join(config.C.Output, file) b, err := os.ReadFile(filepath) if err != nil { diff --git a/pkg/memos/memos.go b/pkg/memos/memos.go index f785016..f08b86d 100644 --- a/pkg/memos/memos.go +++ b/pkg/memos/memos.go @@ -43,7 +43,7 @@ func Post(pd PostData) error { resp, err := client.R(). SetSuccessResult(&createMemoResp). SetBodyJsonMarshal(Memo{ - Content: fmt.Sprintf("#%s #%d \n%s", pd.ChannelTitle, pd.ChannelID, pd.Content), + Content: fmt.Sprintf("#%s #%d \n\n%s", pd.ChannelTitle, pd.ChannelID, pd.Content), Visibility: "PUBLIC", }). Post("api/v1/memos") @@ -85,5 +85,5 @@ func Upload(res Resource) (Resource, error) { return Resource{}, errors.New("post memo failed, body: " + resp.String()) } - return res, nil + return result, nil }