11package themes
22
33import (
4+ "encoding/base64"
45 "fmt"
6+ "net/http"
57 "os"
68 "strings"
79
@@ -18,7 +20,7 @@ func isDir(path string) bool {
1820 return err == nil && stat .IsDir ()
1921}
2022
21- func uploadFile ( client * shopify. Client , themeID int64 , source , destination string ) error {
23+ func destinationPath ( source , destination string ) string {
2224 const themePathSeperator = "/"
2325
2426 if strings .Index (destination , "." ) == - 1 {
@@ -30,17 +32,26 @@ func uploadFile(client *shopify.Client, themeID int64, source, destination strin
3032 destination = destination + path [len (path ) - 1 ]
3133 }
3234
35+ return destination
36+ }
37+
38+ func uploadFile (client * shopify.Client , themeID int64 , source , destination string ) error {
39+ destination = destinationPath (source , destination )
40+
3341 fmt .Printf ("Uploading '%s' to '%s'\n " , source , destination )
3442
3543 value , err := os .ReadFile (source )
3644 if err != nil {
3745 return fmt .Errorf ("Failed to read file '%s': %s" , source , err )
3846 }
3947
40- asset := shopify.Asset {
41- Key : destination ,
42- Value : string (value ),
43- ThemeID : themeID ,
48+ asset := shopify.Asset {Key : destination , ThemeID : themeID }
49+
50+ // Others? Maybe always b64 encode?
51+ if strings .HasPrefix (http .DetectContentType (value ), "image/" ) {
52+ asset .Attachment = base64 .StdEncoding .EncodeToString (value )
53+ } else {
54+ asset .Value = string (value )
4455 }
4556
4657 _ , err = client .Asset .Update (themeID , asset )
0 commit comments