mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
Refactor FDL logic
This commit is contained in:
parent
a1d3e4c5d2
commit
34ad1d7f83
2 changed files with 20 additions and 25 deletions
|
@ -3,6 +3,7 @@
|
|||
using Newtonsoft.Json;
|
||||
using ShareX.UploadersLib.Properties;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Web;
|
||||
using System.Windows.Forms;
|
||||
|
@ -36,13 +37,13 @@ public override URLShortener CreateShortener(UploadersConfig config, TaskReferen
|
|||
public class FirebaseRequest
|
||||
{
|
||||
public DynamicLinkInfo dynamicLinkInfo { get; set; }
|
||||
public Suffix suffix { get; set; }
|
||||
}
|
||||
|
||||
public class DynamicLinkInfo
|
||||
{
|
||||
public string dynamicLinkDomain { get; set; }
|
||||
public string link { get; set; }
|
||||
public Suffix suffix { get; set; }
|
||||
}
|
||||
|
||||
public class Suffix
|
||||
|
@ -66,39 +67,33 @@ public override UploadResult ShortenURL(string url)
|
|||
{
|
||||
UploadResult result = new UploadResult { URL = url };
|
||||
|
||||
string RequestUrl = "https://firebasedynamiclinks.googleapis.com/v1/shortLinks";
|
||||
string option;
|
||||
FirebaseRequest request = new FirebaseRequest
|
||||
{
|
||||
dynamicLinkInfo = new DynamicLinkInfo
|
||||
{
|
||||
dynamicLinkDomain = DynamicLinkDomain + ".app.goo.gl",
|
||||
link = url
|
||||
}
|
||||
};
|
||||
|
||||
Dictionary<string, string> RequestUrlArgs = new Dictionary<string, string>
|
||||
string RequestUrl = "https://firebasedynamiclinks.googleapis.com/v1/shortLinks";
|
||||
|
||||
Dictionary<string, string> args = new Dictionary<string, string>
|
||||
{
|
||||
{ "key", WebAPIKey }
|
||||
};
|
||||
|
||||
if (IsShort)
|
||||
{
|
||||
option = "SHORT";
|
||||
}
|
||||
else
|
||||
request.suffix = new Suffix
|
||||
{
|
||||
option = "UNGUESSABLE";
|
||||
}
|
||||
|
||||
FirebaseRequest request = new FirebaseRequest
|
||||
{
|
||||
dynamicLinkInfo = new DynamicLinkInfo
|
||||
{
|
||||
dynamicLinkDomain = DynamicLinkDomain + ".app.goo.gl",
|
||||
link = HttpUtility.UrlEncode(url),
|
||||
suffix = new Suffix
|
||||
{
|
||||
option = option
|
||||
}
|
||||
}
|
||||
option = "SHORT"
|
||||
};
|
||||
}
|
||||
|
||||
string RequestJson = JsonConvert.SerializeObject(request);
|
||||
|
||||
result.Response = SendRequest(HttpMethod.POST, RequestUrl, RequestJson, ContentTypeJSON, RequestUrlArgs);
|
||||
result.Response = SendRequest(HttpMethod.POST, RequestUrl, RequestJson, ContentTypeJSON, args);
|
||||
result.ShortenedURL = JsonConvert.DeserializeObject<FirebaseResponse>(result.Response).shortLink;
|
||||
|
||||
return result;
|
||||
|
|
|
@ -434,7 +434,7 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
|
|||
|
||||
public string FirebaseWebAPIKey = "";
|
||||
public string FirebaseDynamicLinkDomain = "";
|
||||
public bool FirebaseIsShort = true;
|
||||
public bool FirebaseIsShort = false;
|
||||
|
||||
#endregion Firebase Dynamic Links
|
||||
|
||||
|
|
Loading…
Reference in a new issue