Skip to content

Commit df886b0

Browse files
committed
Add 'imgchest.com', 'gofile.io' #77
* Fix crash in CServerParamsDlg when m_ue is null
1 parent 5aaffa7 commit df886b0

File tree

10 files changed

+394
-6
lines changed

10 files changed

+394
-6
lines changed

Data/Favicons/gofile.io.ico

31.2 KB
Binary file not shown.

Data/Favicons/imgchest.com.ico

45.1 KB
Binary file not shown.

Data/Scripts/gofile.nut

Lines changed: 333 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,333 @@
1+
/**
2+
* GoFile.io Image Uploader Script
3+
* Official API Documentation: https://gofile.io/api
4+
* Updated: May 16, 2025
5+
*/
6+
7+
const UPLOAD_URL = "https://upload.gofile.io/uploadfile";
8+
const API_BASE_URL = "https://api.gofile.io";
9+
10+
function _PrintError(t, txt) {
11+
local errorMessage = "[gofile.io] " + txt + " Response code: " + nm.responseCode();
12+
if (t != null && "message" in t) {
13+
errorMessage += "\n" + t.message;
14+
} else if (t != null && "error" in t) {
15+
errorMessage += "\n" + t.error;
16+
}
17+
WriteLog("error", errorMessage);
18+
}
19+
20+
/**
21+
* This is the function that performs the upload of the file
22+
* @param string pathToFile
23+
* @param UploadParams options
24+
* @return int - success(1), failure(0)
25+
*/
26+
function UploadFile(pathToFile, options) {
27+
/**
28+
* @var task
29+
* @type FileUploadTaskWrapper
30+
*/
31+
local task = options.getTask().getFileTask();
32+
33+
// Get API token if provided (for authenticated uploads)
34+
local apiToken = ServerParams.getParam("Password");
35+
local folderId = ""; //options.getFolderID();
36+
local uploadRegion = ServerParams.getParam("uploadRegion");
37+
38+
// Determine upload URL based on region preference
39+
local uploadUrl = UPLOAD_URL;
40+
if (uploadRegion != "" && uploadRegion != "auto") {
41+
uploadUrl = "https://upload-" + uploadRegion + ".gofile.io/uploadfile";
42+
}
43+
44+
nm.setUrl(uploadUrl);
45+
46+
// Add authentication header if token is provided
47+
if (apiToken != "") {
48+
nm.addQueryHeader("Authorization", "Bearer " + apiToken);
49+
}
50+
51+
// Add the file (required parameter)
52+
nm.addPostFieldFile("file", pathToFile, task.getDisplayName(), GetFileMimeType(pathToFile));
53+
54+
// Add optional folderId if specified
55+
if (folderId != "") {
56+
nm.addPostField("folderId", folderId);
57+
}
58+
59+
// Perform multipart upload
60+
if (!nm.doUploadMultipartData()) {
61+
return ResultCode.Failure;
62+
}
63+
64+
// Parse response regardless of HTTP status code as required
65+
local t = ParseJSON(nm.responseBody());
66+
67+
if (t == null) {
68+
WriteLog("error", "[gofile.io] Invalid JSON response");
69+
return ResultCode.Failure;
70+
}
71+
72+
// Check if upload was successful
73+
if (!("status" in t) || t.status != "ok") {
74+
_PrintError(t, "Upload failed");
75+
return ResultCode.Failure;
76+
}
77+
78+
if (!("data" in t)) {
79+
_PrintError(t, "Upload failed - no data in response");
80+
return ResultCode.Failure;
81+
}
82+
83+
local data = t.data;
84+
local fileId = "";
85+
local downloadPage = "";
86+
local directUrl = "";
87+
local guestToken = "";
88+
89+
// Extract file information from response
90+
if ("fileId" in data) {
91+
fileId = data.fileId;
92+
}
93+
if ("downloadPage" in data) {
94+
downloadPage = data.downloadPage;
95+
}
96+
if ("directLink" in data) {
97+
directUrl = data.directLink;
98+
}
99+
if ("guestToken" in data) {
100+
guestToken = data.guestToken;
101+
// Store guest token for future uploads to same folder
102+
ServerParams.setParam("guestToken", guestToken);
103+
}
104+
if ("parentFolder" in data) {
105+
// Store parent folder ID for future uploads
106+
ServerParams.setParam("lastFolderId", data.parentFolder);
107+
}
108+
109+
// Set URLs for the application
110+
options.setViewUrl(downloadPage);
111+
options.setDirectUrl(directUrl);
112+
113+
return ResultCode.Success;
114+
}
115+
116+
/**
117+
* Authenticating on remote server (optional function)
118+
* GoFile.io supports both authenticated and anonymous uploads
119+
* @return int - success(1), failure(0)
120+
*/
121+
function Authenticate() {
122+
local userName = ServerParams.getParam("Login");
123+
local apiToken = ServerParams.getParam("Password");
124+
125+
if (apiToken == "") {
126+
if (userName != "") {
127+
WriteLog("error", "[gofile.io] You must set API token.");
128+
return ResultCode.Failure;
129+
}
130+
// No token provided - will use anonymous upload
131+
return ResultCode.Success;
132+
}
133+
134+
// Test the API token by getting account ID
135+
nm.addQueryHeader("Authorization", "Bearer " + apiToken);
136+
nm.doGet(API_BASE_URL + "/accounts/getid");
137+
138+
local t = ParseJSON(nm.responseBody());
139+
140+
if (t != null && "status" in t && t.status == "ok") {
141+
return ResultCode.Success;
142+
} else {
143+
_PrintError(t, "Authentication failed - invalid API token");
144+
return ResultCode.Failure;
145+
}
146+
}
147+
148+
function _ObtainRootFolder(apiToken) {
149+
// Get account ID first
150+
nm.addQueryHeader("Authorization", "Bearer " + apiToken);
151+
nm.doGet(API_BASE_URL + "/accounts/getid");
152+
153+
local accountResponse = ParseJSON(nm.responseBody());
154+
if (accountResponse == null || !("status" in accountResponse) || accountResponse.status != "ok") {
155+
_PrintError(accountResponse, "Failed to get account ID");
156+
return "";
157+
}
158+
159+
local accountId = accountResponse.data.id;
160+
161+
// Get account details to find root folder
162+
nm.addQueryHeader("Authorization", "Bearer " + apiToken);
163+
nm.doGet(API_BASE_URL + "/accounts/" + accountId);
164+
165+
local detailsResponse = ParseJSON(nm.responseBody());
166+
if (detailsResponse == null || !("status" in detailsResponse) || detailsResponse.status != "ok") {
167+
_PrintError(detailsResponse, "Failed to get account details");
168+
return "";
169+
}
170+
return detailsResponse.data.rootFolder;
171+
}
172+
173+
/**
174+
* Optional function:
175+
* Retrieving folder (album) list from server
176+
* This requires premium account and authenticated access
177+
* @var CFolderList list
178+
* @return int - success(1), failure(0)
179+
*/
180+
function GetFolderList(list) {
181+
local parentId = list.parentFolder().getId();
182+
local apiToken = ServerParams.getParam("Password");
183+
184+
if (parentId == "") {
185+
local rootFolderId = _ObtainRootFolder(apiToken);
186+
// Add root folder
187+
local rootFolder = CFolderItem();
188+
rootFolder.setId(rootFolderId);
189+
rootFolder.setTitle("Root (/)");
190+
list.AddFolderItem(rootFolder);
191+
} else {
192+
nm.addQueryHeader("Authorization", "Bearer " + apiToken);
193+
nm.doGet(API_BASE_URL + "/contents/" + parentId);
194+
}
195+
196+
return ResultCode.Success;
197+
}
198+
199+
/**
200+
* Create a folder (optional function)
201+
* Requires API token and premium account
202+
* @var CFolderItem parentAlbum
203+
* @var CFolderItem album
204+
* @return int - success(1), failure(0)
205+
*/
206+
function CreateFolder(parentAlbum, album) {
207+
local apiToken = ServerParams.getParam("Password");
208+
209+
if (apiToken == "") {
210+
WriteLog("error", "[gofile.io] API token required for folder creation");
211+
return ResultCode.Failure;
212+
}
213+
214+
local parentFolderId = parentAlbum.getId();
215+
216+
if (parentFolderId == "") {
217+
parentFolderId = _ObtainRootFolder(apiToken);
218+
}
219+
220+
local folderName = album.getTitle();
221+
222+
nm.setUrl(API_BASE_URL + "/contents/createFolder");
223+
nm.addQueryHeader("Authorization", "Bearer " + apiToken);
224+
nm.addQueryHeader("Content-Type", "application/json");
225+
226+
local requestData = {
227+
parentFolderId = parentFolderId
228+
};
229+
230+
if (folderName != "") {
231+
requestData.folderName <- folderName;
232+
}
233+
234+
nm.doPost(ToJSON(requestData));
235+
236+
local t = ParseJSON(nm.responseBody());
237+
if (t != null && "status" in t && t.status == "ok" && "data" in t) {
238+
album.setId(t.data.id);
239+
album.setTitle(t.data.name);
240+
album.setViewUrl("https://gofile.io/d/" + t.data.code);
241+
return ResultCode.Success;
242+
} else {
243+
_PrintError(t, "Failed to create folder");
244+
return ResultCode.Failure;
245+
}
246+
}
247+
248+
/**
249+
* Modify a folder (update name, description) (optional function)
250+
* @var CFolderItem album
251+
* @return int - success(1), failure(0)
252+
*/
253+
function ModifyFolder(album) {
254+
local apiToken = ServerParams.getParam("Password");
255+
256+
if (apiToken == "") {
257+
WriteLog("error", "[gofile.io] API token required for folder modification");
258+
return ResultCode.Failure;
259+
}
260+
261+
local folderId = album.getId();
262+
local folderName = album.getTitle();
263+
264+
nm.setUrl(API_BASE_URL + "/contents/" + folderId + "/update");
265+
nm.addQueryHeader("Authorization", "Bearer " + apiToken);
266+
nm.addQueryHeader("Content-Type", "application/json");
267+
268+
local requestData = {
269+
attribute = "name",
270+
attributeValue = folderName
271+
};
272+
273+
nm.doPut(ToJSON(requestData));
274+
275+
local t = ParseJSON(nm.responseBody());
276+
if (t != null && "status" in t && t.status == "ok") {
277+
return ResultCode.Success;
278+
} else {
279+
_PrintError(t, "Failed to modify folder");
280+
return ResultCode.Failure;
281+
}
282+
}
283+
284+
/**
285+
* A function that returns a list of types of access restrictions to an album
286+
* @return array
287+
*/
288+
function GetFolderAccessTypeList() {
289+
return ["Public", "Private"];
290+
}
291+
292+
/**
293+
* Define server parameters that user can configure
294+
* @return table
295+
*/
296+
function GetServerParamList() {
297+
return {
298+
uploadRegion = {
299+
title = "Upload Region",
300+
type = "choice",
301+
items = [
302+
{
303+
id = "auto",
304+
label = "Automatic (Closest Region)"
305+
},
306+
{
307+
id = "eu-par",
308+
label = "Europe (Paris)"
309+
},
310+
{
311+
id = "na-phx",
312+
label = "North America (Phoenix)"
313+
},
314+
{
315+
id = "ap-sgp",
316+
label = "Asia Pacific (Singapore)"
317+
},
318+
{
319+
id = "ap-hkg",
320+
label = "Asia Pacific (Hong Kong)"
321+
},
322+
{
323+
id = "ap-tyo",
324+
label = "Asia Pacific (Tokyo)"
325+
},
326+
{
327+
id = "sa-sao",
328+
label = "South America (São Paulo)"
329+
}
330+
]
331+
}
332+
}
333+
}

