# HG changeset patch # User anatofuz # Date 1607075519 -32400 # Node ID 0b9932242273d51229ea72dca0baac59fc5440f4 # Parent af840bc25791c81faeb7915a05b56bd3cd65dede ... diff -r af840bc25791 -r 0b9932242273 client/client.go --- 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) diff -r af840bc25791 -r 0b9932242273 client/page.go --- 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 } diff -r af840bc25791 -r 0b9932242273 cmd_edit.go --- 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) }