summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJacob Weisz <ocdtrekkie@noreply@mills.io>2022-09-24 05:29:27 +0000
committerJames Mills <james@mills.io>2022-09-24 05:29:27 +0000
commit70fbc8c7b0d65fd71878520e5cb14e4a494137fa (patch)
tree33ee4a923fd9647e056304a755d775517fd34592 /app
parent29f278459156f7bd9aec225ed78706d18e001c56 (diff)
Add Sandstorm packaging files (#26)
I am not quite done here, I need to finish some of the packaging metadata, and I am going to maybe take a pass at permissions prior to release. Opening the pull request so you can easily track the progress. Note that Sandstorm app metadata is supposed to be less than 1 MB total, so I optimized your screenshots. I dare you to tell the difference with the naked eye. Co-authored-by: Jacob Weisz <inbox@jacobweisz.com> Reviewed-on: https://git.mills.io/prologic/tube/pulls/26 Co-authored-by: Jacob Weisz <ocdtrekkie@noreply@mills.io> Co-committed-by: Jacob Weisz <ocdtrekkie@noreply@mills.io>
Diffstat (limited to 'app')
-rw-r--r--app/app.go7
-rw-r--r--app/middleware/auth.go15
2 files changed, 21 insertions, 1 deletions
diff --git a/app/app.go b/app/app.go
index 6b89c5b..11b06f4 100644
--- a/app/app.go
+++ b/app/app.go
@@ -97,10 +97,15 @@ func NewApp(cfg *Config) (*App, error) {
// Setup Router
authPassword := os.Getenv("auth_password")
+ isSandstorm := os.Getenv("SANDSTORM")
r := mux.NewRouter().StrictSlash(true)
r.HandleFunc("/", a.indexHandler).Methods("GET", "OPTIONS")
- r.HandleFunc("/upload", middleware.OptionallyRequireAdminAuth(a.uploadHandler, authPassword)).Methods("GET", "OPTIONS", "POST")
+ if isSandstorm == "1" {
+ r.HandleFunc("/upload", middleware.RequireSandstormPermission(a.uploadHandler, "upload")).Methods("GET", "OPTIONS", "POST")
+ } else {
+ r.HandleFunc("/upload", middleware.OptionallyRequireAdminAuth(a.uploadHandler, authPassword)).Methods("GET", "OPTIONS", "POST")
+ }
r.HandleFunc("/import", a.importHandler).Methods("GET", "OPTIONS", "POST")
r.HandleFunc("/v/{id}.mp4", a.videoHandler).Methods("GET")
r.HandleFunc("/v/{prefix}/{id}.mp4", a.videoHandler).Methods("GET")
diff --git a/app/middleware/auth.go b/app/middleware/auth.go
index 61a58e3..c023492 100644
--- a/app/middleware/auth.go
+++ b/app/middleware/auth.go
@@ -3,6 +3,7 @@ package middleware
import (
"crypto/subtle"
"net/http"
+ "strings"
log "github.com/sirupsen/logrus"
)
@@ -48,3 +49,17 @@ func OptionallyRequireAdminAuth(handler http.HandlerFunc, password string) http.
handler(w, r)
}
}
+
+func RequireSandstormPermission(handler http.HandlerFunc, permissionNeeded string) http.HandlerFunc {
+ return func(w http.ResponseWriter, r *http.Request) {
+
+ // Failed
+ if !strings.Contains(r.Header.Get("X-Sandstorm-Permissions"), permissionNeeded) {
+ http.Error(w, "Unauthorized", http.StatusUnauthorized)
+ log.Debugln("No upload capability granted")
+ return
+ }
+
+ handler(w, r)
+ }
+}