mirror of
https://github.com/fiatjaf/khatru.git
synced 2026-06-04 01:31:12 +02:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b4d81dde4 | ||
|
|
7bfdbb557c | ||
|
|
3f26a1f727 |
@@ -9,6 +9,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/liamg/magic"
|
"github.com/liamg/magic"
|
||||||
"github.com/nbd-wtf/go-nostr"
|
"github.com/nbd-wtf/go-nostr"
|
||||||
@@ -190,8 +191,14 @@ func (bs BlossomServer) handleGetBlob(w http.ResponseWriter, r *http.Request) {
|
|||||||
for _, lb := range bs.LoadBlob {
|
for _, lb := range bs.LoadBlob {
|
||||||
reader, _ := lb(r.Context(), hhash)
|
reader, _ := lb(r.Context(), hhash)
|
||||||
if reader != nil {
|
if reader != nil {
|
||||||
w.Header().Add("Content-Type", mime.TypeByExtension(ext))
|
// use unix epoch as the time if we can't find the descriptor
|
||||||
io.Copy(w, reader)
|
// as described in the http.ServeContent documentation
|
||||||
|
t := time.Unix(0, 0)
|
||||||
|
descriptor, err := bs.Store.Get(r.Context(), hhash)
|
||||||
|
if err == nil && descriptor != nil {
|
||||||
|
t = descriptor.Uploaded.Time()
|
||||||
|
}
|
||||||
|
http.ServeContent(w, r, hhash+ext, t, reader)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -257,7 +264,13 @@ func (bs BlossomServer) handleList(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
w.Write([]byte{'['})
|
w.Write([]byte{'['})
|
||||||
enc := json.NewEncoder(w)
|
enc := json.NewEncoder(w)
|
||||||
|
first := true
|
||||||
for bd := range ch {
|
for bd := range ch {
|
||||||
|
if !first {
|
||||||
|
w.Write([]byte{','})
|
||||||
|
} else {
|
||||||
|
first = false
|
||||||
|
}
|
||||||
enc.Encode(bd)
|
enc.Encode(bd)
|
||||||
}
|
}
|
||||||
w.Write([]byte{']'})
|
w.Write([]byte{']'})
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ type BlossomServer struct {
|
|||||||
Store BlobIndex
|
Store BlobIndex
|
||||||
|
|
||||||
StoreBlob []func(ctx context.Context, sha256 string, body []byte) error
|
StoreBlob []func(ctx context.Context, sha256 string, body []byte) error
|
||||||
LoadBlob []func(ctx context.Context, sha256 string) (io.Reader, error)
|
LoadBlob []func(ctx context.Context, sha256 string) (io.ReadSeeker, error)
|
||||||
DeleteBlob []func(ctx context.Context, sha256 string) error
|
DeleteBlob []func(ctx context.Context, sha256 string) error
|
||||||
|
|
||||||
RejectUpload []func(ctx context.Context, auth *nostr.Event, size int, ext string) (bool, string, int)
|
RejectUpload []func(ctx context.Context, auth *nostr.Event, size int, ext string) (bool, string, int)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func main() {
|
|||||||
fmt.Println("storing", sha256, len(body))
|
fmt.Println("storing", sha256, len(body))
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
bl.LoadBlob = append(bl.LoadBlob, func(ctx context.Context, sha256 string) (io.Reader, error) {
|
bl.LoadBlob = append(bl.LoadBlob, func(ctx context.Context, sha256 string) (io.ReadSeeker, error) {
|
||||||
fmt.Println("loading", sha256)
|
fmt.Println("loading", sha256)
|
||||||
blob := strings.NewReader("aaaaa")
|
blob := strings.NewReader("aaaaa")
|
||||||
return blob, nil
|
return blob, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user