From f9e9aab24355d134ebee10a2f4ced2acbae91087 Mon Sep 17 00:00:00 2001 From: Lz Date: Mon, 30 Oct 2023 15:28:25 +0800 Subject: [PATCH] fix:download file/thumbnail by authticket in winsdk (#1265) --- winsdk/allocation.go | 16 ++++- winsdk/browser.go | 13 +++- winsdk/cache.go | 9 +-- winsdk/helper.go | 14 ++++- winsdk/sdk.go | 57 ++++++++++++++++- winsdk/storage.go | 119 ++++++++++++++++++++++++++++++++---- winsdk/zboxapi.go | 60 ++++++++++++++++++ zboxapi/sdk.go | 9 +-- zboxcore/fileref/fileref.go | 42 +++++++------ zboxcore/sdk/allocation.go | 10 ++- zboxcore/sdk/listworker.go | 34 ++++++----- 11 files changed, 317 insertions(+), 66 deletions(-) diff --git a/winsdk/allocation.go b/winsdk/allocation.go index 0f21029eb..f121c2a1f 100644 --- a/winsdk/allocation.go +++ b/winsdk/allocation.go @@ -27,6 +27,11 @@ import ( // //export GetAllocation func GetAllocation(allocationID *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() allocID := C.GoString(allocationID) return WithJSON(getAllocation(allocID)) } @@ -41,6 +46,11 @@ func GetAllocation(allocationID *C.char) *C.char { // //export ListAllocations func ListAllocations() *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() items, err := sdk.GetAllocations() if err != nil { log.Error("win: ", err) @@ -61,7 +71,11 @@ func ListAllocations() *C.char { // //export CreateFreeAllocation func CreateFreeAllocation(freemarker *C.char) *C.char { - + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() marker := &zboxapi.FreeMarker{} js := C.GoString(freemarker) err := json.Unmarshal([]byte(js), marker) diff --git a/winsdk/browser.go b/winsdk/browser.go index 0822210f5..8f4dca987 100644 --- a/winsdk/browser.go +++ b/winsdk/browser.go @@ -33,6 +33,11 @@ type RemoteFile struct { // //export ListAll func ListAll(allocationID *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() alloc, err := getAllocation(C.GoString(allocationID)) if err != nil { log.Error("win: ", err) @@ -76,7 +81,11 @@ func ListAll(allocationID *C.char) *C.char { // //export List func List(allocationID, remotePath, authTicket, lookupHash *C.char) *C.char { - + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() allocID := C.GoString(allocationID) remotepath := C.GoString(remotePath) authticket := C.GoString(authTicket) @@ -113,7 +122,7 @@ func List(allocationID, remotePath, authTicket, lookupHash *C.char) *C.char { return WithJSON("[]", errors.New("Error: lookuphash flag is missing")) } - allocationObj, err := getAllocationWith(authticket) + allocationObj, _, err := getAllocationWith(authticket) if err != nil { log.Error("win: ", err) return WithJSON("[]", err) diff --git a/winsdk/cache.go b/winsdk/cache.go index 70d490c4b..b5d4c918f 100644 --- a/winsdk/cache.go +++ b/winsdk/cache.go @@ -52,18 +52,19 @@ func getAllocation(allocationID string) (*sdk.Allocation, error) { return it.Allocation, nil } -func getAllocationWith(authTicket string) (*sdk.Allocation, error) { +func getAllocationWith(authTicket string) (*sdk.Allocation, *marker.AuthTicket, error) { sEnc, err := base64.StdEncoding.DecodeString(authTicket) if err != nil { - return nil, errors.New("Error decoding the auth ticket." + err.Error()) + return nil, nil, errors.New("Error decoding the auth ticket." + err.Error()) } at := &marker.AuthTicket{} err = json.Unmarshal(sEnc, at) if err != nil { - return nil, errors.New("Error unmarshaling the auth ticket." + err.Error()) + return nil, nil, errors.New("Error unmarshaling the auth ticket." + err.Error()) } - return getAllocation(at.AllocationID) + alloc, err := getAllocation(at.AllocationID) + return alloc, at, err } func getFileMeta(allocationID, remotePath string) (*sdk.ConsolidatedFileMeta, error) { diff --git a/winsdk/helper.go b/winsdk/helper.go index 09b05fdfd..867ab2677 100644 --- a/winsdk/helper.go +++ b/winsdk/helper.go @@ -7,13 +7,13 @@ import ( "C" ) import ( + "encoding/base64" "encoding/json" "os" "path/filepath" "github.com/0chain/gosdk/core/encryption" "github.com/0chain/gosdk/zboxcore/marker" - "github.com/0chain/gosdk/zboxcore/sdk" ) func getZcnWorkDir() (string, error) { @@ -57,9 +57,17 @@ func getLookupHash(allocationID, path string) string { return encryption.Hash(allocationID + ":" + path) } -func getAuthTicket(authTicket *C.char) (*marker.AuthTicket, string, error) { +func decodeAuthTicket(authTicket *C.char) (*marker.AuthTicket, string, error) { at := C.GoString(authTicket) - t, err := sdk.InitAuthTicket(at).Unmarshall() + buf, err := base64.StdEncoding.DecodeString(at) + if err != nil { + return nil, at, err + } + t := &marker.AuthTicket{} + err = json.Unmarshal(buf, t) + if err != nil { + return nil, at, err + } return t, at, err } diff --git a/winsdk/sdk.go b/winsdk/sdk.go index 3a55576aa..667da05a3 100644 --- a/winsdk/sdk.go +++ b/winsdk/sdk.go @@ -37,6 +37,11 @@ func main() { // //export SetLogFile func SetLogFile(file *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() f, err := os.OpenFile(C.GoString(file), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) if err != nil { @@ -81,6 +86,11 @@ func SetLogFile(file *C.char) *C.char { // //export InitSDKs func InitSDKs(configJson *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() l.Logger.Info("Start InitSDKs") @@ -146,7 +156,11 @@ func InitSDKs(configJson *C.char) *C.char { // //export InitWallet func InitWallet(clientJson *C.char) *C.char { - + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() l.Logger.Info("Start InitStorageSDK") clientJs := C.GoString(clientJson) @@ -188,6 +202,11 @@ var ErrInvalidSignatureScheme = errors.New("invalid_signature_scheme") // //export SignRequest func SignRequest(privateKey, signatureScheme, data *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() key := C.GoString(privateKey) scheme := C.GoString(signatureScheme) d := C.GoString(data) @@ -209,7 +228,11 @@ func SignRequest(privateKey, signatureScheme, data *C.char) *C.char { // //export VerifySignature func VerifySignature(publicKey, signatureScheme string, data string, signature string) *C.char { - + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() hash := encryption.Hash(data) signScheme := zcncrypto.NewSignatureScheme(signatureScheme) @@ -233,6 +256,11 @@ func VerifySignature(publicKey, signatureScheme string, data string, signature s // //export CryptoJsEncrypt func CryptoJsEncrypt(passphrase, message *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() pass := C.GoString(passphrase) msg := C.GoString(message) @@ -249,6 +277,11 @@ func CryptoJsEncrypt(passphrase, message *C.char) *C.char { // //export CryptoJsDecrypt func CryptoJsDecrypt(passphrase, encryptedMessage *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() pass := C.GoString(passphrase) msg := C.GoString(encryptedMessage) @@ -265,6 +298,11 @@ func CryptoJsDecrypt(passphrase, encryptedMessage *C.char) *C.char { // //export GetPublicEncryptionKey func GetPublicEncryptionKey(mnemonics *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() m := C.GoString(mnemonics) return WithJSON(zcncore.GetPublicEncryptionKey(m)) } @@ -281,6 +319,11 @@ func GetPublicEncryptionKey(mnemonics *C.char) *C.char { // //export GetLookupHash func GetLookupHash(allocationID *C.char, path *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() hash := getLookupHash(C.GoString(allocationID), C.GoString(path)) return WithJSON(hash, nil) } @@ -296,6 +339,11 @@ func GetLookupHash(allocationID *C.char, path *C.char) *C.char { // //export SetFFmpeg func SetFFmpeg(fullFileName *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() f := C.GoString(fullFileName) _, err := os.Stat(f) @@ -317,6 +365,11 @@ func SetFFmpeg(fullFileName *C.char) *C.char { // //export GetFileContentType func GetFileContentType(file *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() f, err := os.Open(C.GoString(file)) if err != nil { log.Error("win: ", err) diff --git a/winsdk/storage.go b/winsdk/storage.go index f8bbc55f3..fc5bcd5f2 100644 --- a/winsdk/storage.go +++ b/winsdk/storage.go @@ -15,6 +15,7 @@ import ( "time" "github.com/0chain/gosdk/core/common" + "github.com/0chain/gosdk/zboxcore/marker" "github.com/0chain/gosdk/zboxcore/sdk" ) @@ -28,6 +29,12 @@ import ( // //export GetFileStats func GetFileStats(allocationID, remotePath *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() + allocID := C.GoString(allocationID) path := C.GoString(remotePath) @@ -69,6 +76,12 @@ func GetFileStats(allocationID, remotePath *C.char) *C.char { // //export Delete func Delete(allocationID, path *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() + allocID := C.GoString(allocationID) alloc, err := getAllocation(allocID) @@ -108,6 +121,11 @@ type MultiOperationOption struct { // //export MultiOperation func MultiOperation(_allocationID, _jsonMultiOperationOptions *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() allocationID := C.GoString(_allocationID) jsonMultiOperationOptions := C.GoString(_jsonMultiOperationOptions) if allocationID == "" { @@ -144,6 +162,12 @@ func MultiOperation(_allocationID, _jsonMultiOperationOptions *C.char) *C.char { } // GetFileMeta get metadata by path +// ## Inputs +// - allocationID +// - path +// - authTicket +// +// ## Outputs // // return // { @@ -152,19 +176,43 @@ func MultiOperation(_allocationID, _jsonMultiOperationOptions *C.char) *C.char { // } // //export GetFileMeta -func GetFileMeta(allocationID, path *C.char) *C.char { +func GetFileMeta(allocationID, path, authTicket *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() allocID := C.GoString(allocationID) - alloc, err := getAllocation(allocID) + t := C.GoString(authTicket) + + var ticket *marker.AuthTicket + + var alloc *sdk.Allocation + var err error + isShared := len(t) > 0 + if isShared { + alloc, ticket, err = getAllocationWith(t) + } else { + alloc, err = getAllocation(allocID) + } + if err != nil { + log.Error("win: ", err) return WithJSON(nil, err) } s := C.GoString(path) - f, err := alloc.GetFileMeta(s) + var f *sdk.ConsolidatedFileMeta + if isShared { + f, err = alloc.GetFileMetaFromAuthTicket(t, ticket.FilePathHash) + } else { + f, err = alloc.GetFileMeta(s) + } if err != nil { + log.Error("win: ", err, " authTicket=", t, " path=", s) return WithJSON(nil, err) } @@ -185,7 +233,7 @@ func GetFileMeta(allocationID, path *C.char) *C.char { func BulkUpload(allocationID, files *C.char) *C.char { defer func() { if r := recover(); r != nil { - log.Error("win: ", r) + log.Error("win: crash ", r) } }() allocID := C.GoString(allocationID) @@ -255,6 +303,11 @@ func BulkUpload(allocationID, files *C.char) *C.char { // //export GetUploadStatus func GetUploadStatus(lookupHash *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() h := C.GoString(lookupHash) h2, ok := transcodeFiles.Get(h) @@ -305,6 +358,11 @@ func SetNumBlockDownloads(num int) { // //export DownloadFile func DownloadFile(allocationID, localPath, remotePath *C.char, verifyDownload, isFinal bool) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() allocID := C.GoString(allocationID) alloc, err := getAllocation(allocID) @@ -341,7 +399,7 @@ func DownloadFile(allocationID, localPath, remotePath *C.char, verifyDownload, i func DownloadThumbnail(allocationID, localPath, remotePath *C.char, verifyDownload bool, isFinal bool) *C.char { defer func() { if r := recover(); r != nil { - log.Error("win: DownloadThumbnail ", r) + log.Error("win: crash ", r) } }() allocID := C.GoString(allocationID) @@ -380,8 +438,13 @@ func DownloadThumbnail(allocationID, localPath, remotePath *C.char, verifyDownlo // //export DownloadSharedFile func DownloadSharedFile(localPath, authTicket *C.char, verifyDownload bool, isFinal bool) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() info := &SharedInfo{} - t, at, err := getAuthTicket(authTicket) + t, at, err := decodeAuthTicket(authTicket) if err != nil { return WithJSON(info, err) } @@ -420,9 +483,15 @@ func DownloadSharedFile(localPath, authTicket *C.char, verifyDownload bool, isFi // //export DownloadSharedThumbnail func DownloadSharedThumbnail(localPath, authTicket *C.char, verifyDownload bool, isFinal bool) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() info := &SharedInfo{} - t, at, err := getAuthTicket(authTicket) + t, at, err := decodeAuthTicket(authTicket) if err != nil { + log.Error("win: ", err, " authTicket=", at) return WithJSON(info, err) } info.AllocationID = t.AllocationID @@ -430,6 +499,7 @@ func DownloadSharedThumbnail(localPath, authTicket *C.char, verifyDownload bool, alloc, err := getAllocation(t.AllocationID) if err != nil { + log.Error("win: ", err, " authTicket=", at) return WithJSON(info, err) } @@ -437,6 +507,7 @@ func DownloadSharedThumbnail(localPath, authTicket *C.char, verifyDownload bool, err = alloc.DownloadThumbnailFromAuthTicket(C.GoString(localPath), at, t.FilePathHash, t.FileName, verifyDownload, statusBar, isFinal) if err != nil { + log.Error("win: ", err, " authTicket=", at, " lookuphash=", t.FilePathHash) return WithJSON(info, err) } @@ -465,6 +536,12 @@ func DownloadSharedThumbnail(localPath, authTicket *C.char, verifyDownload bool, func DownloadFileBlocks(allocationID, localPath, remotePath *C.char, startBlock int64, endBlock int64, numBlocks int, verifyDownload bool, isFinal bool) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() + allocID := C.GoString(allocationID) alloc, err := getAllocation(allocID) @@ -487,7 +564,6 @@ func DownloadFileBlocks(allocationID, // DownloadSharedFileBlocks - downalod shared file blocks // ## Inputs -// - allocationID // - localPath // - remotePath // - startBlock @@ -504,12 +580,16 @@ func DownloadFileBlocks(allocationID, // } // //export DownloadSharedFileBlocks -func DownloadSharedFileBlocks(allocationID, - localPath, authTicket *C.char, startBlock int64, endBlock int64, +func DownloadSharedFileBlocks(localPath, authTicket *C.char, startBlock int64, endBlock int64, numBlocks int, verifyDownload bool, isFinal bool) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() info := &SharedInfo{} - t, at, err := getAuthTicket(authTicket) + t, at, err := decodeAuthTicket(authTicket) if err != nil { return WithJSON(info, err) } @@ -544,7 +624,11 @@ func DownloadSharedFileBlocks(allocationID, // //export GetDownloadStatus func GetDownloadStatus(key *C.char, isThumbnail bool) *C.char { - + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() k := C.GoString(key) if isThumbnail { k += ":thumbnail" @@ -577,7 +661,13 @@ func GetDownloadStatus(key *C.char, isThumbnail bool) *C.char { // //export CreateAuthTicket func CreateAuthTicket(allocationID, remotePath, refereeClientID, refereePublicEncryptionKey, availableAfter *C.char, expirationSeconds int64) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() alloc, err := getAllocation(C.GoString(allocationID)) + if err != nil { log.Error("win: ", err) return WithJSON(nil, err) @@ -628,6 +718,11 @@ func CreateAuthTicket(allocationID, remotePath, refereeClientID, refereePublicEn // //export DeleteAuthTicket func DeleteAuthTicket(allocationID, remotePath, refereeClientID *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() alloc, err := getAllocation(C.GoString(allocationID)) if err != nil { log.Error("win: ", err) diff --git a/winsdk/zboxapi.go b/winsdk/zboxapi.go index d41c8d874..0a8c5a628 100644 --- a/winsdk/zboxapi.go +++ b/winsdk/zboxapi.go @@ -29,6 +29,11 @@ var ( // //export InitZBox func InitZBox(zboxHost, zboxAppType *C.char) { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() if zboxApiClient == nil { zboxApiClient = zboxapi.NewClient() } @@ -53,6 +58,11 @@ func InitZBox(zboxHost, zboxAppType *C.char) { // //export SetZBoxWallet func SetZBoxWallet(clientID, clientPrivateKey, clientPublicKey *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() if zboxApiClient == nil { return WithJSON(false, ErrZboxApiNotInitialized) } @@ -78,6 +88,11 @@ func SetZBoxWallet(clientID, clientPrivateKey, clientPublicKey *C.char) *C.char // //export GetCsrfToken func GetCsrfToken() *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() if zboxApiClient == nil { return WithJSON(0, ErrZboxApiNotInitialized) } @@ -95,6 +110,11 @@ func GetCsrfToken() *C.char { // //export CreateJwtSession func CreateJwtSession(phoneNumber *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() if zboxApiClient == nil { return WithJSON(0, ErrZboxApiNotInitialized) } @@ -111,6 +131,11 @@ func CreateJwtSession(phoneNumber *C.char) *C.char { // //export CreateJwtToken func CreateJwtToken(phoneNumber *C.char, jwtSessionID int64, otp *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() if zboxApiClient == nil { return WithJSON("", ErrZboxApiNotInitialized) } @@ -127,6 +152,11 @@ func CreateJwtToken(phoneNumber *C.char, jwtSessionID int64, otp *C.char) *C.cha // //export RefreshJwtToken func RefreshJwtToken(phoneNumber, token *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() if zboxApiClient == nil { return WithJSON("", ErrZboxApiNotInitialized) } @@ -145,6 +175,11 @@ func RefreshJwtToken(phoneNumber, token *C.char) *C.char { // //export GetFreeMarker func GetFreeMarker(phoneNumber, token *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() marker, err := zboxApiClient.GetFreeStorage(context.TODO(), C.GoString(phoneNumber), C.GoString(token)) if err != nil { log.Error("win: ", err) @@ -169,6 +204,11 @@ func GetFreeMarker(phoneNumber, token *C.char) *C.char { // //export CreateSharedInfo func CreateSharedInfo(phoneNumber, token, sharedInfo *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() js := C.GoString(sharedInfo) s := zboxapi.SharedInfo{} @@ -203,6 +243,11 @@ func CreateSharedInfo(phoneNumber, token, sharedInfo *C.char) *C.char { // //export DeleteSharedInfo func DeleteSharedInfo(phoneNumber, token, authTicket, lookupHash *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() err := zboxApiClient.DeleteSharedInfo(context.TODO(), C.GoString(phoneNumber), C.GoString(token), C.GoString(authTicket), C.GoString(lookupHash)) if err != nil { log.Error("win: ", err) @@ -226,6 +271,11 @@ func DeleteSharedInfo(phoneNumber, token, authTicket, lookupHash *C.char) *C.cha // //export GetSharedByMe func GetSharedByMe(phoneNumber, token *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() list, err := zboxApiClient.GetSharedByMe(context.TODO(), C.GoString(phoneNumber), C.GoString(token)) if err != nil { log.Error("win: ", err) @@ -249,6 +299,11 @@ func GetSharedByMe(phoneNumber, token *C.char) *C.char { // //export GetSharedByPublic func GetSharedByPublic(phoneNumber, token *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() list, err := zboxApiClient.GetSharedByPublic(context.TODO(), C.GoString(phoneNumber), C.GoString(token)) if err != nil { log.Error("win: ", err) @@ -272,6 +327,11 @@ func GetSharedByPublic(phoneNumber, token *C.char) *C.char { // //export GetSharedToMe func GetSharedToMe(phoneNumber, token *C.char) *C.char { + defer func() { + if r := recover(); r != nil { + log.Error("win: crash ", r) + } + }() list, err := zboxApiClient.GetSharedToMe(context.TODO(), C.GoString(phoneNumber), C.GoString(token)) if err != nil { log.Error("win: ", err) diff --git a/zboxapi/sdk.go b/zboxapi/sdk.go index c091df59a..dee51560a 100644 --- a/zboxapi/sdk.go +++ b/zboxapi/sdk.go @@ -71,6 +71,8 @@ func (c *Client) SetWallet(clientID, clientPrivateKey, clientPublicKey string) { } func (c *Client) parseResponse(resp *http.Response, respBody []byte, result interface{}) error { + + log.Info("zboxapi: ", resp.StatusCode, " ", string(respBody)) if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusCreated { if err := json.Unmarshal(respBody, result); err != nil { return thrown.Throw(ErrInvalidJsonResponse, string(respBody)) @@ -262,7 +264,6 @@ func (c *Client) GetFreeStorage(ctx context.Context, phoneNumber, token string) return err } - log.Info("zboxapi: ", string(respBody)) return c.parseResponse(resp, respBody, result) }) @@ -302,7 +303,6 @@ func (c *Client) CreateSharedInfo(ctx context.Context, phoneNumber, token string return err } - log.Info("zboxapi: ", string(respBody)) return c.parseResponse(resp, respBody, &result) }) @@ -335,7 +335,6 @@ func (c *Client) DeleteSharedInfo(ctx context.Context, phoneNumber, token, authT return err } - log.Info("zboxapi: ", string(respBody)) return c.parseResponse(resp, respBody, &result) }) @@ -381,8 +380,6 @@ func (c *Client) getShared(ctx context.Context, phoneNumber, token string, isPri return err } - log.Info("zboxapi: ", string(respBody)) - return c.parseResponse(resp, respBody, &result) }) @@ -416,8 +413,6 @@ func (c *Client) GetSharedToMe(ctx context.Context, phoneNumber, token string) ( return err } - log.Info("zboxapi: ", string(respBody)) - return c.parseResponse(resp, respBody, &result) }) diff --git a/zboxcore/fileref/fileref.go b/zboxcore/fileref/fileref.go index eae303752..df821c5f0 100644 --- a/zboxcore/fileref/fileref.go +++ b/zboxcore/fileref/fileref.go @@ -60,26 +60,28 @@ type RefEntity interface { } type Ref struct { - Type string `json:"type" mapstructure:"type"` - AllocationID string `json:"allocation_id" mapstructure:"allocation_id"` - Name string `json:"name" mapstructure:"name"` - Path string `json:"path" mapstructure:"path"` - Size int64 `json:"size" mapstructure:"size"` - ActualSize int64 `json:"actual_file_size" mapstructure:"actual_file_size"` - Hash string `json:"hash" mapstructure:"hash"` - ChunkSize int64 `json:"chunk_size" mapstructure:"chunk_size"` - NumBlocks int64 `json:"num_of_blocks" mapstructure:"num_of_blocks"` - PathHash string `json:"path_hash" mapstructure:"path_hash"` - LookupHash string `json:"lookup_hash" mapstructure:"lookup_hash"` - FileID string `json:"file_id" mapstructure:"file_id"` - FileMetaHash string `json:"file_meta_hash" mapstructure:"file_meta_hash"` - ThumbnailHash string `json:"thumbnail_hash" mapstructure:"thumbnail_hash"` - ThumbnailSize int64 `json:"thumbnail_size" mapstructure:"thumbnail_size"` - HashToBeComputed bool - ChildrenLoaded bool - Children []RefEntity `json:"-" mapstructure:"-"` - CreatedAt common.Timestamp `json:"created_at" mapstructure:"created_at"` - UpdatedAt common.Timestamp `json:"updated_at" mapstructure:"updated_at"` + Type string `json:"type" mapstructure:"type"` + AllocationID string `json:"allocation_id" mapstructure:"allocation_id"` + Name string `json:"name" mapstructure:"name"` + Path string `json:"path" mapstructure:"path"` + Size int64 `json:"size" mapstructure:"size"` + ActualSize int64 `json:"actual_file_size" mapstructure:"actual_file_size"` + Hash string `json:"hash" mapstructure:"hash"` + ChunkSize int64 `json:"chunk_size" mapstructure:"chunk_size"` + NumBlocks int64 `json:"num_of_blocks" mapstructure:"num_of_blocks"` + PathHash string `json:"path_hash" mapstructure:"path_hash"` + LookupHash string `json:"lookup_hash" mapstructure:"lookup_hash"` + FileID string `json:"file_id" mapstructure:"file_id"` + FileMetaHash string `json:"file_meta_hash" mapstructure:"file_meta_hash"` + ThumbnailHash string `json:"thumbnail_hash" mapstructure:"thumbnail_hash"` + ThumbnailSize int64 `json:"thumbnail_size" mapstructure:"thumbnail_size"` + ActualThumbnailHash string `json:"actual_thumbnail_hash" mapstructure:"actual_thumbnail_hash"` + ActualThumbnailSize int64 `json:"actual_thumbnail_size" mapstructure:"actual_thumbnail_size"` + HashToBeComputed bool + ChildrenLoaded bool + Children []RefEntity `json:"-" mapstructure:"-"` + CreatedAt common.Timestamp `json:"created_at" mapstructure:"created_at"` + UpdatedAt common.Timestamp `json:"updated_at" mapstructure:"updated_at"` } func GetReferenceLookup(allocationID string, path string) string { diff --git a/zboxcore/sdk/allocation.go b/zboxcore/sdk/allocation.go index 252538f17..704a72ddc 100644 --- a/zboxcore/sdk/allocation.go +++ b/zboxcore/sdk/allocation.go @@ -104,7 +104,11 @@ type ConsolidatedFileMeta struct { ActualFileSize int64 ActualNumBlocks int64 EncryptedKey string - Collaborators []fileref.Collaborator + + ActualThumbnailSize int64 + ActualThumbnailHash string + + Collaborators []fileref.Collaborator } type AllocationStats struct { @@ -1489,6 +1493,8 @@ func (a *Allocation) GetFileMeta(path string) (*ConsolidatedFileMeta, error) { result.EncryptedKey = ref.EncryptedKey result.Collaborators = ref.Collaborators result.ActualFileSize = ref.ActualFileSize + result.ActualThumbnailHash = ref.ActualThumbnailHash + result.ActualThumbnailSize = ref.ActualThumbnailSize if result.ActualFileSize > 0 { result.ActualNumBlocks = (ref.ActualFileSize + CHUNK_SIZE - 1) / CHUNK_SIZE } @@ -1544,6 +1550,8 @@ func (a *Allocation) GetFileMetaFromAuthTicket(authTicket string, lookupHash str result.Size = ref.Size result.NumBlocks = ref.NumBlocks result.ActualFileSize = ref.ActualFileSize + result.ActualThumbnailHash = ref.ActualThumbnailHash + result.ActualThumbnailSize = ref.ActualThumbnailSize if result.ActualFileSize > 0 { result.ActualNumBlocks = (result.ActualFileSize + CHUNK_SIZE - 1) / CHUNK_SIZE } diff --git a/zboxcore/sdk/listworker.go b/zboxcore/sdk/listworker.go index b803a81c4..3c1c063e0 100644 --- a/zboxcore/sdk/listworker.go +++ b/zboxcore/sdk/listworker.go @@ -44,20 +44,22 @@ type listResponse struct { } type ListResult struct { - Name string `json:"name"` - Path string `json:"path,omitempty"` - Type string `json:"type"` - Size int64 `json:"size"` - Hash string `json:"hash,omitempty"` - FileMetaHash string `json:"file_meta_hash,omitempty"` - MimeType string `json:"mimetype,omitempty"` - NumBlocks int64 `json:"num_blocks"` - LookupHash string `json:"lookup_hash"` - EncryptionKey string `json:"encryption_key"` - ActualSize int64 `json:"actual_size"` - ActualNumBlocks int64 `json:"actual_num_blocks"` - ThumbnailHash string `json:"thumbnail_hash"` - ThumbnailSize int64 `json:"thumbnail_size"` + Name string `json:"name"` + Path string `json:"path,omitempty"` + Type string `json:"type"` + Size int64 `json:"size"` + Hash string `json:"hash,omitempty"` + FileMetaHash string `json:"file_meta_hash,omitempty"` + MimeType string `json:"mimetype,omitempty"` + NumBlocks int64 `json:"num_blocks"` + LookupHash string `json:"lookup_hash"` + EncryptionKey string `json:"encryption_key"` + ActualSize int64 `json:"actual_size"` + ActualNumBlocks int64 `json:"actual_num_blocks"` + ThumbnailHash string `json:"thumbnail_hash"` + ThumbnailSize int64 `json:"thumbnail_size"` + ActualThumbnailHash string `json:"actual_thumbnail_hash"` + ActualThumbnailSize int64 `json:"actual_thumbnail_size"` CreatedAt common.Timestamp `json:"created_at"` UpdatedAt common.Timestamp `json:"updated_at"` @@ -220,6 +222,8 @@ func (req *ListRequest) GetListFromBlobbers() (*ListResult, error) { result.ActualSize = ti.ref.ActualSize result.ThumbnailHash = ti.ref.ThumbnailHash result.ThumbnailSize = ti.ref.ThumbnailSize + result.ActualThumbnailHash = ti.ref.ActualThumbnailHash + result.ActualThumbnailSize = ti.ref.ActualThumbnailSize if ti.ref.ActualSize > 0 { result.ActualNumBlocks = (ti.ref.ActualSize + CHUNK_SIZE - 1) / CHUNK_SIZE @@ -279,6 +283,8 @@ func (lr *ListResult) populateChildren(children []fileref.RefEntity, childResult childResult.ActualSize = (child.(*fileref.FileRef)).ActualFileSize childResult.ThumbnailHash = (child.(*fileref.FileRef)).ThumbnailHash childResult.ThumbnailSize = (child.(*fileref.FileRef)).ThumbnailSize + childResult.ActualThumbnailHash = (child.(*fileref.FileRef)).ActualThumbnailHash + childResult.ActualThumbnailSize = (child.(*fileref.FileRef)).ActualThumbnailSize } else { childResult.ActualSize = (child.(*fileref.Ref)).ActualSize }