ShareX/ShareX.UploadersLib/FileUploaders/Pomf.cs

189 lines
7 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
2017-01-11 21:39:40 +13:00
Copyright (c) 2007-2017 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;
using System.Windows.Forms;
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;
2016-06-28 05:20:55 +12:00
public override Icon ServiceIcon => Resources.Pomf;
public override bool CheckConfig(UploadersConfig config)
{
return config.PomfUploader != null && !string.IsNullOrEmpty(config.PomfUploader.UploadURL);
}
public override GenericUploader CreateUploader(UploadersConfig config, TaskReferenceHelper taskInfo)
{
return new Pomf(config.PomfUploader);
}
public override TabPage GetUploadersConfigTabPage(UploadersConfigForm form) => form.tpPomf;
}
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>()
{
//new PomfUploader("https://pomf.se/upload.php"),
2016-11-08 19:38:44 +13:00
new PomfUploader("https://comfy.moe/upload.php"),
2017-08-27 18:07:31 +12:00
new PomfUploader("https://doko.moe/upload.php"),
2017-03-19 13:28:50 +13:00
new PomfUploader("https://edfile.pro/upload/archive"),
2016-12-24 01:02:47 +13:00
new PomfUploader("https://filebox.moe/upload.php"),
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("https://mixtape.moe/upload.php"),
2016-02-04 17:39:22 +13:00
new PomfUploader("https://pomf.cat/upload.php", "https://a.pomf.cat"),
new PomfUploader("https://pomf.space/upload.php"),
2016-11-08 19:38:44 +13:00
new PomfUploader("https://pomf.pyonpyon.moe/upload.php"),
new PomfUploader("https://pomfe.co/upload.php", "https://a.pomfe.co"),
2016-01-09 11:30:38 +13:00
new PomfUploader("http://reich.io/upload.php"),
new PomfUploader("https://safe.moe/api/upload"),
2015-12-08 13:21:20 +13:00
new PomfUploader("https://sugoi.vidyagam.es/upload.php"),
2016-11-08 19:38:44 +13:00
new PomfUploader("https://up.asis.io/upload.php", "http://dl.asis.io"),
new PomfUploader("https://vidga.me/upload.php")
};
2016-07-01 17:41:57 +12:00
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)
{
UploadResult result = SendRequestFile(Uploader.UploadURL, stream, 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))
{
2016-11-08 19:38:44 +13:00
successful.Add(new PomfTest { Name = uploader.ToString(), URL = result.URL, 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; }
2016-11-08 19:38:44 +13:00
public string URL { get; set; }
public long UploadTime { get; set; } = -1;
public override string ToString()
{
2016-11-08 19:38:44 +13:00
if (!string.IsNullOrEmpty(URL))
{
2016-11-08 19:38:44 +13:00
return $"{Name} ({UploadTime}ms): {URL}";
}
return Name;
}
}
2014-08-22 15:05:48 +12:00
}
2017-03-30 10:03:08 +13:00
}