@@ -11,8 +11,10 @@ import (
1111 "os"
1212 "strconv"
1313 "strings"
14+ "time"
1415
1516 u "github.com/jolav/codetabs/_utils"
17+ "github.com/jolav/codetabs/store"
1618)
1719
1820const (
@@ -84,6 +86,7 @@ func (l *loc) Router(w http.ResponseWriter, r *http.Request) {
8486 l .doLocUploadRequest (w , r )
8587 return
8688 }
89+
8790 r .ParseForm ()
8891 l .branch = r .Form .Get ("branch" )
8992 if r .Form .Get ("ignored" ) != "" {
@@ -134,6 +137,7 @@ func (l *loc) doLocRepoRequest(w http.ResponseWriter, r *http.Request) {
134137 total2.Lines += v.Lines
135138 }
136139 l.languagesOUT = append(l.languagesOUT, total2)
140+ l.storeData()
137141 u.SendJSONToClient(w, l.languagesOUT, 200)
138142 return
139143 */
@@ -218,7 +222,12 @@ func (l *loc) doLocRepoRequest(w http.ResponseWriter, r *http.Request) {
218222 total .Lines += v .Lines
219223 }
220224 l .languagesOUT = append (l .languagesOUT , total )
221-
225+ if l .branch == "" { // cant call gitlab with master
226+ l .branch = "master"
227+ }
228+ if len (l .ignored ) == 0 && l .branch == "master" {
229+ l .storeData ()
230+ }
222231 u .SendJSONToClient (w , l .languagesOUT , 200 )
223232 u .GenericCommand (destroyTemporalDir )
224233}
@@ -317,11 +326,29 @@ func (l *loc) doLocUploadRequest(w http.ResponseWriter, r *http.Request) {
317326 total .Lines += v .Lines
318327 }
319328 l .languagesOUT = append (l .languagesOUT , total )
320-
329+ //l.storeData()
321330 u .SendJSONToClient (w , l .languagesOUT , 200 )
322331 u .GenericCommand (destroyTemporalDir )
323332}
324333
334+ func (l * loc ) storeData () {
335+ d := store .NewDataLoc ()
336+
337+ dataJSON , err := json .Marshal (l .languagesOUT )
338+ if err != nil {
339+ log .Printf ("ERROR Marshaling %s\n " , err )
340+ d .Data = string (`{}` )
341+ } else {
342+ d .Data = string (dataJSON )
343+ }
344+ d .Date = time .Now ().Format ("2006-01-02 15:04:05.000" )
345+ d .Repo = l .source + "/" + l .repo
346+ d .Source = l .source
347+ //u.PrettyPrintStruct(d)
348+ go d .SaveDataLoc ()
349+ //go store.SaveDataLoc(d)
350+ }
351+
325352func NewLoc (test bool ) loc {
326353 l := loc {
327354 order : "0" ,
0 commit comments