add multi region support for cloud sync
This commit is contained in:
@@ -79,6 +79,7 @@ type retStruct struct {
|
||||
Reason string `json:"reason"`
|
||||
Subscriptions []shuffle.PaymentSubscription `json:"subscriptions"`
|
||||
Licensed bool `json:"licensed"`
|
||||
CloudSyncUrl string `json:"cloud_sync_url,omitempty"`
|
||||
}
|
||||
|
||||
type Contact struct {
|
||||
@@ -3906,6 +3907,7 @@ func remoteOrgJobController(org shuffle.Org, body []byte) error {
|
||||
SyncFeatures shuffle.SyncFeatures `json:"sync_features"`
|
||||
Subscriptions []shuffle.PaymentSubscription `json:"subscriptions"`
|
||||
Licensed bool `json:"licensed"`
|
||||
CloudSyncUrl string `json:"cloud_sync_url,omitempty"`
|
||||
}
|
||||
|
||||
responseData := retStruct{}
|
||||
@@ -4083,6 +4085,19 @@ func remoteOrgJobHandler(org shuffle.Org, interval int) error {
|
||||
backupJobData = []byte{}
|
||||
}
|
||||
|
||||
cloudSyncRegionUrlCacheKey := fmt.Sprintf("org_cloudsync_region_url_%s", org.Id)
|
||||
cloudSyncRegionUrlCached, err := shuffle.GetCache(ctx, cloudSyncRegionUrlCacheKey)
|
||||
if err == nil {
|
||||
if cachedBytes, ok := cloudSyncRegionUrlCached.([]byte); ok && len(cachedBytes) > 0 {
|
||||
syncUrl = string(cachedBytes)
|
||||
log.Printf("[DEBUG] Using cached cloud sync region url for org %s: %s", org.Id, syncUrl)
|
||||
}
|
||||
}
|
||||
|
||||
if len(syncUrl) == 0 || !strings.HasPrefix(syncUrl, "http") {
|
||||
syncUrl = "https://shuffler.io"
|
||||
}
|
||||
|
||||
syncUrl := fmt.Sprintf("%s/api/v1/cloud/sync", syncUrl)
|
||||
client := shuffle.GetExternalClient(syncUrl)
|
||||
req, err := http.NewRequest(
|
||||
@@ -5075,6 +5090,11 @@ func handleCloudSetup(resp http.ResponseWriter, request *http.Request) {
|
||||
shuffle.SetCache(ctx, licenseCacheKey, licensedBytes, 1800)
|
||||
}
|
||||
|
||||
if len(responseData.CloudSyncUrl) > 0 {
|
||||
cloudSyncRegionUrlCacheKey := fmt.Sprintf("org_cloudsync_region_url_%s", org.Id)
|
||||
shuffle.SetCache(ctx, cloudSyncRegionUrlCacheKey, []byte(responseData.CloudSyncUrl), 1800)
|
||||
}
|
||||
|
||||
org.SyncConfig = shuffle.SyncConfig{
|
||||
Apikey: responseData.SessionKey,
|
||||
Interval: responseData.IntervalSeconds,
|
||||
|
||||
Reference in New Issue
Block a user