mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
ACL Broken
This commit is contained in:
parent
96ff489777
commit
7c3569a39d
5 changed files with 2050 additions and 8460 deletions
|
@ -29,6 +29,7 @@ You should have received a copy of the GNU General Public License
|
|||
using ShareX.HelpersLib;
|
||||
using ShareX.UploadersLib.Properties;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
@ -51,7 +52,8 @@ public override GenericUploader CreateUploader(UploadersConfig config, TaskRefer
|
|||
return new GoogleCloudStorage(config.GoogleCloudStorageOAuth2Info)
|
||||
{
|
||||
bucket = config.GoogleCloudStorageBucket,
|
||||
domain = config.GoogleCloudStorageDomain
|
||||
domain = config.GoogleCloudStorageDomain,
|
||||
prefix = config.GoogleCloudStorageObjectPrefix
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -92,6 +94,12 @@ public bool GetAccessToken(string code)
|
|||
return googleAuth.GetAccessToken(code);
|
||||
}
|
||||
|
||||
private string GetUploadPath(string fileName)
|
||||
{
|
||||
string path = NameParser.Parse(NameParserType.FolderPath, prefix.Trim('/'));
|
||||
return URLHelpers.CombineURL(path, fileName);
|
||||
}
|
||||
|
||||
public class ObjectACL
|
||||
{
|
||||
public string entity { get; set; }
|
||||
|
@ -104,8 +112,8 @@ public class GoogleCloudStorageResponse
|
|||
}
|
||||
|
||||
public string bucket { get; set; }
|
||||
public string path { get; set; }
|
||||
public string domain { get; set; }
|
||||
public string prefix { get; set; }
|
||||
|
||||
public override UploadResult Upload(Stream stream, string fileName)
|
||||
{
|
||||
|
@ -113,17 +121,14 @@ public override UploadResult Upload(Stream stream, string fileName)
|
|||
|
||||
UploadResult result = new UploadResult();
|
||||
|
||||
path = path + "/";
|
||||
|
||||
string uploadurl = $"https://www.googleapis.com/upload/storage/v1/b/{path}{bucket}/o";
|
||||
string aclurl = $"https://www.googleapis.com/storage/v1/b/{bucket}/o/{path}{fileName}/acl";
|
||||
|
||||
string contentType = Helpers.GetMimeType(fileName);
|
||||
|
||||
string uploadpath = GetUploadPath(fileName);
|
||||
|
||||
Dictionary<string, string> args = new Dictionary<string, string>
|
||||
{
|
||||
{ "uploadType", "media" },
|
||||
{ "name", fileName }
|
||||
{ "name", uploadpath }
|
||||
};
|
||||
|
||||
ObjectACL publicacl = new ObjectACL
|
||||
|
@ -132,21 +137,25 @@ public override UploadResult Upload(Stream stream, string fileName)
|
|||
role = "READER"
|
||||
};
|
||||
|
||||
result.Response = SendRequest(HttpMethod.POST, uploadurl, stream, contentType, args, googleAuth.GetAuthHeaders());
|
||||
result.Response = SendRequest(HttpMethod.POST, $"https://www.googleapis.com/upload/storage/v1/b/{bucket}/o",
|
||||
stream, contentType, args, googleAuth.GetAuthHeaders());
|
||||
string responsename = JsonConvert.DeserializeObject<GoogleCloudStorageResponse>(result.Response).name;
|
||||
|
||||
if (responsename == fileName)
|
||||
Debug.WriteLine(uploadpath);
|
||||
|
||||
if (responsename == uploadpath)
|
||||
{
|
||||
string requestjson = JsonConvert.SerializeObject(publicacl);
|
||||
SendRequest(HttpMethod.POST, aclurl, requestjson, ContentTypeJSON, headers: googleAuth.GetAuthHeaders());
|
||||
SendRequest(HttpMethod.POST, $"https://www.googleapis.com/storage/v1/b/{bucket}/o/{uploadpath}/acl",
|
||||
requestjson, ContentTypeJSON, headers: googleAuth.GetAuthHeaders());
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(domain))
|
||||
{
|
||||
domain = "storage.googleapis.com";
|
||||
domain = "storage.googleapis.com/{bucket}";
|
||||
}
|
||||
|
||||
result.URL = $"https://{domain}/{bucket}/{path}{fileName}";
|
||||
result.URL = $"https://{domain}/{uploadpath}";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -303,6 +303,7 @@ private void InitializeComponent()
|
|||
this.lblAmazonS3AccessKey = new System.Windows.Forms.Label();
|
||||
this.txtAmazonS3AccessKey = new System.Windows.Forms.TextBox();
|
||||
this.tpGoogleCloudStorage = new System.Windows.Forms.TabPage();
|
||||
this.oauth2GoogleCloudStorage = new ShareX.UploadersLib.OAuthControl();
|
||||
this.tpAzureStorage = new System.Windows.Forms.TabPage();
|
||||
this.cbAzureStorageEnvironment = new System.Windows.Forms.ComboBox();
|
||||
this.lblAzureStorageEnvironment = new System.Windows.Forms.Label();
|
||||
|
@ -638,7 +639,10 @@ private void InitializeComponent()
|
|||
this.lblWidthHint = new System.Windows.Forms.Label();
|
||||
this.ttlvMain = new ShareX.HelpersLib.TabToListView();
|
||||
this.actRapidShareAccountType = new ShareX.UploadersLib.AccountTypeControl();
|
||||
this.oauth2GoogleCloudStorage = new ShareX.UploadersLib.OAuthControl();
|
||||
this.txtGoogleCloudStorageBucket = new System.Windows.Forms.TextBox();
|
||||
this.lblGoogleCloudStorageBucket = new System.Windows.Forms.Label();
|
||||
this.txtGoogleCloudStorageDomain = new System.Windows.Forms.TextBox();
|
||||
this.lblGoogleCloudStorageDomain = new System.Windows.Forms.Label();
|
||||
this.tpOtherUploaders.SuspendLayout();
|
||||
this.tcOtherUploaders.SuspendLayout();
|
||||
this.tpTwitter.SuspendLayout();
|
||||
|
@ -2780,11 +2784,24 @@ private void InitializeComponent()
|
|||
//
|
||||
// tpGoogleCloudStorage
|
||||
//
|
||||
this.tpGoogleCloudStorage.Controls.Add(this.lblGoogleCloudStorageDomain);
|
||||
this.tpGoogleCloudStorage.Controls.Add(this.txtGoogleCloudStorageDomain);
|
||||
this.tpGoogleCloudStorage.Controls.Add(this.lblGoogleCloudStorageBucket);
|
||||
this.tpGoogleCloudStorage.Controls.Add(this.txtGoogleCloudStorageBucket);
|
||||
this.tpGoogleCloudStorage.Controls.Add(this.oauth2GoogleCloudStorage);
|
||||
resources.ApplyResources(this.tpGoogleCloudStorage, "tpGoogleCloudStorage");
|
||||
this.tpGoogleCloudStorage.Name = "tpGoogleCloudStorage";
|
||||
this.tpGoogleCloudStorage.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// oauth2GoogleCloudStorage
|
||||
//
|
||||
resources.ApplyResources(this.oauth2GoogleCloudStorage, "oauth2GoogleCloudStorage");
|
||||
this.oauth2GoogleCloudStorage.Name = "oauth2GoogleCloudStorage";
|
||||
this.oauth2GoogleCloudStorage.OpenButtonClicked += new ShareX.UploadersLib.OAuthControl.OpenButtonClickedEventHandler(this.oauth2GoogleCloudStorage_OpenButtonClicked);
|
||||
this.oauth2GoogleCloudStorage.CompleteButtonClicked += new ShareX.UploadersLib.OAuthControl.CompleteButtonClickedEventHandler(this.oauth2GoogleCloudStorage_CompleteButtonClicked);
|
||||
this.oauth2GoogleCloudStorage.ClearButtonClicked += new ShareX.UploadersLib.OAuthControl.ClearButtonclickedEventHandler(this.oauth2GoogleCloudStorage_ClearButtonClicked);
|
||||
this.oauth2GoogleCloudStorage.RefreshButtonClicked += new ShareX.UploadersLib.OAuthControl.RefreshButtonClickedEventHandler(this.oauth2GoogleCloudStorage_RefreshButtonClicked);
|
||||
//
|
||||
// tpAzureStorage
|
||||
//
|
||||
this.tpAzureStorage.BackColor = System.Drawing.SystemColors.Window;
|
||||
|
@ -5203,14 +5220,27 @@ private void InitializeComponent()
|
|||
this.actRapidShareAccountType.Name = "actRapidShareAccountType";
|
||||
this.actRapidShareAccountType.SelectedAccountType = ShareX.UploadersLib.AccountType.Anonymous;
|
||||
//
|
||||
// oauth2GoogleCloudStorage
|
||||
// txtGoogleCloudStorageBucket
|
||||
//
|
||||
resources.ApplyResources(this.oauth2GoogleCloudStorage, "oauth2GoogleCloudStorage");
|
||||
this.oauth2GoogleCloudStorage.Name = "oauth2GoogleCloudStorage";
|
||||
this.oauth2GoogleCloudStorage.OpenButtonClicked += new ShareX.UploadersLib.OAuthControl.OpenButtonClickedEventHandler(this.oauth2GoogleCloudStorage_OpenButtonClicked);
|
||||
this.oauth2GoogleCloudStorage.CompleteButtonClicked += new ShareX.UploadersLib.OAuthControl.CompleteButtonClickedEventHandler(this.oauth2GoogleCloudStorage_CompleteButtonClicked);
|
||||
this.oauth2GoogleCloudStorage.ClearButtonClicked += new ShareX.UploadersLib.OAuthControl.ClearButtonclickedEventHandler(this.oauth2GoogleCloudStorage_ClearButtonClicked);
|
||||
this.oauth2GoogleCloudStorage.RefreshButtonClicked += new ShareX.UploadersLib.OAuthControl.RefreshButtonClickedEventHandler(this.oauth2GoogleCloudStorage_RefreshButtonClicked);
|
||||
resources.ApplyResources(this.txtGoogleCloudStorageBucket, "txtGoogleCloudStorageBucket");
|
||||
this.txtGoogleCloudStorageBucket.Name = "txtGoogleCloudStorageBucket";
|
||||
this.txtGoogleCloudStorageBucket.TextChanged += new System.EventHandler(this.txtGoogleCloudStorageBucket_TextChanged);
|
||||
//
|
||||
// lblGoogleCloudStorageBucket
|
||||
//
|
||||
resources.ApplyResources(this.lblGoogleCloudStorageBucket, "lblGoogleCloudStorageBucket");
|
||||
this.lblGoogleCloudStorageBucket.Name = "lblGoogleCloudStorageBucket";
|
||||
//
|
||||
// txtGoogleCloudStorageDomain
|
||||
//
|
||||
resources.ApplyResources(this.txtGoogleCloudStorageDomain, "txtGoogleCloudStorageDomain");
|
||||
this.txtGoogleCloudStorageDomain.Name = "txtGoogleCloudStorageDomain";
|
||||
this.txtGoogleCloudStorageDomain.TextChanged += new System.EventHandler(this.txtGoogleCloudStorageDomain_TextChanged);
|
||||
//
|
||||
// lblGoogleCloudStorageDomain
|
||||
//
|
||||
resources.ApplyResources(this.lblGoogleCloudStorageDomain, "lblGoogleCloudStorageDomain");
|
||||
this.lblGoogleCloudStorageDomain.Name = "lblGoogleCloudStorageDomain";
|
||||
//
|
||||
// UploadersConfigForm
|
||||
//
|
||||
|
@ -5291,6 +5321,7 @@ private void InitializeComponent()
|
|||
this.gbAmazonS3Advanced.ResumeLayout(false);
|
||||
this.gbAmazonS3Advanced.PerformLayout();
|
||||
this.tpGoogleCloudStorage.ResumeLayout(false);
|
||||
this.tpGoogleCloudStorage.PerformLayout();
|
||||
this.tpAzureStorage.ResumeLayout(false);
|
||||
this.tpAzureStorage.PerformLayout();
|
||||
this.tpGfycat.ResumeLayout(false);
|
||||
|
@ -6000,5 +6031,9 @@ private void InitializeComponent()
|
|||
private System.Windows.Forms.CheckBox cbYouTubeUseShortenedLink;
|
||||
internal System.Windows.Forms.TabPage tpGoogleCloudStorage;
|
||||
private OAuthControl oauth2GoogleCloudStorage;
|
||||
private System.Windows.Forms.TextBox txtGoogleCloudStorageBucket;
|
||||
private System.Windows.Forms.Label lblGoogleCloudStorageBucket;
|
||||
private System.Windows.Forms.TextBox txtGoogleCloudStorageDomain;
|
||||
private System.Windows.Forms.Label lblGoogleCloudStorageDomain;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -739,6 +739,9 @@ public void LoadSettings()
|
|||
oauth2GoogleCloudStorage.Status = OAuthLoginStatus.LoginSuccessful;
|
||||
}
|
||||
|
||||
txtGoogleCloudStorageBucket.Text = Config.GoogleCloudStorageBucket;
|
||||
txtGoogleCloudStorageDomain.Text = Config.GoogleCloudStorageDomain;
|
||||
|
||||
#endregion Google Cloud Storage
|
||||
|
||||
#endregion File uploaders
|
||||
|
@ -3063,6 +3066,16 @@ private void oauth2GoogleCloudStorage_RefreshButtonClicked()
|
|||
OAuth2Refresh(new GoogleCloudStorage(Config.GoogleCloudStorageOAuth2Info), oauth2GoogleCloudStorage);
|
||||
}
|
||||
|
||||
private void txtGoogleCloudStorageBucket_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
Config.GoogleCloudStorageBucket = txtGoogleCloudStorageBucket.Text;
|
||||
}
|
||||
|
||||
private void txtGoogleCloudStorageDomain_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
Config.GoogleCloudStorageDomain = txtGoogleCloudStorageDomain.Text;
|
||||
}
|
||||
|
||||
#endregion Google Cloud Storage
|
||||
|
||||
#endregion File uploaders
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -394,6 +394,7 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
|
|||
public OAuth2Info GoogleCloudStorageOAuth2Info = null;
|
||||
public string GoogleCloudStorageBucket = "";
|
||||
public string GoogleCloudStorageDomain = "";
|
||||
public string GoogleCloudStorageObjectPrefix = "ShareX/%y/%mo";
|
||||
|
||||
#endregion Google Cloud Storage
|
||||
|
||||
|
|
Loading…
Reference in a new issue