Adding puush file uploader

This commit is contained in:
Jaex 2016-06-11 21:54:14 +03:00
parent c08abd1026
commit 21f53ce6b6
10 changed files with 527 additions and 14 deletions

View file

@ -94,6 +94,8 @@ public enum FileDestination
OneDrive,
[Description("Google Drive")]
GoogleDrive,
[Description("puush")]
Puush,
[Description("Box")]
Box,
[Description("MEGA")]

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

View file

@ -0,0 +1,137 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2016 ShareX Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
using System.Collections.Generic;
using System.IO;
namespace ShareX.UploadersLib.FileUploaders
{
public class PuushFileUploaderService : FileUploaderService
{
public override FileDestination EnumValue { get; } = FileDestination.Puush;
public override bool CheckConfig(UploadersConfig config)
{
return !string.IsNullOrEmpty(config.PuushAPIKey);
}
public override GenericUploader CreateUploader(UploadersConfig config, TaskReferenceHelper taskInfo)
{
return new Puush()
{
APIKey = config.PuushAPIKey
};
}
}
public class Puush : FileUploader
{
public const string PuushURL = "https://puush.me";
public const string PuushAPIURL = PuushURL + "/api";
public const string PuushAPILoginURL = PuushAPIURL + "/auth";
public const string PuushAPIUploadURL = PuushAPIURL + "/up";
public const string PuushRegisterURL = PuushURL + "/register";
public const string PuushResetPasswordURL = PuushURL + "/reset_password";
public string APIKey { get; set; }
public string Login(string email, string password)
{
Dictionary<string, string> arguments = new Dictionary<string, string>();
arguments.Add("e", email);
arguments.Add("p", password);
arguments.Add("z", "ShareX");
string response = SendRequest(HttpMethod.POST, PuushAPILoginURL, arguments);
if (!string.IsNullOrEmpty(response))
{
string[] values = response.Split(',');
if (values != null && values.Length > 1)
{
int status;
if (int.TryParse(values[0], out status) && status >= 0)
{
return values[1];
}
}
}
return null;
}
public override UploadResult Upload(Stream stream, string fileName)
{
Dictionary<string, string> arguments = new Dictionary<string, string>();
arguments.Add("k", APIKey);
arguments.Add("z", "ShareX");
UploadResult result = UploadData(stream, PuushAPIUploadURL, fileName, "f", arguments);
if (result.IsSuccess)
{
string[] values = result.Response.Split(',');
if (values != null && values.Length > 1)
{
int status;
if (!int.TryParse(values[0], out status))
{
status = -2;
}
if (status < 0)
{
switch (status)
{
case -1:
Errors.Add("Authentication failure.");
break;
default:
case -2:
Errors.Add("Connection error.");
break;
case -3:
Errors.Add("Checksum error.");
break;
case -4:
Errors.Add("Insufficient account storage remaining.");
break;
}
}
else
{
result.URL = values[1];
}
}
}
return result;
}
}
}

View file

