mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-07 15:35:47 +12:00
Add custom domain support in program
Form not done
This commit is contained in:
parent
098e5aff64
commit
f2ab7f2f08
|
@ -43,14 +43,15 @@ public class GoogleCloudStorageNewFileUploaderService : FileUploaderService
|
||||||
|
|
||||||
public override bool CheckConfig(UploadersConfig config)
|
public override bool CheckConfig(UploadersConfig config)
|
||||||
{
|
{
|
||||||
return OAuth2Info.CheckOAuth(config.GoogleCloudStorageOAuth2Info);
|
return OAuth2Info.CheckOAuth(config.GoogleCloudStorageOAuth2Info) && !string.IsNullOrEmpty(config.GoogleCloudStorageBucket);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override GenericUploader CreateUploader(UploadersConfig config, TaskReferenceHelper taskInfo)
|
public override GenericUploader CreateUploader(UploadersConfig config, TaskReferenceHelper taskInfo)
|
||||||
{
|
{
|
||||||
return new GoogleCloudStorage(config.GoogleCloudStorageOAuth2Info)
|
return new GoogleCloudStorage(config.GoogleCloudStorageOAuth2Info)
|
||||||
{
|
{
|
||||||
bucket = config.GoogleCloudStorageBucket
|
bucket = config.GoogleCloudStorageBucket,
|
||||||
|
domain = config.GoogleCloudStorageDomain
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,6 +104,8 @@ public class GoogleCloudStorageResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
public string bucket { get; set; }
|
public string bucket { get; set; }
|
||||||
|
public string path { get; set; }
|
||||||
|
public string domain { get; set; }
|
||||||
|
|
||||||
public override UploadResult Upload(Stream stream, string fileName)
|
public override UploadResult Upload(Stream stream, string fileName)
|
||||||
{
|
{
|
||||||
|
@ -110,10 +113,10 @@ public override UploadResult Upload(Stream stream, string fileName)
|
||||||
|
|
||||||
UploadResult result = new UploadResult();
|
UploadResult result = new UploadResult();
|
||||||
|
|
||||||
result.URL = $"https://storage.googleapis.com/{bucket}/{fileName}";
|
path = path + "/";
|
||||||
|
|
||||||
string uploadurl = $"https://www.googleapis.com/upload/storage/v1/b/{bucket}/o";
|
string uploadurl = $"https://www.googleapis.com/upload/storage/v1/b/{path}{bucket}/o";
|
||||||
string aclurl = $"https://www.googleapis.com/storage/v1/b/{bucket}/o/{fileName}/acl";
|
string aclurl = $"https://www.googleapis.com/storage/v1/b/{bucket}/o/{path}{fileName}/acl";
|
||||||
|
|
||||||
string contentType = Helpers.GetMimeType(fileName);
|
string contentType = Helpers.GetMimeType(fileName);
|
||||||
|
|
||||||
|
@ -138,6 +141,13 @@ public override UploadResult Upload(Stream stream, string fileName)
|
||||||
SendRequest(HttpMethod.POST, aclurl, requestjson, ContentTypeJSON, headers: googleAuth.GetAuthHeaders());
|
SendRequest(HttpMethod.POST, aclurl, requestjson, ContentTypeJSON, headers: googleAuth.GetAuthHeaders());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(domain))
|
||||||
|
{
|
||||||
|
domain = "storage.googleapis.com";
|
||||||
|
}
|
||||||
|
|
||||||
|
result.URL = $"https://{domain}/{bucket}/{path}{fileName}";
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -392,7 +392,8 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
|
||||||
#region Google Cloud Storage
|
#region Google Cloud Storage
|
||||||
|
|
||||||
public OAuth2Info GoogleCloudStorageOAuth2Info = null;
|
public OAuth2Info GoogleCloudStorageOAuth2Info = null;
|
||||||
public string GoogleCloudStorageBucket = "cdn.riolu.com";
|
public string GoogleCloudStorageBucket = "";
|
||||||
|
public string GoogleCloudStorageDomain = "";
|
||||||
|
|
||||||
#endregion Google Cloud Storage
|
#endregion Google Cloud Storage
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue