From 7679ecd5f67b6cb969cb2313d4d1215d1520d364 Mon Sep 17 00:00:00 2001 From: jolav Date: Tue, 14 Feb 2023 11:24:12 +0100 Subject: [PATCH] 0.8.3 stars crash fixed + log bug --- README.md | 4 ++-- _utils/stats.go | 23 ++++++++++++++++------- main.go | 2 +- stars/stars.go | 4 ++++ www/_public/templates/version.html | 2 +- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1587cb1..d87ee76 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -![Version](https://img.shields.io/badge/version-0.8.2-orange.svg) +![Version](https://img.shields.io/badge/version-0.8.3-orange.svg) ![Maintained YES](https://img.shields.io/badge/Maintained%3F-yes-green.svg) ![Ask Me Anything !](https://img.shields.io/badge/Ask%20me-anything-1abc9c.svg) # ![logo](https://github.com/jolav/codetabs/blob/master/www/_public/icons/ct/ct64r.png?raw=true) **ONLINE TOOLS ([codetabs.com](https://codetabs.com))** -**version 0.8.2** +**version 0.8.3** 1. [Count LOC (lines of code) online from github/gitlab repos or zipped uploaded folder](#count-loc-online) 2. [CORS proxy](#cors-proxy) diff --git a/_utils/stats.go b/_utils/stats.go index cc59432..6c08264 100644 --- a/_utils/stats.go +++ b/_utils/stats.go @@ -3,6 +3,7 @@ package _utils import ( + "fmt" "log" "net/http" "os" @@ -11,21 +12,29 @@ import ( ) // AddHit ... -func AddHit(w http.ResponseWriter, r *http.Request, - service, mode string, hLog *log.Logger) { +func AddHit(w http.ResponseWriter, r *http.Request, service, mode string, + hLog *log.Logger) { ip := GetIP(r) sv := strings.ToUpper(service) - host := r.Header.Get("Origin") + host := r.Header.Get("Host") if host == "" { - host = " ? " + host = r.Header.Get("Origin") + if host == "" { + host = r.Header.Get("Referer") + if host == "" { + host = "???" + } + } } - quest := r.Form.Get("quest") + + askingFor := strings.Trim(fmt.Sprint(r.URL), string(r.URL.Path)) + if mode == "production" { - hLog.Println(ip, sv, host, quest) + hLog.Println(ip, sv, host, askingFor) hitUrl := "http://localhost:3970/addHit/" + service saveHit(w, hitUrl) } else { - log.Println(ip, sv, host, quest) + log.Println(ip, sv, host, askingFor) } } diff --git a/main.go b/main.go index f64578f..54ff58f 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,7 @@ import ( "github.com/jolav/codetabs/weather" ) -var version = "0.8.2" +var version = "0.8.3" var when = "undefined" type Conf struct { diff --git a/stars/stars.go b/stars/stars.go index 4ae0869..d86e248 100644 --- a/stars/stars.go +++ b/stars/stars.go @@ -62,6 +62,10 @@ func Router(w http.ResponseWriter, r *http.Request) { s.cleanStarsStruct() r.ParseForm() data := r.Form.Get("repo") + if data == "" { + u.BadRequest(w, r) + return + } s.source = data[0:2] s.repo = data[2:len(data)] aux := strings.Split(s.repo, "/") diff --git a/www/_public/templates/version.html b/www/_public/templates/version.html index a746918..a37255e 100644 --- a/www/_public/templates/version.html +++ b/www/_public/templates/version.html @@ -2,7 +2,7 @@

API doc - (version 0.8.2) + (version 0.8.3)