@ -0,0 +1,139 @@
namespace ShareX.UploadersLib.Forms
{
partial class PuushLoginForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblPassword = new System.Windows.Forms.Label();
this.lblEmail = new System.Windows.Forms.Label();
this.txtEmail = new System.Windows.Forms.TextBox();
this.txtPassword = new System.Windows.Forms.TextBox();
this.btnLogin = new System.Windows.Forms.Button();
this.llForgottenPassword = new System.Windows.Forms.LinkLabel();
this.llCreateAccount = new System.Windows.Forms.LinkLabel();
this.SuspendLayout();
//
// lblPassword
//
this.lblPassword.AutoSize = true;
this.lblPassword.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblPassword.Location = new System.Drawing.Point(13, 96);
this.lblPassword.Name = "lblPassword";
this.lblPassword.Size = new System.Drawing.Size(71, 16);
this.lblPassword.TabIndex = 1;
this.lblPassword.Text = "Password:";
//
// lblEmail
//
this.lblEmail.AutoSize = true;
this.lblEmail.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblEmail.Location = new System.Drawing.Point(13, 40);
this.lblEmail.Name = "lblEmail";
this.lblEmail.Size = new System.Drawing.Size(45, 16);
this.lblEmail.TabIndex = 3;
this.lblEmail.Text = "Email:";
//
// txtEmail
//
this.txtEmail.Location = new System.Drawing.Point(16, 64);
this.txtEmail.Name = "txtEmail";
this.txtEmail.Size = new System.Drawing.Size(224, 20);
this.txtEmail.TabIndex = 4;
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(16, 120);
this.txtPassword.Name = "txtPassword";
this.txtPassword.Size = new System.Drawing.Size(224, 20);
this.txtPassword.TabIndex = 5;
this.txtPassword.UseSystemPasswordChar = true;
//
// btnLogin
//
this.btnLogin.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnLogin.Location = new System.Drawing.Point(16, 176);
this.btnLogin.Name = "btnLogin";
this.btnLogin.Size = new System.Drawing.Size(224, 32);
this.btnLogin.TabIndex = 6;
this.btnLogin.Text = "Login";
this.btnLogin.UseVisualStyleBackColor = true;
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
//
// llForgottenPassword
//
this.llForgottenPassword.AutoSize = true;
this.llForgottenPassword.Location = new System.Drawing.Point(13, 152);
this.llForgottenPassword.Name = "llForgottenPassword";
this.llForgottenPassword.Size = new System.Drawing.Size(106, 13);
this.llForgottenPassword.TabIndex = 7;
this.llForgottenPassword.TabStop = true;
this.llForgottenPassword.Text = "Forgotten password?";
this.llForgottenPassword.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.llForgottenPassword_LinkClicked);
//
// llCreateAccount
//
this.llCreateAccount.AutoSize = true;
this.llCreateAccount.Location = new System.Drawing.Point(13, 16);
this.llCreateAccount.Name = "llCreateAccount";
this.llCreateAccount.Size = new System.Drawing.Size(104, 13);
this.llCreateAccount.TabIndex = 8;
this.llCreateAccount.TabStop = true;
this.llCreateAccount.Text = "Create an account...";
this.llCreateAccount.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.llCreateAccount_LinkClicked);
//
// PuushLoginForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.Window;
this.ClientSize = new System.Drawing.Size(256, 224);
this.Controls.Add(this.llCreateAccount);
this.Controls.Add(this.llForgottenPassword);
this.Controls.Add(this.btnLogin);
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.txtEmail);
this.Controls.Add(this.lblEmail);
this.Controls.Add(this.lblPassword);
this.Name = "PuushLoginForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "puush login";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label lblPassword;
private System.Windows.Forms.Label lblEmail;
private System.Windows.Forms.TextBox txtEmail;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.Button btnLogin;
private System.Windows.Forms.LinkLabel llForgottenPassword;
private System.Windows.Forms.LinkLabel llCreateAccount;
}
}

View file

