mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 12:39:17 +00:00
support byte ranges for field data as well
This commit is contained in:
parent
06957fdcd7
commit
b53115fb52
@ -1,6 +1,8 @@
|
|||||||
package databag
|
package databag
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
@ -42,7 +44,7 @@ func GetCardProfileImage(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", http.DetectContentType(data))
|
// response with content
|
||||||
w.Write(data);
|
http.ServeContent(w, r, "image", time.Unix(slot.Card.Updated, 0), bytes.NewReader(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,8 +10,6 @@ import (
|
|||||||
|
|
||||||
func GetChannelTopicAsset(w http.ResponseWriter, r *http.Request) {
|
func GetChannelTopicAsset(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
PrintMsg(r)
|
|
||||||
|
|
||||||
// scan parameters
|
// scan parameters
|
||||||
params := mux.Vars(r)
|
params := mux.Vars(r)
|
||||||
topicId := params["topicId"]
|
topicId := params["topicId"]
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package databag
|
package databag
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
@ -26,8 +28,8 @@ func GetProfileImage(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", http.DetectContentType(data))
|
// response with content
|
||||||
w.Write(data);
|
http.ServeContent(w, r, "image", time.Unix(account.Updated, 0), bytes.NewReader(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,6 +66,7 @@ type Account struct {
|
|||||||
ChannelRevision int64 `gorm:"not null;default:1"`
|
ChannelRevision int64 `gorm:"not null;default:1"`
|
||||||
CardRevision int64 `gorm:"not null;default:1"`
|
CardRevision int64 `gorm:"not null;default:1"`
|
||||||
Created int64 `gorm:"autoCreateTime"`
|
Created int64 `gorm:"autoCreateTime"`
|
||||||
|
Updated int64 `gorm:"autoUpdateTime"`
|
||||||
Disabled bool `gorm:"not null;default:false"`
|
Disabled bool `gorm:"not null;default:false"`
|
||||||
AccountDetail AccountDetail
|
AccountDetail AccountDetail
|
||||||
Apps []App
|
Apps []App
|
||||||
|
@ -140,7 +140,7 @@ func TestAttributeShare(t *testing.T) {
|
|||||||
param["articleId"] = article.Id
|
param["articleId"] = article.Id
|
||||||
param["field"] = "nested.image"
|
param["field"] = "nested.image"
|
||||||
aData, aType, aErr := ApiTestData(GetArticleSubjectField, "GET", "/attributes/articles/{articleId}/subject/{field}",
|
aData, aType, aErr := ApiTestData(GetArticleSubjectField, "GET", "/attributes/articles/{articleId}/subject/{field}",
|
||||||
¶m, nil, APP_TOKENAPP, set.A.Token)
|
¶m, nil, APP_TOKENAPP, set.A.Token, 0, 0)
|
||||||
assert.NoError(t, aErr)
|
assert.NoError(t, aErr)
|
||||||
assert.Equal(t, "image/png", aType["Content-Type"][0])
|
assert.Equal(t, "image/png", aType["Content-Type"][0])
|
||||||
img, _ = base64.StdEncoding.DecodeString(image)
|
img, _ = base64.StdEncoding.DecodeString(image)
|
||||||
@ -150,7 +150,7 @@ func TestAttributeShare(t *testing.T) {
|
|||||||
param["articleId"] = article.Id
|
param["articleId"] = article.Id
|
||||||
param["field"] = "nested.image"
|
param["field"] = "nested.image"
|
||||||
cData, cType, cErr := ApiTestData(GetArticleSubjectField, "GET", "/attributes/articles/{articleId}/subject/{field}",
|
cData, cType, cErr := ApiTestData(GetArticleSubjectField, "GET", "/attributes/articles/{articleId}/subject/{field}",
|
||||||
¶m, nil, APP_TOKENCONTACT, set.C.A.Token)
|
¶m, nil, APP_TOKENCONTACT, set.C.A.Token, 0, 0)
|
||||||
assert.NoError(t, cErr)
|
assert.NoError(t, cErr)
|
||||||
assert.Equal(t, "image/png", cType["Content-Type"][0])
|
assert.Equal(t, "image/png", cType["Content-Type"][0])
|
||||||
img, _ = base64.StdEncoding.DecodeString(image)
|
img, _ = base64.StdEncoding.DecodeString(image)
|
||||||
|
@ -41,7 +41,7 @@ func TestContactSync(t *testing.T) {
|
|||||||
¶m, &msg, APP_TOKENAPP, set.B.Token, &card, nil))
|
¶m, &msg, APP_TOKENAPP, set.B.Token, &card, nil))
|
||||||
assert.True(t, card.Data.CardProfile.ImageSet)
|
assert.True(t, card.Data.CardProfile.ImageSet)
|
||||||
data, hdr, res = ApiTestData(GetCardProfileImage, "GET", "/contact/cards/{cardId}/profile/image",
|
data, hdr, res = ApiTestData(GetCardProfileImage, "GET", "/contact/cards/{cardId}/profile/image",
|
||||||
¶m, &data, APP_TOKENAPP, set.B.Token)
|
¶m, &data, APP_TOKENAPP, set.B.Token, 0, 0)
|
||||||
assert.NoError(t, res)
|
assert.NoError(t, res)
|
||||||
|
|
||||||
// compare retrieved image
|
// compare retrieved image
|
||||||
|
@ -103,7 +103,7 @@ func TestProfileUpdate(t *testing.T) {
|
|||||||
|
|
||||||
// retrieve profile image
|
// retrieve profile image
|
||||||
data, hdr, err = ApiTestData(GetProfileImage, "GET", "/profile/image", nil, nil,
|
data, hdr, err = ApiTestData(GetProfileImage, "GET", "/profile/image", nil, nil,
|
||||||
APP_TOKENAPP, set.A.Token)
|
APP_TOKENAPP, set.A.Token, 0, 0)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// compare retrieved image
|
// compare retrieved image
|
||||||
|
Loading…
Reference in New Issue
Block a user