代码拉取完成,页面将自动刷新
同步操作将从 deng-dev/fileboy 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
// Copyright (c) 2018-2020 Author dengsgo<dengsgo@yoytang.com> [https://github.com/dengsgo/fileboy]
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
package main
import (
"bytes"
"encoding/json"
"net/http"
"strings"
"time"
)
type postParams struct {
ProjectFolder string `json:"project_folder"`
File string `json:"file"`
Changed int64 `json:"changed"`
Ext string `json:"ext"`
Event string `json:"event"`
}
type NetNotifier struct {
CallUrl string
CanPost bool
}
func newNetNotifier(callUrl string) *NetNotifier {
callPost := true
if strings.TrimSpace(callUrl) == "" {
callPost = false
}
return &NetNotifier{
CallUrl: callUrl,
CanPost: callPost,
}
}
func (n *NetNotifier) Put(cf *changedFile) {
if !n.CanPost {
logWarn("notifier call url ignore. ", n.CallUrl)
return
}
n.dispatch(&postParams{
ProjectFolder: projectFolder,
File: cf.Name,
Changed: cf.Changed,
Ext: cf.Ext,
Event: cf.Event,
})
}
func (n *NetNotifier) dispatch(params *postParams) {
b, err := json.Marshal(params)
if err != nil {
logError("json.Marshal n.params. ", err)
return
}
client := &http.Client{
Timeout: time.Second * 15,
}
req, err := http.NewRequest("POST", n.CallUrl, bytes.NewBuffer(b))
if err != nil {
logError("http.NewRequest. ", err)
return
}
req.Header.Set("Content-Type", "application/json;charset=UTF-8")
req.Header.Set("User-Agent", "FileBoy Net Notifier v1.16")
resp, err := client.Do(req)
if err != nil {
logError("notifier call failed. err:", err)
return
}
defer func() {
if resp != nil && resp.Body != nil {
_ = resp.Body.Close()
}
}()
if resp.StatusCode >= 300 {
// todo retry???
}
logInfo("notifier done .")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。