@@ -140,9 +140,11 @@ type snapResponse struct {
140140 Snapshots []snapItem `json:"snapshots"`
141141}
142142type snapItem struct {
143- Snapshot string `json:"snapshot,omitempty"`
144- Uuid string `json:"uuid,omitempty"`
145- State string `json:"state,omitempty"`
143+ Snapshot string `json:"snapshot,omitempty"`
144+ Uuid string `json:"uuid,omitempty"`
145+ State string `json:"state,omitempty"`
146+ CreateEpoch int64
147+ CreateDate string
146148}
147149
148150type scrollResponse struct {
@@ -366,6 +368,7 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
366368 log .Println (remoteIP , "\t " , r .Method , "\t " , r .URL .Path , "\t " , request .Action , "\t " , http .StatusInternalServerError , "\t " , err .Error ())
367369 return
368370 }
371+ re := regexp .MustCompile (`^(.*)-(\d{4}\.\d{2}\.\d{2})` )
369372
370373 if ! rt .conf .Snapshot .Include {
371374 for _ , n := range snap_resp .Snapshots {
@@ -374,25 +377,46 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
374377 log .Println ("Regex error for " , n .Snapshot )
375378 }
376379 if ! matched {
380+ match := re .FindStringSubmatch (n .Snapshot )
381+ n .CreateDate = match [2 ]
382+ d , err := time .Parse ("2006.01.02" , n .CreateDate )
383+ n .CreateEpoch = d .Unix ()
384+ if err != nil {
385+ http .Error (w , err .Error (), http .StatusInternalServerError )
386+ log .Println (remoteIP , "\t " , r .Method , "\t " , r .URL .Path , "\t " , request .Action , "\t " , http .StatusInternalServerError , "\t " , err .Error ())
387+ return
388+ }
377389 snap_items = append (snap_items , n )
378390 }
379-
391+ }
392+ } else {
393+ for _ , n := range snap_resp .Snapshots {
394+ match := re .FindStringSubmatch (n .Snapshot )
395+ n .CreateDate = match [2 ]
396+ d , err := time .Parse ("2006.01.02" , n .CreateDate )
397+ n .CreateEpoch = d .Unix ()
398+ if err != nil {
399+ http .Error (w , err .Error (), http .StatusInternalServerError )
400+ log .Println (remoteIP , "\t " , r .Method , "\t " , r .URL .Path , "\t " , request .Action , "\t " , http .StatusInternalServerError , "\t " , err .Error ())
401+ return
402+ }
403+ snap_items = append (snap_items , n )
380404 }
381405 }
382- /*if request.Values.OrderType == "time" {
406+
407+ if request .Values .OrderType == "time" {
383408
384409 if request .Values .OrderDir == "asc" {
385- sort.Slice(snap_list [:], func(i, j int) bool {
386- return snap_list [i].End_epoch < snap_list [j].End_epoch
410+ sort .Slice (snap_items [:], func (i , j int ) bool {
411+ return snap_items [i ].CreateEpoch < snap_items [j ].CreateEpoch
387412 })
388413 } else {
389- sort.Slice(snap_list [:], func(i, j int) bool {
390- return snap_list [i].End_epoch > snap_list [j].End_epoch
414+ sort .Slice (snap_items [:], func (i , j int ) bool {
415+ return snap_items [i ].CreateEpoch > snap_items [j ].CreateEpoch
391416 })
392417 }
393418
394- } else */
395- if request .Values .OrderType == "name" {
419+ } else if request .Values .OrderType == "name" {
396420
397421 if request .Values .OrderDir == "asc" {
398422 sort .Slice (snap_items [:], func (i , j int ) bool {
@@ -414,20 +438,19 @@ func (rt *Router) ApiHandler(w http.ResponseWriter, r *http.Request) {
414438
415439 case "get_snapshots_sorted" :
416440 {
417- /* if request.Values.OrderType == "time" {
441+ if request .Values .OrderType == "time" {
418442
419443 if request .Values .OrderDir == "asc" {
420444 sort .Slice (rt .sl [:], func (i , j int ) bool {
421- return rt.sl[i].End_epoch < rt.sl[j].End_epoch
445+ return rt .sl [i ].CreateEpoch < rt .sl [j ].CreateEpoch
422446 })
423447 } else {
424448 sort .Slice (rt .sl [:], func (i , j int ) bool {
425- return rt.sl[i].End_epoch > rt.sl[j].End_epoch
449+ return rt .sl [i ].CreateEpoch > rt .sl [j ].CreateEpoch
426450 })
427451 }
428452
429- } else */
430- if request .Values .OrderType == "name" {
453+ } else if request .Values .OrderType == "name" {
431454
432455 if request .Values .OrderDir == "asc" {
433456 sort .Slice (rt .sl [:], func (i , j int ) bool {
0 commit comments