2024-01-17 17:06:26 +00:00
|
|
|
/*
|
|
|
|
|
2024-03-19 20:11:43 +00:00
|
|
|
* tracker | MatterLinux Package Tracker
|
|
|
|
* MatterLinux 2023-2024 (https://matterlinux.xyz)
|
2024-01-17 17:06:26 +00:00
|
|
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2024-03-19 20:11:43 +00:00
|
|
|
*/
|
2024-01-17 17:06:26 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-03-19 20:11:43 +00:00
|
|
|
"log"
|
2024-01-17 17:06:26 +00:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.matterlinux.xyz/matter/tracker/lib"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"github.com/gofiber/template/html/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var lastupdate time.Time
|
|
|
|
var updatetick = time.NewTicker(time.Hour)
|
|
|
|
var stopchan = make(chan struct{})
|
|
|
|
|
|
|
|
func UpdateLoop() {
|
|
|
|
UpdatePackages()
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <- updatetick.C:
|
|
|
|
UpdatePackages()
|
|
|
|
case <- stopchan:
|
|
|
|
updatetick.Stop()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func UpdatePackages() {
|
|
|
|
lib.LoadAllPkgs()
|
|
|
|
lastupdate = time.Now()
|
|
|
|
}
|
|
|
|
|
|
|
|
func GETIndex(c *fiber.Ctx) error {
|
2024-01-18 17:25:33 +00:00
|
|
|
repo := c.Query("r")
|
|
|
|
name := c.Query("n")
|
|
|
|
exact := c.Query("e")
|
2024-03-21 18:52:14 +00:00
|
|
|
isjson := c.Query("j")
|
2024-01-18 17:25:33 +00:00
|
|
|
|
|
|
|
if repo == "" && name == "" {
|
2024-03-21 18:52:14 +00:00
|
|
|
if isjson == "1" {
|
|
|
|
return c.JSON(lib.Packages)
|
|
|
|
}
|
2024-01-18 17:25:33 +00:00
|
|
|
return c.Render("index", fiber.Map{
|
|
|
|
"last": lib.GetTimePassed(lastupdate),
|
|
|
|
"repos": lib.Repos,
|
|
|
|
"pkgs": lib.Packages,
|
|
|
|
})
|
2024-01-17 17:06:26 +00:00
|
|
|
}
|
|
|
|
|
2024-01-18 17:25:33 +00:00
|
|
|
name = lib.CleanString(name)
|
2024-01-17 17:06:26 +00:00
|
|
|
var res []lib.Package
|
|
|
|
|
|
|
|
for _, p := range lib.Packages {
|
2024-01-18 17:25:33 +00:00
|
|
|
if(repo != "all" && p.Repo != repo){
|
2024-01-17 17:06:26 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-01-18 17:25:33 +00:00
|
|
|
if(exact == ""){
|
|
|
|
if(strings.Contains(p.Name, name)){
|
|
|
|
res = append(res, p)
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
if (p.Name == name) {
|
|
|
|
res = append(res, p)
|
|
|
|
}
|
2024-01-17 17:06:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-21 18:52:14 +00:00
|
|
|
if isjson == "1" {
|
|
|
|
return c.JSON(res)
|
|
|
|
}
|
|
|
|
|
2024-01-17 17:06:26 +00:00
|
|
|
return c.Render("index", fiber.Map{
|
2024-01-18 17:25:33 +00:00
|
|
|
"search": name,
|
2024-01-17 17:06:26 +00:00
|
|
|
"last": lib.GetTimePassed(lastupdate),
|
|
|
|
"repos": lib.Repos,
|
|
|
|
"pkgs": res,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func main(){
|
2024-03-19 20:11:43 +00:00
|
|
|
log.SetFlags(log.Ltime | log.Lshortfile)
|
|
|
|
|
2024-01-17 17:06:26 +00:00
|
|
|
engine := html.New("./templates", ".html")
|
|
|
|
app := fiber.New(fiber.Config{
|
|
|
|
DisableStartupMessage: true,
|
|
|
|
Views: engine,
|
|
|
|
})
|
|
|
|
|
|
|
|
app.Static("/", "./public")
|
|
|
|
app.Get("/", GETIndex)
|
|
|
|
|
|
|
|
app.Get("*", func(c *fiber.Ctx) error {
|
|
|
|
return lib.RenderError(c, 404)
|
|
|
|
})
|
|
|
|
|
|
|
|
go UpdateLoop()
|
2024-03-19 20:11:43 +00:00
|
|
|
log.Println("Starting MatterLinux Package Tracker on port 9877")
|
2024-01-17 17:06:26 +00:00
|
|
|
err := app.Listen(":9877")
|
|
|
|
if err != nil {
|
2024-03-19 20:11:43 +00:00
|
|
|
log.Printf("Error starting server: %s", err)
|
2024-01-17 17:06:26 +00:00
|
|
|
}
|
|
|
|
close(stopchan)
|
|
|
|
}
|