From d84bfb7ebaabf61c6ba842cefe69c9c06eb6bcc0 Mon Sep 17 00:00:00 2001 From: itzaname Date: Fri, 31 Dec 2021 17:36:54 -0500 Subject: [PATCH] Roblox now just returns the asset id --- asset.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/asset.go b/asset.go index 9990075..829bbfc 100644 --- a/asset.go +++ b/asset.go @@ -1,9 +1,9 @@ package roblox import ( - "encoding/json" "fmt" "io" + "io/ioutil" "net/http" "net/url" "strconv" @@ -24,12 +24,10 @@ type AssetUploadResponse struct { AssetVersionID int64 `json:"AssetVersionId"` } -func (s *Session) CreateAsset(options *AssetUploadOptions, f io.Reader) (AssetUploadResponse, error) { - var aresp AssetUploadResponse - +func (s *Session) CreateAsset(options *AssetUploadOptions, f io.Reader) (int, error) { endpoint, err := url.Parse("https://data.roblox.com/Data/Upload.ashx?json=1&type=Model&genreTypeId=1") if err != nil { - return aresp, err + return -1, err } query := endpoint.Query() @@ -64,7 +62,7 @@ func (s *Session) CreateAsset(options *AssetUploadOptions, f io.Reader) (AssetUp // Perform request resp, err := s.client.Do(req) if err != nil { - return aresp, err + return -1, err } defer resp.Body.Close() @@ -75,20 +73,21 @@ func (s *Session) CreateAsset(options *AssetUploadOptions, f io.Reader) (AssetUp // Perform request resp, err = s.client.Do(req) if err != nil { - return aresp, err + return -1, err } defer resp.Body.Close() } if resp.StatusCode != 200 { - return aresp, fmt.Errorf(resp.Status) + return -1, fmt.Errorf(resp.Status) } - if err := json.NewDecoder(resp.Body).Decode(&aresp); err != nil { - return aresp, err + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return -1, err } - return aresp, nil + return strconv.Atoi(string(body)) } func (s *Session) Download(id int) (io.Reader, error) {