Skip to content

Commit

Permalink
APK Content-Type fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sorokinmax committed Apr 4, 2024
1 parent 7f4079a commit 6451a8a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cmd/astore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"android-store/internal/api"
"android-store/internal/db"
"android-store/internal/globals"
"android-store/internal/middleware"
models "android-store/internal/models/apk"
"fmt"
"log/slog"
Expand Down Expand Up @@ -56,6 +57,7 @@ func main() {
//router.Use(AddUserToCtx())
router.StaticFile("favicon.ico", "./views/favicon.ico")
router.Use(static.Serve("/apps", static.LocalFile("./data/apps", false)))
router.Use(middleware.StaticApkMiddleware())
//router.Use(static.Serve("/icons", static.LocalFile("./icons", false)))
router.GET("/", api.IndexHandler)
//router.GET("/admin", middleware.MidAuth(auth), middleware.AddUserToCtx(), api.IndexHandler)
Expand Down
2 changes: 1 addition & 1 deletion internal/globals/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package globals
// SERVICE DESCRIPTION
const ServiceFriendlyName = "Android store"
const ServiceName = "android-store"
const Version = "1.1.7"
const Version = "1.1.8"

// ENVIRONMENT VARIABLES CONFIGURATION STRUCTURE
type ConfigStruct struct {
Expand Down
17 changes: 17 additions & 0 deletions internal/middleware/middleware.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
package middleware

import (
"strings"

"github.com/gin-gonic/gin"
)

func StaticApkMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
// Apply the Cache-Control header to the static files
if strings.HasPrefix(c.Request.URL.Path, "/apps/") {
c.Header("Content-Type", "application/vnd.android.package-archive")
}
// Continue to the next middleware or handler
c.Next()
}
}

/*
import (
"context"
Expand Down

0 comments on commit 6451a8a

Please sign in to comment.