Mercurial > hg > Members > anatofuz > growsync
changeset 6:0b9932242273
...
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 04 Dec 2020 18:51:59 +0900 |
parents | af840bc25791 |
children | 6da31576fa84 |
files | client/client.go client/page.go cmd_edit.go |
diffstat | 3 files changed, 28 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/client/client.go Fri Dec 04 18:27:09 2020 +0900 +++ b/client/client.go Fri Dec 04 18:51:59 2020 +0900 @@ -76,7 +76,7 @@ u.Path = path.Join(u.Path, uri) - fmt.Printf("[info] method %s, url %s body %s\n", method, u.String(), body) + fmt.Printf("[info] method %s, url %s \n", method, u.String()) req, err := http.NewRequest(method, u.String(), body) req = req.WithContext(ctx)
--- a/client/page.go Fri Dec 04 18:27:09 2020 +0900 +++ b/client/page.go Fri Dec 04 18:51:59 2020 +0900 @@ -128,7 +128,7 @@ return &pagesGet.Page, nil } -const UPDATE_ENDPOINT string = "/_api/pages.update" +const UpdateEndpoint string = "/_api/pages.update" func (p *PagesService) Update(ctx context.Context, pageID, revisionID, body string) (*Page, error) { params := url.Values{} @@ -137,7 +137,7 @@ params.Add("revision_id", revisionID) params.Add("body", body) - res, err := p.client.newRequest(ctx, http.MethodPost, UPDATE_ENDPOINT, ¶ms) + res, err := p.client.newRequest(ctx, http.MethodPost, UpdateEndpoint, ¶ms) if err != nil { return nil, err }
--- a/cmd_edit.go Fri Dec 04 18:27:09 2020 +0900 +++ b/cmd_edit.go Fri Dec 04 18:51:59 2020 +0900 @@ -5,6 +5,7 @@ "flag" "fmt" "io" + "os" "path/filepath" "time" ) @@ -39,6 +40,18 @@ localFilePATH := filepath.Join(config.LocalRoot, growiPATH+".md") + var beforeTime time.Time + + alreadyExistsFile := existsFile(localFilePATH) + + if alreadyExistsFile { + info, err := os.Stat(localFilePATH) + if err != nil { + return err + } + beforeTime = info.ModTime() + } + client, err := NewGrowiClient(config.URL, config.TOKEN) if err != nil { return err @@ -49,6 +62,18 @@ return fmt.Errorf("failed edit mardkwodn file %+v", err) } + if alreadyExistsFile { + info, err := os.Stat(localFilePATH) + if err != nil { + return err + } + + if info.ModTime() == beforeTime { + fmt.Printf("[info] %s not update\n", growiPATH) + return nil + } + } + return client.UpdatePage(growiPATH, localFilePATH) }