mirror of
https://github.com/JustKato/drive-health.git
synced 2026-04-30 01:42:29 +03:00
Started moving to a sqlite3 implementation
This commit is contained in:
@@ -2,6 +2,7 @@ package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"tea.chunkbyte.com/kato/drive-health/lib/hardware"
|
||||
@@ -9,18 +10,22 @@ import (
|
||||
)
|
||||
|
||||
func setupApi(r *gin.Engine) {
|
||||
api := r.Group("/v1/api")
|
||||
api := r.Group("/api/v1")
|
||||
|
||||
api.GET("/disks", func(ctx *gin.Context) {
|
||||
|
||||
olderThan := time.Now().Add(time.Minute * time.Duration(10) * -1)
|
||||
newerThan := time.Now()
|
||||
|
||||
// Fetch the disk list
|
||||
disks, err := hardware.GetSystemHardDrives()
|
||||
disks, err := hardware.GetSystemHardDrives(svc.GetDatabaseRef(), &olderThan, &newerThan)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
}
|
||||
|
||||
if ctx.Request.URL.Query().Get("temp") != "" {
|
||||
for _, d := range disks {
|
||||
d.GetTemperature(true)
|
||||
d.GetTemperature()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +35,4 @@ func setupApi(r *gin.Engine) {
|
||||
})
|
||||
})
|
||||
|
||||
api.GET("/snapshots", func(ctx *gin.Context) {
|
||||
snapshots := svc.GetHardwareSnapshot()
|
||||
|
||||
ctx.JSON(http.StatusOK, snapshots)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"tea.chunkbyte.com/kato/drive-health/lib/hardware"
|
||||
"tea.chunkbyte.com/kato/drive-health/lib/svc"
|
||||
)
|
||||
|
||||
func setupFrontend(r *gin.Engine) {
|
||||
@@ -13,14 +15,16 @@ func setupFrontend(r *gin.Engine) {
|
||||
|
||||
// Set up a route for the root URL
|
||||
r.GET("/", func(c *gin.Context) {
|
||||
olderThan := time.Now().Add(time.Minute * time.Duration(10) * -1)
|
||||
newerThan := time.Now()
|
||||
|
||||
hardDrives, err := hardware.GetSystemHardDrives()
|
||||
hardDrives, err := hardware.GetSystemHardDrives(svc.GetDatabaseRef(), &olderThan, &newerThan)
|
||||
if err != nil {
|
||||
c.AbortWithStatus(500)
|
||||
}
|
||||
|
||||
for _, hdd := range hardDrives {
|
||||
hdd.GetTemperature(true)
|
||||
hdd.GetTemperature()
|
||||
}
|
||||
|
||||
// Render the HTML template
|
||||
|
||||
Reference in New Issue
Block a user