@@ -27,6 +27,7 @@ You should have received a copy of the GNU General Public License
27
27
28
28
using Newtonsoft . Json ;
29
29
using ShareX . UploadersLib . Properties ;
30
+ using System ;
30
31
using System . Collections . Generic ;
31
32
using System . Drawing ;
32
33
using System . IO ;
@@ -57,41 +58,79 @@ public sealed class Lithiio : FileUploader
57
58
{
58
59
public LithiioSettings Config { get ; private set ; }
59
60
61
+ public Lithiio ( )
62
+ {
63
+ }
64
+
60
65
public Lithiio ( LithiioSettings config )
61
66
{
62
67
Config = config ;
63
68
}
64
69
65
70
public override UploadResult Upload ( Stream stream , string fileName )
66
71
{
67
- Dictionary < string , string > arguments = new Dictionary < string , string > ( ) ;
68
- arguments . Add ( "key" , Config . UserAPIKey ) ;
72
+ Dictionary < string , string > args = new Dictionary < string , string > ( ) ;
73
+ args . Add ( "key" , Config . UserAPIKey ) ;
69
74
70
- UploadResult result = SendRequestFile ( "https://upload.lithi.io/v1.php" , stream , fileName , "file" , arguments ) ;
75
+ UploadResult result = SendRequestFile ( "https://upload.lithi.io/v1.php" , stream , fileName , "file" , args ) ;
71
76
72
77
if ( result . IsSuccess )
73
78
{
74
- LithiioResponse response = JsonConvert . DeserializeObject < LithiioResponse > ( result . Response ) ;
79
+ LithiioUploadResponse uploadResponse = JsonConvert . DeserializeObject < LithiioUploadResponse > ( result . Response ) ;
75
80
76
- if ( response . Success )
81
+ if ( uploadResponse . Success )
77
82
{
78
- result . URL = response . URL ;
83
+ result . URL = uploadResponse . URL ;
79
84
}
80
85
else
81
86
{
82
- Errors . Add ( response . Error ) ;
87
+ Errors . Add ( uploadResponse . Error ) ;
83
88
}
84
89
}
85
90
86
91
return result ;
87
92
}
88
93
89
- public class LithiioResponse
94
+ public string FetchAPIKey ( string email , string password )
95
+ {
96
+ Dictionary < string , string > args = new Dictionary < string , string > ( ) ;
97
+ args . Add ( "email" , email ) ;
98
+ args . Add ( "password" , password ) ;
99
+
100
+ string response = SendRequestMultiPart ( "https://lithi.io/api/v1/fetch-api-key.php" , args ) ;
101
+
102
+ if ( ! string . IsNullOrEmpty ( response ) )
103
+ {
104
+ LithiioFetchAPIKeyResponse apiKeyResponse = JsonConvert . DeserializeObject < LithiioFetchAPIKeyResponse > ( response ) ;
105
+
106
+ if ( apiKeyResponse . Success )
107
+ {
108
+ return apiKeyResponse . APIKey ;
109
+ }
110
+ else
111
+ {
112
+ throw new Exception ( apiKeyResponse . Error ) ;
113
+ }
114
+ }
115
+
116
+ return null ;
117
+ }
118
+
119
+ private class LithiioResponse
90
120
{
91
121
public bool Success { get ; set ; }
92
- public string URL { get ; set ; }
93
122
public string Error { get ; set ; }
94
123
}
124
+
125
+ private class LithiioUploadResponse : LithiioResponse
126
+ {
127
+ public string URL { get ; set ; }
128
+ }
129
+
130
+ private class LithiioFetchAPIKeyResponse : LithiioResponse
131
+ {
132
+ public string APIKey { get ; set ; }
133
+ }
95
134
}
96
135
97
136
public class LithiioSettings
0 commit comments