mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-02 18:26:27 +13:00
Added in everything else for Up1 support
This commit is contained in:
parent
8ea5fa7608
commit
7e3265854e
8 changed files with 207 additions and 7 deletions
|
@ -90,6 +90,8 @@ public enum FileDestination
|
||||||
GoogleDrive,
|
GoogleDrive,
|
||||||
[Description("Copy")]
|
[Description("Copy")]
|
||||||
Copy,
|
Copy,
|
||||||
|
[Description("Up1")]
|
||||||
|
Up1,
|
||||||
//[Description("hubiC")]
|
//[Description("hubiC")]
|
||||||
//Hubic,
|
//Hubic,
|
||||||
[Description("Box")]
|
[Description("Box")]
|
||||||
|
@ -298,4 +300,4 @@ public enum OAuthLoginStatus
|
||||||
LoginSuccessful,
|
LoginSuccessful,
|
||||||
LoginFailed
|
LoginFailed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
114
ShareX.UploadersLib/FileUploaders/Up1.cs
Normal file
114
ShareX.UploadersLib/FileUploaders/Up1.cs
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Org.BouncyCastle.Crypto.Engines;
|
||||||
|
using Org.BouncyCastle.Crypto.Modes;
|
||||||
|
using Org.BouncyCastle.Crypto.Parameters;
|
||||||
|
using ShareX.HelpersLib;
|
||||||
|
|
||||||
|
|
||||||
|
namespace ShareX.UploadersLib.FileUploaders
|
||||||
|
{
|
||||||
|
public sealed class Up1 : FileUploader
|
||||||
|
{
|
||||||
|
private const int MacSize = 64;
|
||||||
|
|
||||||
|
public string ApiKey { get; set; }
|
||||||
|
public string SystemUrl { get; set; }
|
||||||
|
|
||||||
|
public Up1(string systemUrl, string apiKey)
|
||||||
|
{
|
||||||
|
SystemUrl = systemUrl;
|
||||||
|
ApiKey = apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static string UrlBase64Encode(byte[] input)
|
||||||
|
{
|
||||||
|
return Convert.ToBase64String(input).Replace("=", "").Replace("+", "-").Replace("/", "_");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Stream Encrypt(Stream stream, out string seed_encoded, out string ident_encoded, string fileName)
|
||||||
|
{
|
||||||
|
RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider();
|
||||||
|
byte[] seed = new byte[16];
|
||||||
|
rngCsp.GetBytes(seed);
|
||||||
|
seed_encoded = UrlBase64Encode(seed);
|
||||||
|
|
||||||
|
SHA512CryptoServiceProvider sha512csp = new SHA512CryptoServiceProvider();
|
||||||
|
byte[] seed_result = sha512csp.ComputeHash(seed);
|
||||||
|
byte[] key = new byte[32];
|
||||||
|
Buffer.BlockCopy(seed_result, 0, key, 0, 32);
|
||||||
|
|
||||||
|
byte[] iv = new byte[16];
|
||||||
|
Buffer.BlockCopy(seed_result, 32, iv, 0, 16);
|
||||||
|
|
||||||
|
byte[] ident = new byte[16];
|
||||||
|
Buffer.BlockCopy(seed_result, 48, ident, 0, 16);
|
||||||
|
ident_encoded = UrlBase64Encode(ident);
|
||||||
|
var fi = new FileInfo(fileName);
|
||||||
|
|
||||||
|
Dictionary<string, string> args = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
// text files aren't detected well by the "ClouDeveloper" mime type library, use ShareX's builtin list first.
|
||||||
|
if (Helpers.IsTextFile(fileName))
|
||||||
|
{
|
||||||
|
args["mime"] = "text/plain";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var mimeOpts = ClouDeveloper.Mime.MediaTypeNames.GetMediaTypeNames(fi.Extension).ToList();
|
||||||
|
args["mime"] = mimeOpts.Count > 0 ? mimeOpts[0] : "image/png";
|
||||||
|
}
|
||||||
|
args["name"] = fileName;
|
||||||
|
|
||||||
|
byte[] d = Encoding.BigEndianUnicode.GetBytes(JsonConvert.SerializeObject(args));
|
||||||
|
|
||||||
|
byte[] rawdata = d.Concat(new byte[] { 0, 0 }).Concat(stream.GetBytes()).ToArray();
|
||||||
|
|
||||||
|
int l = FindIVLen(rawdata.Length);
|
||||||
|
byte[] civ = new byte[l];
|
||||||
|
Array.Copy(iv, civ, l);
|
||||||
|
KeyParameter key_param = new KeyParameter(key);
|
||||||
|
var ccmparams = new CcmParameters(key_param, MacSize, civ, new byte[0]);
|
||||||
|
var ccmMode = new CcmBlockCipher(new AesFastEngine());
|
||||||
|
ccmMode.Init(true, ccmparams);
|
||||||
|
var encBytes = new byte[ccmMode.GetOutputSize(rawdata.Length)];
|
||||||
|
var res = ccmMode.ProcessBytes(rawdata, 0, rawdata.Length, encBytes, 0);
|
||||||
|
ccmMode.DoFinal(encBytes, res);
|
||||||
|
|
||||||
|
return new MemoryStream(encBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int FindIVLen(int bufferLength)
|
||||||
|
{
|
||||||
|
if (bufferLength < 0xFFFF) return 15 - 2;
|
||||||
|
if (bufferLength < 0xFFFFFF) return 15 - 3;
|
||||||
|
return 15 - 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override UploadResult Upload(Stream stream, string fileName)
|
||||||
|
{
|
||||||
|
string seed, ident;
|
||||||
|
Stream encryptedStream = Encrypt(stream, out seed, out ident, fileName);
|
||||||
|
Dictionary<string, string> args = new Dictionary<string, string>();
|
||||||
|
args["ident"] = ident;
|
||||||
|
args["api_key"] = ApiKey;
|
||||||
|
UploadResult result = UploadData(encryptedStream, SystemUrl + "/up", "blob", "file", args);
|
||||||
|
|
||||||
|
if (result.IsSuccess)
|
||||||
|
{
|
||||||
|
Dictionary<string, string> values = JsonConvert.DeserializeObject<Dictionary<string, string>>(result.Response);
|
||||||
|
result.URL = SystemUrl + "/#" + seed;
|
||||||
|
result.DeletionURL = SystemUrl + "/del?ident=" + ident + "&delkey=" + values["delkey"];
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -428,6 +428,11 @@ private void InitializeComponent()
|
||||||
this.atcGoogleURLShortenerAccountType = new ShareX.UploadersLib.AccountTypeControl();
|
this.atcGoogleURLShortenerAccountType = new ShareX.UploadersLib.AccountTypeControl();
|
||||||
this.oauthTwitter = new ShareX.UploadersLib.OAuthControl();
|
this.oauthTwitter = new ShareX.UploadersLib.OAuthControl();
|
||||||
this.actRapidShareAccountType = new ShareX.UploadersLib.AccountTypeControl();
|
this.actRapidShareAccountType = new ShareX.UploadersLib.AccountTypeControl();
|
||||||
|
this.tpUp1 = new System.Windows.Forms.TabPage();
|
||||||
|
this.txtUp1Key = new System.Windows.Forms.TextBox();
|
||||||
|
this.txtUp1Host = new System.Windows.Forms.TextBox();
|
||||||
|
this.lblUp1Key = new System.Windows.Forms.Label();
|
||||||
|
this.lblUp1Host = new System.Windows.Forms.Label();
|
||||||
this.tpOtherUploaders.SuspendLayout();
|
this.tpOtherUploaders.SuspendLayout();
|
||||||
this.tcOtherUploaders.SuspendLayout();
|
this.tcOtherUploaders.SuspendLayout();
|
||||||
this.tpTwitter.SuspendLayout();
|
this.tpTwitter.SuspendLayout();
|
||||||
|
@ -489,6 +494,7 @@ private void InitializeComponent()
|
||||||
this.tpPicasa.SuspendLayout();
|
this.tpPicasa.SuspendLayout();
|
||||||
this.tpChevereto.SuspendLayout();
|
this.tpChevereto.SuspendLayout();
|
||||||
this.tcUploaders.SuspendLayout();
|
this.tcUploaders.SuspendLayout();
|
||||||
|
this.tpUp1.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// txtRapidSharePremiumUserName
|
// txtRapidSharePremiumUserName
|
||||||
|
@ -1202,6 +1208,7 @@ private void InitializeComponent()
|
||||||
this.tcFileUploaders.Controls.Add(this.tpGoogleDrive);
|
this.tcFileUploaders.Controls.Add(this.tpGoogleDrive);
|
||||||
this.tcFileUploaders.Controls.Add(this.tpBox);
|
this.tcFileUploaders.Controls.Add(this.tpBox);
|
||||||
this.tcFileUploaders.Controls.Add(this.tpCopy);
|
this.tcFileUploaders.Controls.Add(this.tpCopy);
|
||||||
|
this.tcFileUploaders.Controls.Add(this.tpUp1);
|
||||||
this.tcFileUploaders.Controls.Add(this.tpHubic);
|
this.tcFileUploaders.Controls.Add(this.tpHubic);
|
||||||
this.tcFileUploaders.Controls.Add(this.tpAmazonS3);
|
this.tcFileUploaders.Controls.Add(this.tpAmazonS3);
|
||||||
this.tcFileUploaders.Controls.Add(this.tpMega);
|
this.tcFileUploaders.Controls.Add(this.tpMega);
|
||||||
|
@ -3398,6 +3405,40 @@ private void InitializeComponent()
|
||||||
resources.ApplyResources(this.actRapidShareAccountType, "actRapidShareAccountType");
|
resources.ApplyResources(this.actRapidShareAccountType, "actRapidShareAccountType");
|
||||||
this.actRapidShareAccountType.Name = "actRapidShareAccountType";
|
this.actRapidShareAccountType.Name = "actRapidShareAccountType";
|
||||||
this.actRapidShareAccountType.SelectedAccountType = ShareX.UploadersLib.AccountType.Anonymous;
|
this.actRapidShareAccountType.SelectedAccountType = ShareX.UploadersLib.AccountType.Anonymous;
|
||||||
|
|
||||||
|
//
|
||||||
|
+ // tpUp1
|
||||||
|
+ //
|
||||||
|
+ this.tpUp1.Controls.Add(this.txtUp1Key);
|
||||||
|
+ this.tpUp1.Controls.Add(this.txtUp1Host);
|
||||||
|
+ this.tpUp1.Controls.Add(this.lblUp1Key);
|
||||||
|
+ this.tpUp1.Controls.Add(this.lblUp1Host);
|
||||||
|
+ resources.ApplyResources(this.tpUp1, "tpUp1");
|
||||||
|
+ this.tpUp1.Name = "tpUp1";
|
||||||
|
+ this.tpUp1.UseVisualStyleBackColor = true;
|
||||||
|
+ //
|
||||||
|
+ // txtUp1Key
|
||||||
|
+ //
|
||||||
|
+ resources.ApplyResources(this.txtUp1Key, "txtUp1Key");
|
||||||
|
+ this.txtUp1Key.Name = "txtUp1Key";
|
||||||
|
+ this.txtUp1Key.TextChanged += new System.EventHandler(this.txtUp1Key_TextChanged);
|
||||||
|
+ //
|
||||||
|
+ // txtUp1Host
|
||||||
|
+ //
|
||||||
|
+ resources.ApplyResources(this.txtUp1Host, "txtUp1Host");
|
||||||
|
+ this.txtUp1Host.Name = "txtUp1Host";
|
||||||
|
+ this.txtUp1Host.TextChanged += new System.EventHandler(this.txtUp1Host_TextChanged);
|
||||||
|
+ //
|
||||||
|
+ // lblUp1Key
|
||||||
|
+ //
|
||||||
|
+ resources.ApplyResources(this.lblUp1Key, "lblUp1Key");
|
||||||
|
+ this.lblUp1Key.Name = "lblUp1Key";
|
||||||
|
+ //
|
||||||
|
+ // lblUp1Host
|
||||||
|
+ //
|
||||||
|
+ resources.ApplyResources(this.lblUp1Host, "lblUp1Host");
|
||||||
|
+ this.lblUp1Host.Name = "lblUp1Host";
|
||||||
|
|
||||||
//
|
//
|
||||||
// UploadersConfigForm
|
// UploadersConfigForm
|
||||||
//
|
//
|
||||||
|
@ -3516,6 +3557,8 @@ private void InitializeComponent()
|
||||||
this.tpChevereto.ResumeLayout(false);
|
this.tpChevereto.ResumeLayout(false);
|
||||||
this.tpChevereto.PerformLayout();
|
this.tpChevereto.PerformLayout();
|
||||||
this.tcUploaders.ResumeLayout(false);
|
this.tcUploaders.ResumeLayout(false);
|
||||||
|
this.tpUp1.ResumeLayout(false);
|
||||||
|
this.tpUp1.PerformLayout();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3920,5 +3963,10 @@ private void InitializeComponent()
|
||||||
private HelpersLib.MyListView lvTwitterAccounts;
|
private HelpersLib.MyListView lvTwitterAccounts;
|
||||||
private System.Windows.Forms.ColumnHeader chTwitterAccount;
|
private System.Windows.Forms.ColumnHeader chTwitterAccount;
|
||||||
private System.Windows.Forms.Label lblCustomUploaderRegexTip;
|
private System.Windows.Forms.Label lblCustomUploaderRegexTip;
|
||||||
|
private System.Windows.Forms.TabPage tpUp1;
|
||||||
|
private System.Windows.Forms.TextBox txtUp1Key;
|
||||||
|
private System.Windows.Forms.TextBox txtUp1Host;
|
||||||
|
private System.Windows.Forms.Label lblUp1Key;
|
||||||
|
private System.Windows.Forms.Label lblUp1Host;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -537,6 +537,11 @@ public void LoadSettings(UploadersConfig uploadersConfig)
|
||||||
txtMediaFirePath.Text = Config.MediaFirePath;
|
txtMediaFirePath.Text = Config.MediaFirePath;
|
||||||
cbMediaFireUseLongLink.Checked = Config.MediaFireUseLongLink;
|
cbMediaFireUseLongLink.Checked = Config.MediaFireUseLongLink;
|
||||||
|
|
||||||
|
// Up1
|
||||||
|
|
||||||
|
txtUp1Host.Text = Config.Up1Host;
|
||||||
|
txtUp1Key.Text = Config.Up1Key;
|
||||||
|
|
||||||
// Lambda
|
// Lambda
|
||||||
|
|
||||||
txtLambdaApiKey.Text = Config.LambdaSettings.UserAPIKey;
|
txtLambdaApiKey.Text = Config.LambdaSettings.UserAPIKey;
|
||||||
|
@ -1870,6 +1875,20 @@ private void cbOwnCloudIgnoreInvalidCert_CheckedChanged(object sender, EventArgs
|
||||||
|
|
||||||
#endregion ownCloud
|
#endregion ownCloud
|
||||||
|
|
||||||
|
#region Up1
|
||||||
|
|
||||||
|
private void txtUp1Host_TextChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Config.Up1Host = txtUp1Host.Text;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void txtUp1Key_TextChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Config.Up1Key = txtUp1Key.Text;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion Up1
|
||||||
|
|
||||||
#region Pushbullet
|
#region Pushbullet
|
||||||
|
|
||||||
private void txtPushbulletUserKey_TextChanged(object sender, EventArgs e)
|
private void txtPushbulletUserKey_TextChanged(object sender, EventArgs e)
|
||||||
|
@ -2480,4 +2499,4 @@ private void txtCustomUploaderLog_LinkClicked(object sender, LinkClickedEventArg
|
||||||
|
|
||||||
#endregion Other Uploaders
|
#endregion Other Uploaders
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,12 @@
|
||||||
<HintPath>..\packages\MegaApiClient.1.1.0\lib\net40\MegaApiClient.dll</HintPath>
|
<HintPath>..\packages\MegaApiClient.1.1.0\lib\net40\MegaApiClient.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="ClouDeveloper.Mime">
|
||||||
|
<HintPath>..\packages\cloudeveloper.mime.1.0.0\lib\net40-client\ClouDeveloper.Mime.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="crypto">
|
||||||
|
<HintPath>..\packages\Portable.BouncyCastle.1.7.0.2\lib\portable-net4+sl5+wp8+win8+wpa81+MonoTouch10+MonoAndroid10+xamarinmac20+xamarinios10\crypto.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
|
@ -293,6 +299,7 @@
|
||||||
<Compile Include="FileUploaders\MediaCrushUploader.cs" />
|
<Compile Include="FileUploaders\MediaCrushUploader.cs" />
|
||||||
<Compile Include="URLShorteners\VgdURLShortener.cs" />
|
<Compile Include="URLShorteners\VgdURLShortener.cs" />
|
||||||
<Compile Include="URLShorteners\YourlsURLShortener.cs" />
|
<Compile Include="URLShorteners\YourlsURLShortener.cs" />
|
||||||
|
<Compile Include="FileUploaders\Up1.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Controls\AccountsControl.de.resx">
|
<EmbeddedResource Include="Controls\AccountsControl.de.resx">
|
||||||
|
@ -759,4 +766,4 @@ if not exist APIKeysLocal.cs (
|
||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
</Target>
|
</Target>
|
||||||
-->
|
-->
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -241,6 +241,11 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
|
||||||
|
|
||||||
public PushbulletSettings PushbulletSettings = new PushbulletSettings();
|
public PushbulletSettings PushbulletSettings = new PushbulletSettings();
|
||||||
|
|
||||||
|
// Up1
|
||||||
|
|
||||||
|
public string Up1Host = "https://up1.ca";
|
||||||
|
public string Up1Key = "c61540b5ceecd05092799f936e27755f";
|
||||||
|
|
||||||
// Lambda
|
// Lambda
|
||||||
|
|
||||||
public LambdaSettings LambdaSettings = new LambdaSettings();
|
public LambdaSettings LambdaSettings = new LambdaSettings();
|
||||||
|
@ -476,4 +481,4 @@ public int GetLocalhostIndex(EDataType dataType)
|
||||||
|
|
||||||
#endregion Helper Methods
|
#endregion Helper Methods
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,4 +5,6 @@
|
||||||
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net40" />
|
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net40" />
|
||||||
<package id="SSH.NET" version="2014.4.6-beta1" targetFramework="net40" />
|
<package id="SSH.NET" version="2014.4.6-beta1" targetFramework="net40" />
|
||||||
<package id="System.Net.FtpClient" version="1.0.5281.14359" targetFramework="net40" />
|
<package id="System.Net.FtpClient" version="1.0.5281.14359" targetFramework="net40" />
|
||||||
</packages>
|
<package id="cloudeveloper.mime" version="1.0.0" targetFramework="net40" />
|
||||||
|
<package id="Portable.BouncyCastle" version="1.7.0.2" targetFramework="net40" />
|
||||||
|
</packages>
|
||||||
|
|
|
@ -1009,6 +1009,9 @@ public UploadResult UploadFile(Stream stream, string fileName)
|
||||||
case FileDestination.Dropfile:
|
case FileDestination.Dropfile:
|
||||||
fileUploader = new Dropfile();
|
fileUploader = new Dropfile();
|
||||||
break;
|
break;
|
||||||
|
case FileDestination.Up1:
|
||||||
|
fileUploader = new Up1(Program.UploadersConfig.Up1Host, Program.UploadersConfig.Up1Key);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileUploader != null)
|
if (fileUploader != null)
|
||||||
|
@ -1307,4 +1310,4 @@ public void Dispose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue