mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-02 18:26:27 +13:00
Add support for extensionless upload on GCS
This commit is contained in:
parent
33a3a82012
commit
b8d2a0b9da
5 changed files with 1670 additions and 8289 deletions
|
@ -51,7 +51,10 @@ public override GenericUploader CreateUploader(UploadersConfig config, TaskRefer
|
||||||
{
|
{
|
||||||
Bucket = config.GoogleCloudStorageBucket,
|
Bucket = config.GoogleCloudStorageBucket,
|
||||||
Domain = config.GoogleCloudStorageDomain,
|
Domain = config.GoogleCloudStorageDomain,
|
||||||
Prefix = config.GoogleCloudStorageObjectPrefix
|
Prefix = config.GoogleCloudStorageObjectPrefix,
|
||||||
|
RemoveExtensionImage = config.GoogleCloudStorageRemoveExtensionImage,
|
||||||
|
RemoveExtensionText = config.GoogleCloudStorageRemoveExtensionText,
|
||||||
|
RemoveExtensionVideo = config.GoogleCloudStorageRemoveExtensionVideo
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +66,9 @@ public sealed class GoogleCloudStorage : FileUploader, IOAuth2
|
||||||
public string Bucket { get; set; }
|
public string Bucket { get; set; }
|
||||||
public string Domain { get; set; }
|
public string Domain { get; set; }
|
||||||
public string Prefix { get; set; }
|
public string Prefix { get; set; }
|
||||||
|
public bool RemoveExtensionImage { get; set; }
|
||||||
|
public bool RemoveExtensionText { get; set; }
|
||||||
|
public bool RemoveExtensionVideo { get; set; }
|
||||||
|
|
||||||
public OAuth2Info AuthInfo => googleAuth.AuthInfo;
|
public OAuth2Info AuthInfo => googleAuth.AuthInfo;
|
||||||
|
|
||||||
|
@ -100,10 +106,20 @@ public override UploadResult Upload(Stream stream, string fileName)
|
||||||
{
|
{
|
||||||
if (!CheckAuthorization()) return null;
|
if (!CheckAuthorization()) return null;
|
||||||
|
|
||||||
|
string contentType = Helpers.GetMimeType(fileName);
|
||||||
|
|
||||||
|
if ((RemoveExtensionImage && Helpers.IsImageFile(fileName)) ||
|
||||||
|
(RemoveExtensionText && Helpers.IsTextFile(fileName)) ||
|
||||||
|
(RemoveExtensionVideo && Helpers.IsVideoFile(fileName)))
|
||||||
|
{
|
||||||
|
fileName = Path.GetFileNameWithoutExtension(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
string uploadpath = GetUploadPath(fileName);
|
string uploadpath = GetUploadPath(fileName);
|
||||||
|
|
||||||
GoogleCloudStorageMetadata metadata = new GoogleCloudStorageMetadata
|
GoogleCloudStorageMetadata metadata = new GoogleCloudStorageMetadata
|
||||||
{
|
{
|
||||||
|
contentType = contentType,
|
||||||
name = uploadpath,
|
name = uploadpath,
|
||||||
acl = new GoogleCloudStorageAcl[]
|
acl = new GoogleCloudStorageAcl[]
|
||||||
{
|
{
|
||||||
|
@ -170,6 +186,7 @@ private class GoogleCloudStorageResponse
|
||||||
|
|
||||||
private class GoogleCloudStorageMetadata
|
private class GoogleCloudStorageMetadata
|
||||||
{
|
{
|
||||||
|
public string contentType { get; set; }
|
||||||
public string name { get; set; }
|
public string name { get; set; }
|
||||||
public GoogleCloudStorageAcl[] acl { get; set; }
|
public GoogleCloudStorageAcl[] acl { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,6 +337,10 @@ private void InitializeComponent()
|
||||||
this.lblAmazonS3AccessKey = new System.Windows.Forms.Label();
|
this.lblAmazonS3AccessKey = new System.Windows.Forms.Label();
|
||||||
this.txtAmazonS3AccessKey = new System.Windows.Forms.TextBox();
|
this.txtAmazonS3AccessKey = new System.Windows.Forms.TextBox();
|
||||||
this.tpGoogleCloudStorage = new System.Windows.Forms.TabPage();
|
this.tpGoogleCloudStorage = new System.Windows.Forms.TabPage();
|
||||||
|
this.lblGoogleCloudStorageStripExtension = new System.Windows.Forms.Label();
|
||||||
|
this.cbGoogleCloudStorageStripExtensionText = new System.Windows.Forms.CheckBox();
|
||||||
|
this.cbGoogleCloudStorageStripExtensionVideo = new System.Windows.Forms.CheckBox();
|
||||||
|
this.cbGoogleCloudStorageStripExtensionImage = new System.Windows.Forms.CheckBox();
|
||||||
this.lblGoogleCloudStoragePathPreview = new System.Windows.Forms.Label();
|
this.lblGoogleCloudStoragePathPreview = new System.Windows.Forms.Label();
|
||||||
this.lblGoogleCloudStoragePathPreviewLabel = new System.Windows.Forms.Label();
|
this.lblGoogleCloudStoragePathPreviewLabel = new System.Windows.Forms.Label();
|
||||||
this.txtGoogleCloudStorageObjectPrefix = new System.Windows.Forms.TextBox();
|
this.txtGoogleCloudStorageObjectPrefix = new System.Windows.Forms.TextBox();
|
||||||
|
@ -2907,6 +2911,10 @@ private void InitializeComponent()
|
||||||
//
|
//
|
||||||
// tpGoogleCloudStorage
|
// tpGoogleCloudStorage
|
||||||
//
|
//
|
||||||
|
this.tpGoogleCloudStorage.Controls.Add(this.lblGoogleCloudStorageStripExtension);
|
||||||
|
this.tpGoogleCloudStorage.Controls.Add(this.cbGoogleCloudStorageStripExtensionText);
|
||||||
|
this.tpGoogleCloudStorage.Controls.Add(this.cbGoogleCloudStorageStripExtensionVideo);
|
||||||
|
this.tpGoogleCloudStorage.Controls.Add(this.cbGoogleCloudStorageStripExtensionImage);
|
||||||
this.tpGoogleCloudStorage.Controls.Add(this.lblGoogleCloudStoragePathPreview);
|
this.tpGoogleCloudStorage.Controls.Add(this.lblGoogleCloudStoragePathPreview);
|
||||||
this.tpGoogleCloudStorage.Controls.Add(this.lblGoogleCloudStoragePathPreviewLabel);
|
this.tpGoogleCloudStorage.Controls.Add(this.lblGoogleCloudStoragePathPreviewLabel);
|
||||||
this.tpGoogleCloudStorage.Controls.Add(this.txtGoogleCloudStorageObjectPrefix);
|
this.tpGoogleCloudStorage.Controls.Add(this.txtGoogleCloudStorageObjectPrefix);
|
||||||
|
@ -2920,6 +2928,32 @@ private void InitializeComponent()
|
||||||
this.tpGoogleCloudStorage.Name = "tpGoogleCloudStorage";
|
this.tpGoogleCloudStorage.Name = "tpGoogleCloudStorage";
|
||||||
this.tpGoogleCloudStorage.UseVisualStyleBackColor = true;
|
this.tpGoogleCloudStorage.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
|
// lblGoogleCloudStorageStripExtension
|
||||||
|
//
|
||||||
|
resources.ApplyResources(this.lblGoogleCloudStorageStripExtension, "lblGoogleCloudStorageStripExtension");
|
||||||
|
this.lblGoogleCloudStorageStripExtension.Name = "lblGoogleCloudStorageStripExtension";
|
||||||
|
//
|
||||||
|
// cbGoogleCloudStorageStripExtensionText
|
||||||
|
//
|
||||||
|
resources.ApplyResources(this.cbGoogleCloudStorageStripExtensionText, "cbGoogleCloudStorageStripExtensionText");
|
||||||
|
this.cbGoogleCloudStorageStripExtensionText.Name = "cbGoogleCloudStorageStripExtensionText";
|
||||||
|
this.cbGoogleCloudStorageStripExtensionText.UseVisualStyleBackColor = true;
|
||||||
|
this.cbGoogleCloudStorageStripExtensionText.CheckedChanged += new System.EventHandler(this.cbGoogleCloudStorageStripExtensionText_CheckedChanged);
|
||||||
|
//
|
||||||
|
// cbGoogleCloudStorageStripExtensionVideo
|
||||||
|
//
|
||||||
|
resources.ApplyResources(this.cbGoogleCloudStorageStripExtensionVideo, "cbGoogleCloudStorageStripExtensionVideo");
|
||||||
|
this.cbGoogleCloudStorageStripExtensionVideo.Name = "cbGoogleCloudStorageStripExtensionVideo";
|
||||||
|
this.cbGoogleCloudStorageStripExtensionVideo.UseVisualStyleBackColor = true;
|
||||||
|
this.cbGoogleCloudStorageStripExtensionVideo.CheckedChanged += new System.EventHandler(this.cbGoogleCloudStorageStripExtensionVideo_CheckedChanged);
|
||||||
|
//
|
||||||
|
// cbGoogleCloudStorageStripExtensionImage
|
||||||
|
//
|
||||||
|
resources.ApplyResources(this.cbGoogleCloudStorageStripExtensionImage, "cbGoogleCloudStorageStripExtensionImage");
|
||||||
|
this.cbGoogleCloudStorageStripExtensionImage.Name = "cbGoogleCloudStorageStripExtensionImage";
|
||||||
|
this.cbGoogleCloudStorageStripExtensionImage.UseVisualStyleBackColor = true;
|
||||||
|
this.cbGoogleCloudStorageStripExtensionImage.CheckedChanged += new System.EventHandler(this.cbGoogleCloudStorageStripExtensionImage_CheckedChanged);
|
||||||
|
//
|
||||||
// lblGoogleCloudStoragePathPreview
|
// lblGoogleCloudStoragePathPreview
|
||||||
//
|
//
|
||||||
resources.ApplyResources(this.lblGoogleCloudStoragePathPreview, "lblGoogleCloudStoragePathPreview");
|
resources.ApplyResources(this.lblGoogleCloudStoragePathPreview, "lblGoogleCloudStoragePathPreview");
|
||||||
|
@ -6373,5 +6407,9 @@ private void InitializeComponent()
|
||||||
private System.Windows.Forms.Label lblKuttPassword;
|
private System.Windows.Forms.Label lblKuttPassword;
|
||||||
private System.Windows.Forms.TextBox txtKuttPassword;
|
private System.Windows.Forms.TextBox txtKuttPassword;
|
||||||
internal System.Windows.Forms.TabPage tpKutt;
|
internal System.Windows.Forms.TabPage tpKutt;
|
||||||
|
private System.Windows.Forms.Label lblGoogleCloudStorageStripExtension;
|
||||||
|
private System.Windows.Forms.CheckBox cbGoogleCloudStorageStripExtensionText;
|
||||||
|
private System.Windows.Forms.CheckBox cbGoogleCloudStorageStripExtensionVideo;
|
||||||
|
private System.Windows.Forms.CheckBox cbGoogleCloudStorageStripExtensionImage;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -759,6 +759,10 @@ private void LoadFileUploaderSettings()
|
||||||
txtGoogleCloudStorageDomain.Text = Config.GoogleCloudStorageDomain;
|
txtGoogleCloudStorageDomain.Text = Config.GoogleCloudStorageDomain;
|
||||||
txtGoogleCloudStorageObjectPrefix.Text = Config.GoogleCloudStorageObjectPrefix;
|
txtGoogleCloudStorageObjectPrefix.Text = Config.GoogleCloudStorageObjectPrefix;
|
||||||
|
|
||||||
|
cbGoogleCloudStorageStripExtensionImage.Checked = Config.GoogleCloudStorageRemoveExtensionImage;
|
||||||
|
cbGoogleCloudStorageStripExtensionVideo.Checked = Config.GoogleCloudStorageRemoveExtensionVideo;
|
||||||
|
cbGoogleCloudStorageStripExtensionText.Checked = Config.GoogleCloudStorageRemoveExtensionText;
|
||||||
|
|
||||||
#endregion Google Cloud Storage
|
#endregion Google Cloud Storage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3138,6 +3142,21 @@ private void txtGoogleCloudStorageObjectPrefix_TextChanged(object sender, EventA
|
||||||
UpdateGoogleCloudStorageStatus();
|
UpdateGoogleCloudStorageStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void cbGoogleCloudStorageStripExtensionImage_CheckedChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Config.GoogleCloudStorageRemoveExtensionImage = cbGoogleCloudStorageStripExtensionImage.Checked;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cbGoogleCloudStorageStripExtensionVideo_CheckedChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Config.GoogleCloudStorageRemoveExtensionVideo = cbGoogleCloudStorageStripExtensionVideo.Checked;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cbGoogleCloudStorageStripExtensionText_CheckedChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Config.GoogleCloudStorageRemoveExtensionText = cbGoogleCloudStorageStripExtensionText.Checked;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion Google Cloud Storage
|
#endregion Google Cloud Storage
|
||||||
|
|
||||||
#endregion File uploaders
|
#endregion File uploaders
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -410,6 +410,9 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
|
||||||
public string GoogleCloudStorageBucket = "";
|
public string GoogleCloudStorageBucket = "";
|
||||||
public string GoogleCloudStorageDomain = "";
|
public string GoogleCloudStorageDomain = "";
|
||||||
public string GoogleCloudStorageObjectPrefix = "ShareX/%y/%mo";
|
public string GoogleCloudStorageObjectPrefix = "ShareX/%y/%mo";
|
||||||
|
public bool GoogleCloudStorageRemoveExtensionImage = false;
|
||||||
|
public bool GoogleCloudStorageRemoveExtensionVideo = false;
|
||||||
|
public bool GoogleCloudStorageRemoveExtensionText = false;
|
||||||
|
|
||||||
#endregion Google Cloud Storage
|
#endregion Google Cloud Storage
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue