Skip to content

Commit

Permalink
Merge pull request #261 from factly/fix/medium-proxy-url
Browse files Browse the repository at this point in the history
added bucket name env variable
  • Loading branch information
shreeharsha-factly authored Sep 7, 2022
2 parents e52869c + 0ad2555 commit fdb58bb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions server/model/medium.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package model

import (
"encoding/json"
"fmt"
"net/url"
"strings"

"github.com/jinzhu/gorm/dialects/postgres"
"github.com/spf13/viper"
Expand Down Expand Up @@ -54,7 +56,11 @@ func (media *Medium) AfterCreate(tx *gorm.DB) (err error) {
_ = json.Unmarshal(media.URL.RawMessage, &resurl)
if rawURL, found := resurl["raw"]; found {
urlObj, _ := url.Parse(rawURL.(string))
resurl["proxy"] = viper.GetString("imageproxy_url") + urlObj.Path
bucket_name := ""
if viper.IsSet("bucket_name") {
bucket_name = fmt.Sprint(viper.GetString("bucket_name"), "/")
}
resurl["proxy"] = strings.Replace(viper.GetString("imageproxy_url")+urlObj.Path, bucket_name, "", 1)

rawBArr, _ := json.Marshal(resurl)
media.URL = postgres.Jsonb{
Expand All @@ -72,7 +78,11 @@ func (media *Medium) AfterFind(tx *gorm.DB) (err error) {
_ = json.Unmarshal(media.URL.RawMessage, &resurl)
if rawURL, found := resurl["raw"]; found {
urlObj, _ := url.Parse(rawURL.(string))
resurl["proxy"] = viper.GetString("imageproxy_url") + urlObj.Path
bucket_name := ""
if viper.IsSet("bucket_name") {
bucket_name = fmt.Sprint(viper.GetString("bucket_name"), "/")
}
resurl["proxy"] = strings.Replace(viper.GetString("imageproxy_url")+urlObj.Path, bucket_name, "", 1)

rawBArr, _ := json.Marshal(resurl)
media.URL = postgres.Jsonb{
Expand Down

0 comments on commit fdb58bb

Please sign in to comment.