feat: name change + bugfixes

This commit is contained in:
2026-10-09 22:55:02 +02:00
parent fb84e3384b
commit 95a25453df
8 changed files with 113 additions and 23 deletions
+40 -7
View File
@@ -3,11 +3,12 @@ package routes
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"kooltab-updateserver/internal/apk_util"
"kooltab-updateserver/internal/auth"
"kooltab-updateserver/internal/db"
"kooltab-updateserver/internal/models"
"kooltap-updateserver/internal/apk_util"
"kooltap-updateserver/internal/auth"
"kooltap-updateserver/internal/db"
"kooltap-updateserver/internal/models"
"net/http"
"os"
"path/filepath"
@@ -24,6 +25,8 @@ func Register(r *gin.Engine) {
api.GET("/releases", ListReleases)
}
r.GET("/download/latest", DownloadLatest)
admin := r.Group("/admin")
admin.Use(auth.AdminAuth())
{
@@ -38,9 +41,8 @@ func CheckUpdate(c *gin.Context) {
var latest models.Release
if err := db.DB.
Order("created_at desc").
First(&latest).Error; err != nil {
// The highest Android version code is the latest build, regardless of upload order
if err := latestRelease(&latest); err != nil {
c.JSON(http.StatusOK, gin.H{
"update": false,
@@ -79,6 +81,27 @@ func CheckUpdate(c *gin.Context) {
})
}
// DownloadLatest redirects to the newest APK, for installing on a new tablet from a browser
func DownloadLatest(c *gin.Context) {
var latest models.Release
if err := latestRelease(&latest); err != nil {
c.JSON(http.StatusNotFound, gin.H{
"error": "No releases yet",
})
return
}
c.Redirect(http.StatusFound, "/downloads/"+latest.APKFile)
}
func latestRelease(release *models.Release) error {
return db.DB.
Order("version_code desc").
First(release).Error
}
func ListReleases(c *gin.Context) {
var releases []models.Release
@@ -124,6 +147,16 @@ func UploadRelease(c *gin.Context) {
return
}
// Tablets only see the release with the highest version code, so an older or equal one would never be offered
var latest models.Release
if err := latestRelease(&latest); err == nil && int64(info.VersionCode) <= latest.VersionCode {
c.JSON(http.StatusConflict, gin.H{
"error": fmt.Sprintf("version code %d must be higher than the latest release (%s, code %d)",
info.VersionCode, latest.Version, latest.VersionCode),
})
return
}
filename := "app-" + info.Version + ".apk"
path := filepath.Join("uploads", filename)