diff --git a/libgm/client.go b/libgm/client.go index 60817fb..931b9f0 100644 --- a/libgm/client.go +++ b/libgm/client.go @@ -194,48 +194,6 @@ func (c *Client) triggerEvent(evt interface{}) { } } -func (c *Client) DownloadMedia(mediaID string, key []byte) ([]byte, error) { - downloadMetadata := &gmproto.DownloadAttachmentRequest{ - Info: &gmproto.AttachmentInfo{ - AttachmentID: mediaID, - Encrypted: true, - }, - AuthData: &gmproto.AuthMessage{ - RequestID: uuid.NewString(), - TachyonAuthToken: c.AuthData.TachyonAuthToken, - ConfigVersion: util.ConfigMessage, - }, - } - downloadMetadataBytes, err := proto.Marshal(downloadMetadata) - if err != nil { - return nil, err - } - downloadMetadataEncoded := base64.StdEncoding.EncodeToString(downloadMetadataBytes) - req, err := http.NewRequest("GET", util.UploadMediaURL, nil) - if err != nil { - return nil, err - } - util.BuildUploadHeaders(req, downloadMetadataEncoded) - res, reqErr := c.http.Do(req) - if reqErr != nil { - return nil, reqErr - } - defer res.Body.Close() - encryptedBuffImg, err := io.ReadAll(res.Body) - if err != nil { - return nil, err - } - cryptor, err := crypto.NewAESGCMHelper(key) - if err != nil { - return nil, err - } - decryptedImageBytes, decryptionErr := cryptor.DecryptData(encryptedBuffImg) - if decryptionErr != nil { - return nil, decryptionErr - } - return decryptedImageBytes, nil -} - func (c *Client) FetchConfigVersion() { req, bErr := http.NewRequest("GET", util.ConfigUrl, nil) if bErr != nil { diff --git a/libgm/upload.go b/libgm/media.go similarity index 88% rename from libgm/upload.go rename to libgm/media.go index 01efd07..d5c5baa 100644 --- a/libgm/upload.go +++ b/libgm/media.go @@ -247,3 +247,45 @@ func (c *Client) buildStartUploadPayload() (string, error) { return protoDataEncoded, nil } + +func (c *Client) DownloadMedia(mediaID string, key []byte) ([]byte, error) { + downloadMetadata := &gmproto.DownloadAttachmentRequest{ + Info: &gmproto.AttachmentInfo{ + AttachmentID: mediaID, + Encrypted: true, + }, + AuthData: &gmproto.AuthMessage{ + RequestID: uuid.NewString(), + TachyonAuthToken: c.AuthData.TachyonAuthToken, + ConfigVersion: util.ConfigMessage, + }, + } + downloadMetadataBytes, err := proto.Marshal(downloadMetadata) + if err != nil { + return nil, err + } + downloadMetadataEncoded := base64.StdEncoding.EncodeToString(downloadMetadataBytes) + req, err := http.NewRequest("GET", util.UploadMediaURL, nil) + if err != nil { + return nil, err + } + util.BuildUploadHeaders(req, downloadMetadataEncoded) + res, reqErr := c.http.Do(req) + if reqErr != nil { + return nil, reqErr + } + defer res.Body.Close() + encryptedBuffImg, err := io.ReadAll(res.Body) + if err != nil { + return nil, err + } + cryptor, err := crypto.NewAESGCMHelper(key) + if err != nil { + return nil, err + } + decryptedImageBytes, decryptionErr := cryptor.DecryptData(encryptedBuffImg) + if decryptionErr != nil { + return nil, decryptionErr + } + return decryptedImageBytes, nil +}