mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-02 18:26:27 +13:00
Added "Use direct link" checkbox to Google Drive uploader settings
This commit is contained in:
parent
6d9331ceb5
commit
3a2527b003
5 changed files with 68 additions and 2 deletions
|
@ -24,9 +24,11 @@ You should have received a copy of the GNU General Public License
|
||||||
#endregion License Information (GPL v3)
|
#endregion License Information (GPL v3)
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Web;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ShareX.UploadersLib.FileUploaders
|
namespace ShareX.UploadersLib.FileUploaders
|
||||||
|
@ -45,6 +47,7 @@ public override GenericUploader CreateUploader(UploadersConfig config, TaskRefer
|
||||||
return new GoogleDrive(config.GoogleDriveOAuth2Info)
|
return new GoogleDrive(config.GoogleDriveOAuth2Info)
|
||||||
{
|
{
|
||||||
IsPublic = config.GoogleDriveIsPublic,
|
IsPublic = config.GoogleDriveIsPublic,
|
||||||
|
DirectLink = config.GoogleDriveDirectLink,
|
||||||
FolderID = config.GoogleDriveUseFolder ? config.GoogleDriveFolderID : null
|
FolderID = config.GoogleDriveUseFolder ? config.GoogleDriveFolderID : null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -56,6 +59,7 @@ public sealed class GoogleDrive : FileUploader, IOAuth2
|
||||||
{
|
{
|
||||||
public OAuth2Info AuthInfo { get; set; }
|
public OAuth2Info AuthInfo { get; set; }
|
||||||
public bool IsPublic { get; set; }
|
public bool IsPublic { get; set; }
|
||||||
|
public bool DirectLink { get; set; }
|
||||||
public string FolderID { get; set; }
|
public string FolderID { get; set; }
|
||||||
|
|
||||||
public GoogleDrive(OAuth2Info oauth)
|
public GoogleDrive(OAuth2Info oauth)
|
||||||
|
@ -258,9 +262,23 @@ public override UploadResult Upload(Stream stream, string fileName)
|
||||||
SetPermissions(upload.id, GoogleDrivePermissionRole.reader, GoogleDrivePermissionType.anyone, "", true);
|
SetPermissions(upload.id, GoogleDrivePermissionRole.reader, GoogleDrivePermissionType.anyone, "", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DirectLink)
|
||||||
|
{
|
||||||
|
Uri webContentLink = new Uri(upload.webContentLink);
|
||||||
|
|
||||||
|
string leftPart = webContentLink.GetLeftPart(UriPartial.Path);
|
||||||
|
|
||||||
|
NameValueCollection queryString = HttpUtility.ParseQueryString(webContentLink.Query);
|
||||||
|
queryString.Remove("export");
|
||||||
|
|
||||||
|
result.URL = $"{leftPart}?{queryString}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
result.URL = upload.alternateLink;
|
result.URL = upload.alternateLink;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -269,6 +287,7 @@ public class GoogleDriveFile
|
||||||
{
|
{
|
||||||
public string id { get; set; }
|
public string id { get; set; }
|
||||||
public string alternateLink { get; set; }
|
public string alternateLink { get; set; }
|
||||||
|
public string webContentLink { get; set; }
|
||||||
public string title { get; set; }
|
public string title { get; set; }
|
||||||
public string description { get; set; }
|
public string description { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,6 +191,7 @@ private void InitializeComponent()
|
||||||
this.cbOneDriveCreateShareableLink = new System.Windows.Forms.CheckBox();
|
this.cbOneDriveCreateShareableLink = new System.Windows.Forms.CheckBox();
|
||||||
this.oAuth2OneDrive = new ShareX.UploadersLib.OAuthControl();
|
this.oAuth2OneDrive = new ShareX.UploadersLib.OAuthControl();
|
||||||
this.tpGoogleDrive = new System.Windows.Forms.TabPage();
|
this.tpGoogleDrive = new System.Windows.Forms.TabPage();
|
||||||
|
this.cbGoogleDriveDirectLink = new System.Windows.Forms.CheckBox();
|
||||||
this.cbGoogleDriveUseFolder = new System.Windows.Forms.CheckBox();
|
this.cbGoogleDriveUseFolder = new System.Windows.Forms.CheckBox();
|
||||||
this.txtGoogleDriveFolderID = new System.Windows.Forms.TextBox();
|
this.txtGoogleDriveFolderID = new System.Windows.Forms.TextBox();
|
||||||
this.lblGoogleDriveFolderID = new System.Windows.Forms.Label();
|
this.lblGoogleDriveFolderID = new System.Windows.Forms.Label();
|
||||||
|
@ -1826,6 +1827,7 @@ private void InitializeComponent()
|
||||||
//
|
//
|
||||||
// tpGoogleDrive
|
// tpGoogleDrive
|
||||||
//
|
//
|
||||||
|
this.tpGoogleDrive.Controls.Add(this.cbGoogleDriveDirectLink);
|
||||||
this.tpGoogleDrive.Controls.Add(this.cbGoogleDriveUseFolder);
|
this.tpGoogleDrive.Controls.Add(this.cbGoogleDriveUseFolder);
|
||||||
this.tpGoogleDrive.Controls.Add(this.txtGoogleDriveFolderID);
|
this.tpGoogleDrive.Controls.Add(this.txtGoogleDriveFolderID);
|
||||||
this.tpGoogleDrive.Controls.Add(this.lblGoogleDriveFolderID);
|
this.tpGoogleDrive.Controls.Add(this.lblGoogleDriveFolderID);
|
||||||
|
@ -1837,6 +1839,13 @@ private void InitializeComponent()
|
||||||
this.tpGoogleDrive.Name = "tpGoogleDrive";
|
this.tpGoogleDrive.Name = "tpGoogleDrive";
|
||||||
this.tpGoogleDrive.UseVisualStyleBackColor = true;
|
this.tpGoogleDrive.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
|
// cbGoogleDriveDirectLink
|
||||||
|
//
|
||||||
|
resources.ApplyResources(this.cbGoogleDriveDirectLink, "cbGoogleDriveDirectLink");
|
||||||
|
this.cbGoogleDriveDirectLink.Name = "cbGoogleDriveDirectLink";
|
||||||
|
this.cbGoogleDriveDirectLink.UseVisualStyleBackColor = true;
|
||||||
|
this.cbGoogleDriveDirectLink.CheckedChanged += new System.EventHandler(this.cbGoogleDriveDirectLink_CheckedChanged);
|
||||||
|
//
|
||||||
// cbGoogleDriveUseFolder
|
// cbGoogleDriveUseFolder
|
||||||
//
|
//
|
||||||
resources.ApplyResources(this.cbGoogleDriveUseFolder, "cbGoogleDriveUseFolder");
|
resources.ApplyResources(this.cbGoogleDriveUseFolder, "cbGoogleDriveUseFolder");
|
||||||
|
@ -4977,5 +4986,6 @@ private void InitializeComponent()
|
||||||
private System.Windows.Forms.TextBox txtEmailAutomaticSendTo;
|
private System.Windows.Forms.TextBox txtEmailAutomaticSendTo;
|
||||||
private System.Windows.Forms.CheckBox cbEmailAutomaticSend;
|
private System.Windows.Forms.CheckBox cbEmailAutomaticSend;
|
||||||
private System.Windows.Forms.Button btnLithiioGetAPIKey;
|
private System.Windows.Forms.Button btnLithiioGetAPIKey;
|
||||||
|
private System.Windows.Forms.CheckBox cbGoogleDriveDirectLink;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -370,6 +370,7 @@ public void LoadSettings()
|
||||||
}
|
}
|
||||||
|
|
||||||
cbGoogleDriveIsPublic.Checked = Config.GoogleDriveIsPublic;
|
cbGoogleDriveIsPublic.Checked = Config.GoogleDriveIsPublic;
|
||||||
|
cbGoogleDriveDirectLink.Checked = Config.GoogleDriveDirectLink;
|
||||||
cbGoogleDriveUseFolder.Checked = Config.GoogleDriveUseFolder;
|
cbGoogleDriveUseFolder.Checked = Config.GoogleDriveUseFolder;
|
||||||
txtGoogleDriveFolderID.Enabled = Config.GoogleDriveUseFolder;
|
txtGoogleDriveFolderID.Enabled = Config.GoogleDriveUseFolder;
|
||||||
txtGoogleDriveFolderID.Text = Config.GoogleDriveFolderID;
|
txtGoogleDriveFolderID.Text = Config.GoogleDriveFolderID;
|
||||||
|
@ -1366,6 +1367,11 @@ private void cbGoogleDriveIsPublic_CheckedChanged(object sender, EventArgs e)
|
||||||
Config.GoogleDriveIsPublic = cbGoogleDriveIsPublic.Checked;
|
Config.GoogleDriveIsPublic = cbGoogleDriveIsPublic.Checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void cbGoogleDriveDirectLink_CheckedChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Config.GoogleDriveDirectLink = cbGoogleDriveDirectLink.Checked;
|
||||||
|
}
|
||||||
|
|
||||||
private void cbGoogleDriveUseFolder_CheckedChanged(object sender, EventArgs e)
|
private void cbGoogleDriveUseFolder_CheckedChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Config.GoogleDriveUseFolder = cbGoogleDriveUseFolder.Checked;
|
Config.GoogleDriveUseFolder = cbGoogleDriveUseFolder.Checked;
|
||||||
|
|
|
@ -4203,6 +4203,36 @@ store.book[0].title</value>
|
||||||
<data name=">>tpOneDrive.ZOrder" xml:space="preserve">
|
<data name=">>tpOneDrive.ZOrder" xml:space="preserve">
|
||||||
<value>2</value>
|
<value>2</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="cbGoogleDriveDirectLink.AutoSize" type="System.Boolean, mscorlib">
|
||||||
|
<value>True</value>
|
||||||
|
</data>
|
||||||
|
<data name="cbGoogleDriveDirectLink.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
|
||||||
|
<value>NoControl</value>
|
||||||
|
</data>
|
||||||
|
<data name="cbGoogleDriveDirectLink.Location" type="System.Drawing.Point, System.Drawing">
|
||||||
|
<value>16, 287</value>
|
||||||
|
</data>
|
||||||
|
<data name="cbGoogleDriveDirectLink.Size" type="System.Drawing.Size, System.Drawing">
|
||||||
|
<value>73, 17</value>
|
||||||
|
</data>
|
||||||
|
<data name="cbGoogleDriveDirectLink.TabIndex" type="System.Int32, mscorlib">
|
||||||
|
<value>13</value>
|
||||||
|
</data>
|
||||||
|
<data name="cbGoogleDriveDirectLink.Text" xml:space="preserve">
|
||||||
|
<value>Use direct link</value>
|
||||||
|
</data>
|
||||||
|
<data name=">>cbGoogleDriveDirectLink.Name" xml:space="preserve">
|
||||||
|
<value>cbGoogleDriveDirectLink</value>
|
||||||
|
</data>
|
||||||
|
<data name=">>cbGoogleDriveDirectLink.Type" xml:space="preserve">
|
||||||
|
<value>System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</data>
|
||||||
|
<data name=">>cbGoogleDriveDirectLink.Parent" xml:space="preserve">
|
||||||
|
<value>tpGoogleDrive</value>
|
||||||
|
</data>
|
||||||
|
<data name=">>cbGoogleDriveDirectLink.ZOrder" xml:space="preserve">
|
||||||
|
<value>0</value>
|
||||||
|
</data>
|
||||||
<data name="cbGoogleDriveUseFolder.AutoSize" type="System.Boolean, mscorlib">
|
<data name="cbGoogleDriveUseFolder.AutoSize" type="System.Boolean, mscorlib">
|
||||||
<value>True</value>
|
<value>True</value>
|
||||||
</data>
|
</data>
|
||||||
|
|
|
@ -152,6 +152,7 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
|
||||||
|
|
||||||
public OAuth2Info GoogleDriveOAuth2Info = null;
|
public OAuth2Info GoogleDriveOAuth2Info = null;
|
||||||
public bool GoogleDriveIsPublic = true;
|
public bool GoogleDriveIsPublic = true;
|
||||||
|
public bool GoogleDriveDirectLink = false;
|
||||||
public bool GoogleDriveUseFolder = false;
|
public bool GoogleDriveUseFolder = false;
|
||||||
public string GoogleDriveFolderID = "";
|
public string GoogleDriveFolderID = "";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue