Exclude downloaded packages

Signed-off-by: Yuan Si <do4suki@gmail.com>
This commit is contained in:
2023-04-10 06:17:57 +08:00
parent 4c097a523c
commit fd95e54756
2 changed files with 15 additions and 6 deletions
+10 -1
View File
@@ -10,6 +10,7 @@ import (
"honoka-chan/model"
"honoka-chan/utils"
"net/http"
"strings"
"time"
"github.com/gin-gonic/gin"
@@ -146,7 +147,15 @@ func DownloadBatchHandler(ctx *gin.Context) {
pkgList := []model.BatchResult{}
if downloadReq.ClientVersion == PackageVersion && CdnUrl != "" {
pkgType := downloadReq.PackageType
stmt, err := db.Prepare("SELECT pkg_id,pkg_order,pkg_size FROM download_db WHERE pkg_type = ? ORDER BY pkg_id ASC, pkg_order ASC")
exPkgId := ""
if len(downloadReq.ExcludedPackageIds) > 0 {
// https://stackoverflow.com/a/37533144
exPkgId = strings.Trim(strings.Join(strings.Fields(fmt.Sprint(downloadReq.ExcludedPackageIds)), ","), "[]")
exPkgId = fmt.Sprintf("AND pkg_id NOT IN (%s)", exPkgId)
}
fmt.Println(exPkgId)
stmt, err := db.Prepare("SELECT pkg_id,pkg_order,pkg_size FROM download_db WHERE pkg_type = ? " + exPkgId + " ORDER BY pkg_id ASC, pkg_order ASC")
if err != nil {
panic(err)
}
+5 -5
View File
@@ -23,11 +23,11 @@ type AdditionalResp struct {
}
type BatchReq struct {
ClientVersion string `json:"client_version"`
Os string `json:"os"`
PackageType int `json:"package_type"`
ExcludedPackageIds []interface{} `json:"excluded_package_ids"`
CommandNum string `json:"commandNum"`
ClientVersion string `json:"client_version"`
Os string `json:"os"`
PackageType int `json:"package_type"`
ExcludedPackageIds []int `json:"excluded_package_ids"`
CommandNum string `json:"commandNum"`
}
type BatchResult struct {