@ -0,0 +1,92 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2016 ShareX Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
using ShareX.HelpersLib;
using ShareX.UploadersLib.FileUploaders;
using ShareX.UploadersLib.Properties;
using System;
using System.Drawing;
using System.Windows.Forms;
namespace ShareX.UploadersLib.Forms
{
public partial class PuushLoginForm : Form
{
public string APIKey { get; set; }
public PuushLoginForm()
{
InitializeComponent();
Icon = Resources.puush;
}
private bool CheckValidation()
{
bool result = true;
if (string.IsNullOrEmpty(txtEmail.Text))
{
txtEmail.BackColor = Color.FromArgb(255, 200, 200);
result = false;
}
if (string.IsNullOrEmpty(txtPassword.Text))
{
txtPassword.BackColor = Color.FromArgb(255, 200, 200);
result = false;
}
return result;
}
private void llCreateAccount_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
URLHelpers.OpenURL(Puush.PuushRegisterURL);
}
private void llForgottenPassword_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
URLHelpers.OpenURL(Puush.PuushResetPasswordURL);
}
private void btnLogin_Click(object sender, EventArgs e)
{
if (CheckValidation())
{
APIKey = new Puush().Login(txtEmail.Text, txtPassword.Text);
if (!string.IsNullOrEmpty(APIKey))
{
DialogResult = DialogResult.OK;
Close();
}
else
{
MessageBox.Show("Login failed.", "Authentication failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -865,6 +865,16 @@ internal class Resources {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
internal static System.Drawing.Icon puush {
get {
object obj = ResourceManager.GetObject("puush", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>

View file

@ -494,4 +494,7 @@ Created folders:</value>
<data name="SomeImage" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\favicons\someimage.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="puush" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Favicons\puush.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View file

@ -129,6 +129,7 @@
<Compile Include="FileUploaders\AmazonS3Settings.cs" />
<Compile Include="FileUploaders\Box.cs" />
<Compile Include="FileUploaders\Lithiio.cs" />
<Compile Include="FileUploaders\Puush.cs" />
<Compile Include="FileUploaders\Sul.cs" />
<Compile Include="FileUploaders\Dropfile.cs" />
<Compile Include="FileUploaders\Lambda.cs" />
@ -158,6 +159,12 @@
<Compile Include="Forms\OCRSpaceForm.Designer.cs">
<DependentUpon>OCRSpaceForm.cs</DependentUpon>
</Compile>
<Compile Include="Forms\PuushLoginForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\PuushLoginForm.Designer.cs">
<DependentUpon>PuushLoginForm.cs</DependentUpon>
</Compile>
<Compile Include="FTPClient\FTPClientForm.cs">
<SubType>Form</SubType>
</Compile>
@ -591,6 +598,9 @@
<EmbeddedResource Include="Forms\OCRSpaceForm.resx">
<DependentUpon>OCRSpaceForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\PuushLoginForm.resx">
<DependentUpon>PuushLoginForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\ResponseForm.de.resx">
<DependentUpon>ResponseForm.cs</DependentUpon>
</EmbeddedResource>
@ -934,6 +944,9 @@
<ItemGroup>
<Analyzer Include="..\packages\AWSSDK.S3.3.1.7.0\analyzers\dotnet\cs\AWSSDK.S3.CodeAnalysis.dll" />
</ItemGroup>
<ItemGroup>
<None Include="Favicons\puush.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<PropertyGroup>

View file

@ -135,19 +135,19 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
public bool DropboxAutoCreateShareableLink = false;
public DropboxURLType DropboxURLType = DropboxURLType.Default;
// FTP Server
public List<FTPAccount> FTPAccountList = new List<FTPAccount>();
public int FTPSelectedImage = 0;
public int FTPSelectedText = 0;
public int FTPSelectedFile = 0;
// OneDrive
public OAuth2Info OneDriveOAuth2Info = null;
public OneDriveFileInfo OneDriveSelectedFolder = OneDrive.RootFolder;
public bool OneDriveAutoCreateShareableLink = true;
// Copy
public OAuthInfo CopyOAuthInfo = null;
public CopyAccountInfo CopyAccountInfo = null;
public string CopyUploadPath = "ShareX/%y/%mo";
public CopyURLType CopyURLType = CopyURLType.Shortened;
// Google Drive
public OAuth2Info GoogleDriveOAuth2Info = null;
@ -156,6 +156,10 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
public bool GoogleDriveUseFolder = false;
public string GoogleDriveFolderID = "";
// puush
public string PuushAPIKey = "";
// SendSpace
public AccountType SendSpaceAccountType = AccountType.Anonymous;
@ -183,13 +187,6 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
public string LocalhostrPassword = "";
public bool LocalhostrDirectURL = true;
// FTP Server
public List<FTPAccount> FTPAccountList = new List<FTPAccount>();
public int FTPSelectedImage = 0;
public int FTPSelectedText = 0;
public int FTPSelectedFile = 0;
// Shared Folder
public List<LocalhostAccount> LocalhostAccountList = new List<LocalhostAccount>();