aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/main.go b/main.go
index 6907fa4..0ed7c67 100644
--- a/main.go
+++ b/main.go
@@ -4,6 +4,7 @@ import (
"embed"
"encoding/json"
"fmt"
+ "io"
"io/fs"
"llostre/auth"
"llostre/fetchers"
@@ -82,8 +83,14 @@ func init() {
panic(err)
}
+ porxieAddr := os.Getenv("PORXIE_URL")
+ if porxieAddr == "" {
+ porxieAddr = "porxie:6314"
+ }
+
config = &fetchers.Config{
SlingshotURL: slingshotURL,
+ PorxieURL: fmt.Sprintf("http://%s", os.Getenv("PORXIE_ADDR")),
PageSize: 50,
Logger: logger,
Cache: postCache,
@@ -417,6 +424,28 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(note)
}
+func blobHandler(w http.ResponseWriter, r *http.Request) {
+ path := strings.TrimPrefix(r.URL.Path, "/api/blob/")
+ parts := strings.SplitN(path, "/", 2)
+ if len(parts) != 2 {
+ http.Error(w, "invalid blob path", http.StatusBadRequest)
+ return
+ }
+
+ porxieResp, err := http.Get(fmt.Sprintf("%s/%s/%s", config.PorxieURL, parts[0], parts[1]))
+ if err != nil {
+ config.Logger.Error("blob fetch failed", "url", porxieResp, "error", err)
+ http.Error(w, "blob fetch failed", http.StatusBadGateway)
+ return
+ }
+ defer porxieResp.Body.Close()
+
+ w.Header().Set("Content-Type", porxieResp.Header.Get("Content-Type"))
+ w.Header().Set("Cache-Control", porxieResp.Header.Get("Cache-Control"))
+ w.WriteHeader(porxieResp.StatusCode)
+ io.Copy(w, porxieResp.Body)
+}
+
func main() {
defer config.Cache.Close()
@@ -437,5 +466,6 @@ func main() {
http.HandleFunc("/api/login", loginHandler)
http.HandleFunc("/api/callback", callbackHandler)
http.HandleFunc("/api/post/", postHandler) // /api/post/{uri}
+ http.HandleFunc("/api/blob/", blobHandler)
http.ListenAndServe("0.0.0.0:8080", nil)
}