-
Notifications
You must be signed in to change notification settings - Fork 4
Add hash to redirected page #9
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: gh-pages
Are you sure you want to change the base?
Conversation
(当初 GitHub Releases API にハッシュ値が含まれてるかと淡い期待を抱きましたが、流石にそれはなかったので仕方なく都度 fetch して調べるようにしました) |
vital.vim で vim-jp/redirects に fetch してるスクリプトがありますが、http やオレオレ証明書だと 試したスクリプト
結果
|
あとソースコード的なレビュー追加しておきます。 |
@@ -77,10 +84,14 @@ func fetchRedirect(d redirect) (*github.Asset, error) { | |||
return nil, nil | |||
} | |||
|
|||
func updateRedirect(d redirect, a *github.Asset) error { | |||
func updateRedirect(d redirect, a *github.Asset, bin io.ReadCloser) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
io.ReadCloser
を渡すのではなく、この関数のなかでDLしたほうが良い。
Asset の中身だけを見て Redirect を更新するかどうかを決定し、更新時にのみ本体をDLする
という理想形に近づけておくため。
}) | ||
if err != nil { | ||
return nil | ||
} | ||
return nil | ||
} | ||
|
||
func calcSha1Hash(r io.ReadCloser) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この用途なら引数は io.Reader
で十分。
ただし複数の hash アルゴリズムに渡すことを考慮するなら単に []byte
で良い。
ガチなら io.TeeReader
を挟むのだが…
if err != nil { | ||
log.Printf("update failed for %s: %s", d.Path, err) | ||
return | ||
} | ||
} | ||
|
||
func fetchReleaseBinary(a *github.Asset) (io.ReadCloser, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
関数名は downloadAsset(*github.Asset)
もしくは fetchURL(string)
のが良いだろう。
if err != nil { | ||
log.Printf("update failed for %s: %s", d.Path, err) | ||
return | ||
} | ||
} | ||
|
||
func fetchReleaseBinary(a *github.Asset) (io.ReadCloser, error) { | ||
resp, err := http.DefaultClient.Get(a.DownloadURL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
特にクライアントをいじる気がないなら http.Get()
を使う。
Fixes #8
#8 を実装してみました。
以下3点について相談させてください。
_data/redirects.yml
にgithub_release
が書かれてない過去や安定版のリリースについては手動で調べて追記する必要があります。ちなみにスクリプトを実行 +
jekyll serve
後はこんな感じになります。スクリーンショット
実行後の差分