ShareX/ShareX.UploadersLib/FileUploaders/Pomf.cs

192 lines
7.3 KiB
C#
Raw Normal View History

2014-08-22 15:05:48 +12:00
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
2016-01-04 04:16:01 +13:00
Copyright (c) 2007-2016 ShareX Team
2014-08-22 15:05:48 +12:00
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 Newtonsoft.Json;
using ShareX.HelpersLib;
2015-10-12 21:09:02 +13:00
using ShareX.UploadersLib.Properties;
2015-11-04 03:39:57 +13:00
using System;
2014-08-22 15:05:48 +12:00
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
2014-08-22 15:05:48 +12:00
using System.IO;
using System.Linq;
2014-08-22 15:05:48 +12:00
2014-12-11 09:25:20 +13:00
namespace ShareX.UploadersLib.FileUploaders
2014-08-22 15:05:48 +12:00
{
public class PomfFileUploaderService : FileUploaderService
{
public override FileDestination EnumValue { get; } = FileDestination.Pomf;
public override bool CheckConfig(UploadersConfig uploadersConfig)
{
return uploadersConfig.PomfUploader != null && !string.IsNullOrEmpty(uploadersConfig.PomfUploader.UploadURL);
}
public override FileUploader CreateUploader(UploadersConfig uploadersConfig, TaskReferenceHelper taskInfo)
{
return new Pomf(uploadersConfig.PomfUploader);
}
}
public class Pomf : FileUploader
2014-08-22 15:05:48 +12:00
{
2016-01-09 11:30:38 +13:00
// Pomf clones: https://docs.google.com/spreadsheets/d/1kh1TZdtyX7UlRd55OBxf7DB-JGj2rsfWckI0FPQRYhE
public static List<PomfUploader> Uploaders = new List<PomfUploader>()
{
2015-11-02 22:32:52 +13:00
new PomfUploader("http://1339.cf/upload.php", "http://b.1339.cf"),
new PomfUploader("https://catgirlsare.sexy/upload.php"),
2015-11-22 04:49:05 +13:00
new PomfUploader("http://comfy.moe/upload.php"),
2016-01-09 11:30:38 +13:00
new PomfUploader("https://cocaine.ninja/upload.php"),
2015-11-04 04:56:37 +13:00
new PomfUploader("http://cuntflaps.me/upload.php", "http://a.cuntflaps.me"),
2015-12-08 05:00:55 +13:00
new PomfUploader("http://files.plebeianparty.com/upload.php", "http://a.plebeianparty.com"),
2015-11-02 22:32:52 +13:00
new PomfUploader("http://g.zxq.co/upload.php", "http://y.zxq.co"),
2015-12-08 05:00:55 +13:00
new PomfUploader("http://glop.me/upload.php", "http://gateway.glop.me/ipfs"),
2015-11-02 22:32:52 +13:00
new PomfUploader("http://kyaa.sg/upload.php", "https://r.kyaa.sg"),
2016-02-09 05:54:44 +13:00
new PomfUploader("https://maxfile.ro/static/upload.php", "https://d2.maxfile.ro"),
2015-11-02 22:32:52 +13:00
new PomfUploader("https://mixtape.moe/upload.php"),
2015-12-08 05:00:55 +13:00
new PomfUploader("https://nigger.cat/upload.php"),
2016-02-04 17:39:22 +13:00
new PomfUploader("https://pomf.cat/upload.php", "https://a.pomf.cat"),
2015-11-02 22:32:52 +13:00
new PomfUploader("http://pomf.hummingbird.moe/upload.php", "http://a.pomf.hummingbird.moe"),
new PomfUploader("https://pomf.is/upload.php"),
2015-11-22 04:49:05 +13:00
//new PomfUploader("https://pomf.se/upload.php"),
2016-01-09 11:30:38 +13:00
new PomfUploader("http://reich.io/upload.php"),
2015-12-08 13:21:20 +13:00
new PomfUploader("https://sugoi.vidyagam.es/upload.php"),
2015-11-02 22:32:52 +13:00
new PomfUploader("http://up.che.moe/upload.php", "http://cdn.che.moe")
};
2015-10-07 12:43:51 +13:00
public PomfUploader Uploader { get; private set; }
public Pomf(PomfUploader uploader)
{
Uploader = uploader;
}
2014-08-22 15:05:48 +12:00
public override UploadResult Upload(Stream stream, string fileName)
{
2015-10-06 13:09:16 +13:00
if (Uploader == null || string.IsNullOrEmpty(Uploader.UploadURL))
{
2015-10-12 21:09:02 +13:00
Errors.Add(Resources.Pomf_Upload_Please_select_one_of_the_Pomf_uploaders_from__Destination_settings_window____Pomf_tab__);
2015-10-06 13:09:16 +13:00
return null;
}
UploadResult result = UploadData(stream, Uploader.UploadURL, fileName, "files[]");
2014-08-22 15:05:48 +12:00
if (result.IsSuccess)
{
PomfResponse response = JsonConvert.DeserializeObject<PomfResponse>(result.Response);
if (response.success && response.files != null && response.files.Count > 0)
{
string url = response.files[0].url;
if (!URLHelpers.HasPrefix(url) && !string.IsNullOrEmpty(Uploader.ResultURL))
{
url = URLHelpers.CombineURL(Uploader.ResultURL, url);
}
result.URL = url;
2014-08-22 15:05:48 +12:00
}
}
return result;
}
2016-03-06 05:46:44 +13:00
public static string TestUploaders()
2015-11-04 03:39:57 +13:00
{
List<PomfTest> successful = new List<PomfTest>();
List<PomfTest> failed = new List<PomfTest>();
2015-11-04 03:39:57 +13:00
using (MemoryStream ms = new MemoryStream())
2015-11-04 03:39:57 +13:00
{
using (Image logo = ShareXResources.Logo)
2015-11-04 03:39:57 +13:00
{
logo.Save(ms, ImageFormat.Png);
}
2015-11-04 03:39:57 +13:00
foreach (PomfUploader uploader in Uploaders)
{
try
2015-11-04 03:39:57 +13:00
{
Pomf pomf = new Pomf(uploader);
string filename = Helpers.GetRandomAlphanumeric(10) + ".png";
Stopwatch timer = Stopwatch.StartNew();
UploadResult result = pomf.Upload(ms, filename);
long uploadTime = timer.ElapsedMilliseconds;
2015-11-04 03:39:57 +13:00
if (result != null && result.IsSuccess && !string.IsNullOrEmpty(result.URL))
{
successful.Add(new PomfTest { Name = uploader.ToString(), UploadTime = uploadTime });
2015-11-04 03:39:57 +13:00
}
else
{
failed.Add(new PomfTest { Name = uploader.ToString() });
2015-11-04 03:39:57 +13:00
}
}
catch (Exception e)
{
DebugHelper.WriteException(e);
failed.Add(new PomfTest { Name = uploader.ToString() });
}
2015-11-04 03:39:57 +13:00
}
}
return string.Format("Successful uploads ({0}):\r\n\r\n{1}\r\n\r\nFailed uploads ({2}):\r\n\r\n{3}",
successful.Count, string.Join("\r\n", successful.OrderBy(x => x.UploadTime)), failed.Count, string.Join("\r\n", failed));
2015-11-04 03:39:57 +13:00
}
private class PomfResponse
2014-08-22 15:05:48 +12:00
{
public bool success { get; set; }
public object error { get; set; }
public List<PomfFile> files { get; set; }
}
private class PomfFile
2014-08-22 15:05:48 +12:00
{
public string hash { get; set; }
public string name { get; set; }
public string url { get; set; }
public string size { get; set; }
}
private class PomfTest
{
public string Name { get; set; }
public long UploadTime { get; set; } = -1;
public override string ToString()
{
if (UploadTime >= 0)
{
return $"{Name} ({UploadTime}ms)";
}
return Name;
}
}
2014-08-22 15:05:48 +12:00
}
}