diff --git a/lang.go b/lang.go index 1ae44fe..71169c5 100644 --- a/lang.go +++ b/lang.go @@ -8,11 +8,13 @@ import ( func getlist (lang string) []byte { var jloc = []byte(`{ "top": "トップ", - "errfuseiurl": "URLは「http://」又は「https://」で始めます。" + "errfuseiurl": "URLは「http://」又は「https://」で始めます。", + "errfusei": "不正なエラー。" }`) var eloc = []byte(`{ "top": "Top", - "errfuseiurl": "The URL should start with \"http://\" or \"https://\"." + "errfuseiurl": "The URL should start with \"http://\" or \"https://\".", + "errfusei": "Unknown error." }`) if lang == "en" { return eloc } diff --git a/mime.go b/mime.go new file mode 100644 index 0000000..8ebb15b --- /dev/null +++ b/mime.go @@ -0,0 +1,15 @@ +package main + +func getmime () map[string]string { + return map[string]string { + "text/css": ".css", + "text/javascript": ".js", + "image/png": ".png", + "image/jpeg": ".jpg", + "image/webp": ".webp", + "image/gif": ".gif", + "font/ttf": ".ttf", + "font/woff2": ".woff2", + "image/vnd.microsoft.icon": ".ico", + } +} diff --git a/scanpage.go b/scanpage.go index c3e6a0e..51ed073 100644 --- a/scanpage.go +++ b/scanpage.go @@ -25,7 +25,7 @@ func scanpage (path string, domain string, thisdomain string) error { var video = regexp.MustCompile(`()`).ReplaceAllString(string(audio), "") var iframe = regexp.MustCompile(`()`).ReplaceAllString(string(video), "") /* 追加ダウンロード+ローカル化 */ - var ass = regexp.MustCompile(`(= 0; i-- { + if _, err := strconv.Atoi(pc[i]); err == nil { + return pc[i] + } + } + + return "" } func siteHandler (cnf Config) func (http.ResponseWriter, *http.Request) { @@ -49,7 +58,11 @@ func siteHandler (cnf Config) func (http.ResponseWriter, *http.Request) { data.Tit = getloc("top", lang) if r.Method == "POST" { err := r.ParseForm() - if err != nil { fmt.Println(err) } + if err != nil { + fmt.Println(err) + http.Redirect(w, r, "/", http.StatusSeeOther) + return + } // クッキー if r.PostForm.Get("langchange") != "" { @@ -63,16 +76,45 @@ func siteHandler (cnf Config) func (http.ResponseWriter, *http.Request) { return } + var exist []string + if r.PostForm.Get("hozonsite") != "" { - fmt.Println("sasa") url := r.PostForm.Get("hozonsite") - fmt.Println(url) // HTTPかHTTPSじゃない場合 if !checkprefix(url) { data.Err = getloc("errfuseiurl", lang) ftmpl[0] = cnf.webpath + "/view/404.html" } else { - //if r.PostForm.Get("sosin") != "" {} + eurl := stripurl(url) + exist = checkexist(eurl, cnf.datapath) + if len(exist) == 0 || r.PostForm.Get("agree") == "1" { + path := mkdirs(eurl, cnf.datapath) + getpage(url, path) + scanpage(path, eurl, cnf.datapath) + http.Redirect(w, r, cnf.domain + strings.Replace(path, cnf.datapath, "", 1), http.StatusSeeOther) + } else if len(exist) > 0 { + ftmpl[0] = cnf.webpath + "/view/check.html" + data.Url = url + var existing []Exist + e := Exist{} + for _, ex := range exist { + ti, err := strconv.ParseInt(tspath(ex), 10, 64) + if err != nil { + fmt.Println(err) + http.Redirect(w, r, "/", http.StatusSeeOther) + return + } + + t := time.Unix(ti, 0) + e.Date = t.Format("2006年01月02日 15:04:05") + e.Url = strings.Replace(ex, cnf.datapath, cnf.domain, 1) + existing = append(existing, e) + } + data.Ext = existing + } else { + data.Err = getloc("errfusei", lang) + ftmpl[0] = cnf.webpath + "/view/404.html" + } } } } @@ -118,7 +160,13 @@ func archiveHandler (cnf Config) func (http.ResponseWriter, *http.Request) { pth += "index.html" } - bdy, err := os.ReadFile(cnf.datapath + pth) + file := cnf.datapath + pth + if _, err := os.Stat(file); os.IsNotExist(err) { + http.Redirect(w, r, "/404", http.StatusSeeOther) + return + } + + bdy, err := os.ReadFile(file) if err != nil { http.Redirect(w, r, "/404", http.StatusSeeOther) return diff --git a/view/archive.html b/view/archive.html index af9e6a1..89ac6b0 100644 --- a/view/archive.html +++ b/view/archive.html @@ -13,9 +13,10 @@ position: fixed !important; left: 0 !important; top: 0 !important; - font-size: 14px !important; + font-size: 18px !important; font-family: unset !important; width: 100% !important; + text-align: left !important; } .archbody { padding-top: 74px !important; diff --git a/view/check.html b/view/check.html index 7fd9150..8beeea9 100644 --- a/view/check.html +++ b/view/check.html @@ -1,23 +1,28 @@ {{template "header" .}} - {{if eq .Lan "ja"}}既に保存されたページ:{{else}}Pages that already got archived:{{end}} - {{range .Ext}} - +
{{end}}

- {{if eq .Lan "ja"}} - このページが既に保存されているみたいです。
本当に手続きましょうか? - {{else}} + {{if eq .Lan "en"}} This page seems to have been already archived.
Do you really want to proceed? + {{else}} + このページが既に保存されているみたいです。
本当に手続きましょうか? {{end}}

- +
{{template "footer" .}}