Data/servers.xml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,15 +1331,28 @@
13311331
</Actions>
13321332
<Result ImageUrlTemplate="stub" ThumbUrlTemplate="stub" DownloadUrlTemplate="stub"/>
13331333
</Server>
1334-
<Server Name="8upload.com" Authorize="1" MaxFileSize="50331648" Plugin="8upload" WebsiteUrl="https://8upload.com/" RegistrationUrl="https://8upload.com/myaccount/registration.php">
1334+
<Server Name="8upload.com" Authorize="1" MaxFileSize="50331648" Plugin="8upload" WebsiteUrl="https://8upload.com/" RegistrationUrl="https://8upload.com/myaccount/registration.php">
13351335
<Info>
13361336
<SupportedFormats>
13371337
<FormatGroup MaxFileSize="12582912">
13381338
<Format MimeType="image/jpeg">*.jpg,*.jpeg</Format>
13391339
<Format MimeType="image/png">*.png</Format>
1340+
<Format MimeType="image/webp">*.webp</Format>
13401341
<Format MimeType="image/gif">*.gif</Format>
1342+
<Format MimeType="image/bmp">*.bmp</Format>
1343+
<Format MimeType="image/vnd.adobe.photoshop">*.psd</Format>
1344+
<Format MimeType="image/tiff">*.tif,*.tiff</Format>
1345+
<Format MimeType="image/x-xbitmap">*.xmb</Format>
1346+
<Format MimeType="image/avif">*.avif</Format>
1347+
<Format MimeType="application/x-shockwave-flash">*.swf</Format>
1348+
<Format MimeType="image/jp2">*.jpc,*.jp2,*.jpx</Format>
1349+
<Format MimeType="image/jb2">*.jb2</Format>
1350+
<Format MimeType="image/iff">*.iff</Format>
13411351
</FormatGroup>
13421352
</SupportedFormats>
1353+
<StorageTimeInfo>
1354+
<StorageTime>-1</StorageTime>
1355+
</StorageTimeInfo>
13431356
</Info>
13441357
<Actions>
13451358
</Actions>
@@ -1367,6 +1380,31 @@
13671380
</Actions>
13681381
<Result DownloadUrlTemplate="stub"/>
13691382
</Server>
1383+
<Server Name="imgchest.com" MaxFileSize="10485760" Authorize="2" PasswordLabel="API token" WebsiteUrl="https://imgchest.com/" RegistrationUrl="https://imgchest.com/register">
1384+
<Info>
1385+
<SupportedFormats>
1386+
<FormatGroup MaxFileSize="10485760" UserTypes="reg">
1387+
<Format MimeType="image/jpeg">*.jpg,*.jpeg</Format>
1388+
<Format MimeType="image/png">*.png</Format>
1389+
<Format MimeType="image/gif">*.gif</Format>
1390+
<Format MimeType="image/webp">*.webp</Format>
1391+
</FormatGroup>
1392+
</SupportedFormats>
1393+
</Info>
1394+
<Actions>
1395+
<Action Type="upload" Url="https://api.imgchest.com/v1/post" PostParams="images[]=%filename%;" CustomHeaders="Authorization:Bearer $(_PASSWORD)">
1396+
<Call Function="json" Arg1="data.id" AssignVars="FileId:0;" Required="1"/>
1397+
<Call Function="json" Arg1="data.images[0].link" AssignVars="DirectUrl:0;" Required="0"/>
1398+
<Call Function="json" Arg1="data.delete_url" AssignVars="DeleteUrl:0;" Required="0"/>
1399+
</Action>
1400+
</Actions>
1401+
<Result ImageUrlTemplate="$(DirectUrl)" DownloadUrlTemplate="https://imgchest.com/p/$(FileId)" DeleteUrl="$(DeleteUrl)" />
1402+
</Server>
1403+
<Server Name="gofile.io" Type="file" MaxFileSize="-1" Authorize="1" Plugin="gofile" WebsiteUrl="https://gofile.io/" PasswordLabel="API token" SupportsFolders="0">
1404+
<Actions>
1405+
</Actions>
1406+
<Result ImageUrlTemplate="stub" ThumbUrlTemplate="stub" DeleteUrl="stub"/>
1407+
</Server>
13701408
<!--<Server Name="imgpile.com" Authorize="1" Plugin="imgpile" WebsiteUrl="https://imgpile.com/" RegistrationUrl="https://imgpile.com/registerr">
13711409
<Actions>
13721410
</Actions>

0 commit comments

Comments
 (0)