From 9718c5349bb3c183821f6c3f21d31383f8f281cf Mon Sep 17 00:00:00 2001 From: Jaex Date: Sun, 6 Jul 2014 17:56:43 +0300 Subject: [PATCH] Trying to implement ownCloud --- ShareX/UploadTask.cs | 3 + UploadersLib/Enums.cs | 2 + UploadersLib/FileUploaders/OwnCloud.cs | 87 ++++++++++++++++++++++++++ UploadersLib/UploadersLib.csproj | 1 + 4 files changed, 93 insertions(+) create mode 100644 UploadersLib/FileUploaders/OwnCloud.cs diff --git a/ShareX/UploadTask.cs b/ShareX/UploadTask.cs index a1c7fc235..6954b65e8 100644 --- a/ShareX/UploadTask.cs +++ b/ShareX/UploadTask.cs @@ -930,6 +930,9 @@ public UploadResult UploadFile(Stream stream, string fileName) case FileDestination.AmazonS3: fileUploader = new AmazonS3(Program.UploadersConfig.AmazonS3Settings); break; + case FileDestination.OwnCloud: + fileUploader = new OwnCloud("http://demo.owncloud.org", "test", "test"); + break; case FileDestination.Pushbullet: fileUploader = new Pushbullet(Program.UploadersConfig.PushbulletSettings); break; diff --git a/UploadersLib/Enums.cs b/UploadersLib/Enums.cs index b606f463b..c004b8db1 100644 --- a/UploadersLib/Enums.cs +++ b/UploadersLib/Enums.cs @@ -90,6 +90,8 @@ public enum FileDestination Mega, [Description("s3.amazon.com")] AmazonS3, + [Description("owncloud.org")] + OwnCloud, [Description("pushbullet.com")] Pushbullet, [Description("mediacru.sh")] diff --git a/UploadersLib/FileUploaders/OwnCloud.cs b/UploadersLib/FileUploaders/OwnCloud.cs new file mode 100644 index 000000000..c293150da --- /dev/null +++ b/UploadersLib/FileUploaders/OwnCloud.cs @@ -0,0 +1,87 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (C) 2007-2014 ShareX Developers + + 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 . +*/ + +#endregion License Information (GPL v3) + +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.IO; +using System.Linq; +using System.Text; + +namespace UploadersLib.FileUploaders +{ + public sealed class OwnCloud : FileUploader + { + public string Host { get; set; } + public string Username { get; set; } + public string Password { get; set; } + public string Path { get; set; } + + public OwnCloud(string host, string username, string password) + { + Host = host; + Username = username; + Password = password; + } + + public override UploadResult Upload(Stream stream, string fileName) + { + if (string.IsNullOrEmpty(Host)) + { + throw new Exception("ownCloud Host is empty."); + } + + if (string.IsNullOrEmpty(Username) || string.IsNullOrEmpty(Password)) + { + throw new Exception("ownCloud Username or Password is empty."); + } + + if (string.IsNullOrEmpty(Path)) + { + Path = "/"; + } + + Dictionary args = new Dictionary(); + args.Add("format", "json"); + args.Add("path", Path); // path to the file/folder which should be shared + args.Add("shareType", "3"); // ‘0’ = user; ‘1’ = group; ‘3’ = public link + // args.Add("shareWith", ""); // user / group id with which the file should be shared + // args.Add("publicUpload", "true"); // allow public upload to a public shared folder (true/false) + // args.Add("password", ""); // password to protect public link Share with + // args.Add("permissions", "3"); // 1 = read; 2 = update; 4 = create; 8 = delete; 16 = share; 31 = all (default: 31, for public shares: 1) + + string url = Host + "/ocs/v1.php/apps/files_sharing/api/v1/shares"; + NameValueCollection headers = CreateAuthenticationHeader(Username, Password); + UploadResult result = UploadData(stream, url, fileName, "file", args, headers: headers); + + if (result.IsSuccess) + { + result.URL = ""; // Parse response + } + + return result; + } + } +} \ No newline at end of file diff --git a/UploadersLib/UploadersLib.csproj b/UploadersLib/UploadersLib.csproj index 68925a5fc..775721731 100644 --- a/UploadersLib/UploadersLib.csproj +++ b/UploadersLib/UploadersLib.csproj @@ -110,6 +110,7 @@ +