Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
Stable Release
Browse files Browse the repository at this point in the history
  • Loading branch information
sim0n00ps committed Oct 2, 2023
1 parent da0d9c3 commit ba3e57e
Show file tree
Hide file tree
Showing 7 changed files with 312 additions and 279 deletions.
6 changes: 3 additions & 3 deletions GoFile DL/Entities/CreateAccountResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace GoFile_DL.Entities
{
public class CreateAccountResponse
{
public string status { get; set; }
public Data data { get; set; }
public string? status { get; set; }
public Data? data { get; set; }
public class Data
{
public string token { get; set; }
public string? token { get; set; }
}
}
}
8 changes: 4 additions & 4 deletions GoFile DL/Entities/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace GoFile_DL.Entities
{
public class File
{
public string Id { get; set; }
public string Name { get; set; }
public string DownloadLink { get; set; }
public string? Id { get; set; }
public string? Name { get; set; }
public string? DownloadLink { get; set; }
public long Size { get; set; }
public string MD5Hash { get; set; }
public string? MD5Hash { get; set; }
}
}
19 changes: 11 additions & 8 deletions GoFile DL/Entities/Folder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace GoFile_DL.Entities
{
public class Folder
{
public string Id { get; set; }
public string Name { get; set; }
public string? Id { get; set; }
public string? Name { get; set; }
public List<Folder> Folders { get; set; }
public List<File> Files { get; set; }
public string DownloadPath { get; set; }
public string? DownloadPath { get; set; }
public Folder()
{
Folders = new List<Folder>();
Expand All @@ -21,13 +21,16 @@ public Folder()

public async Task IterateFoldersAsync(Func<Folder, string, Task> folderActionAsync, string currentPath)
{
string folderPath = Path.Combine(currentPath, Name);
if(!string.IsNullOrEmpty(Name))
{
string folderPath = Path.Combine(currentPath, Name);

await folderActionAsync(this, folderPath);
await folderActionAsync(this, folderPath);

foreach (var subfolder in Folders)
{
await subfolder.IterateFoldersAsync(folderActionAsync, folderPath);
foreach (var subfolder in Folders)
{
await subfolder.IterateFoldersAsync(folderActionAsync, folderPath);
}
}
}
}
Expand Down
38 changes: 19 additions & 19 deletions GoFile DL/Entities/GetContentResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,40 @@ namespace GoFile_DL.Entities
{
public class GetContentResponse
{
public string status { get; set; }
public Data data { get; set; }
public string? status { get; set; }
public Data? data { get; set; }
public class Data
{
public bool isOwner { get; set; }
public string id { get; set; }
public string type { get; set; }
public string name { get; set; }
public string parentFolder { get; set; }
public string code { get; set; }
public string? id { get; set; }
public string? type { get; set; }
public string? name { get; set; }
public string? parentFolder { get; set; }
public string? code { get; set; }
public long createTime { get; set; }
public bool @public { get; set; }
public List<string> childs { get; set; }
public List<string>? childs { get; set; }
public int totalDownloadCount { get; set; }
public long totalSize { get; set; }
public Dictionary<string, Content> contents { get; set; }
public Dictionary<string, Content>? contents { get; set; }
}

public class Content
{
public string id { get; set; }
public string type { get; set; }
public string name { get; set; }
public string parentFolder { get; set; }
public string? id { get; set; }
public string? type { get; set; }
public string? name { get; set; }
public string? parentFolder { get; set; }
public long createTime { get; set; }
public List<string> childs { get; set; }
public string code { get; set; }
public List<string>? childs { get; set; }
public string? code { get; set; }
public bool @public { get; set; }
public long size { get; set; }
public int downloadCount { get; set; }
public string md5 { get; set; }
public string mimetype { get; set; }
public string serverChoosen { get; set; }
public string link { get; set; }
public string? md5 { get; set; }
public string? mimetype { get; set; }
public string? serverChoosen { get; set; }
public string? link { get; set; }
public bool overloaded { get; set; }
}
}
Expand Down
88 changes: 47 additions & 41 deletions GoFile DL/Helpers/APIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class APIHelper : IAPIHelper
{
response.EnsureSuccessStatusCode();
string body = await response.Content.ReadAsStringAsync();
CreateAccountResponse account = JsonConvert.DeserializeObject<CreateAccountResponse>(body);
if (account != null && account.status == "ok")
CreateAccountResponse? account = JsonConvert.DeserializeObject<CreateAccountResponse?>(body);
if (account != null && account.data != null && account.data.token != null && account.status == "ok")
{
return account.data.token;
}
Expand Down Expand Up @@ -76,27 +76,30 @@ public class APIHelper : IAPIHelper
{
try
{
Dictionary<string, string> getParams = new()
if(config != null && !string.IsNullOrEmpty(config.Token) && !string.IsNullOrEmpty(config.SiteToken))
{
{ "contentId", contentId },
{ "token", config.Token },
{ "websiteToken", config.SiteToken }
};
string queryParams = "?" + string.Join("&", getParams.Select(kvp => $"{kvp.Key}={kvp.Value}"));
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri("https://api.gofile.io/getContent" + queryParams)
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
string body = await response.Content.ReadAsStringAsync();
GetContentResponse content = JsonConvert.DeserializeObject<GetContentResponse>(body);
if(content != null)
Dictionary<string, string> getParams = new()
{
{ "contentId", contentId },
{ "token", config.Token },
{ "websiteToken", config.SiteToken }
};
string queryParams = "?" + string.Join("&", getParams.Select(kvp => $"{kvp.Key}={kvp.Value}"));
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage
{
return content;
Method = HttpMethod.Get,
RequestUri = new Uri("https://api.gofile.io/getContent" + queryParams)
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
string body = await response.Content.ReadAsStringAsync();
GetContentResponse? content = JsonConvert.DeserializeObject<GetContentResponse?>(body);
if (content != null)
{
return content;
}
}
}
}
Expand All @@ -110,28 +113,31 @@ public class APIHelper : IAPIHelper
{
try
{
Dictionary<string, string> getParams = new()
if(config != null && !string.IsNullOrEmpty(config.Token) && !string.IsNullOrEmpty(config.SiteToken))
{
{ "contentId", contentId },
{ "token", config.Token },
{ "websiteToken", config.SiteToken },
{ "password", password }
};
string queryParams = "?" + string.Join("&", getParams.Select(kvp => $"{kvp.Key}={kvp.Value}"));
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri("https://api.gofile.io/getContent" + queryParams)
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
string body = await response.Content.ReadAsStringAsync();
GetContentResponse content = JsonConvert.DeserializeObject<GetContentResponse>(body);
if (content != null)
Dictionary<string, string> getParams = new()
{
{ "contentId", contentId },
{ "token", config.Token },
{ "websiteToken", config.SiteToken },
{ "password", password }
};
string queryParams = "?" + string.Join("&", getParams.Select(kvp => $"{kvp.Key}={kvp.Value}"));
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage
{
return content;
Method = HttpMethod.Get,
RequestUri = new Uri("https://api.gofile.io/getContent" + queryParams)
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
string body = await response.Content.ReadAsStringAsync();
GetContentResponse? content = JsonConvert.DeserializeObject<GetContentResponse?>(body);
if (content != null)
{
return content;
}
}
}
}
Expand Down
36 changes: 22 additions & 14 deletions GoFile DL/Helpers/APIParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ static APIParser()
}
public async Task<Folder> ParseApiResponse(GetContentResponse response, Config config)
{
Folder rootFolder = new Folder
if(response != null && response.data != null && response.data.contents != null)
{
Id = response.data.id,
Name = response.data.name,
Folders = new List<Folder>(),
Files = new List<File>()
};
Folder? rootFolder = new Folder
{
Id = response.data.id,
Name = response.data.name,
Folders = new List<Folder>(),
Files = new List<File>()
};

// Recursively parse contents
await ParseContents(response.data.contents, rootFolder.Folders, rootFolder.Files, config);
await ParseContents(response.data.contents, rootFolder.Folders, rootFolder.Files, config);

return rootFolder;
return rootFolder;
}
return new Folder();
}

public async Task ParseContents(Dictionary<string, GetContentResponse.Content> contents, List<Folder> folders, List<File> files, Config config)
Expand All @@ -44,9 +47,14 @@ public async Task ParseContents(Dictionary<string, GetContentResponse.Content> c
};
folders.Add(folder);

// Fetch folder content dynamically
var folderContentResponse = await FetchFolderContentAsync(content.name, content.id, config); // Implement this method to make the API request
await ParseContents(folderContentResponse.data.contents, folder.Folders, folder.Files, config);
if(content != null && content.name != null && content.id != null)
{
GetContentResponse? folderContentResponse = await FetchFolderContentAsync(content.name, content.id, config);
if (folderContentResponse != null && folderContentResponse.data != null && folderContentResponse.data.contents != null)
{
await ParseContents(folderContentResponse.data.contents, folder.Folders, folder.Files, config);
}
}
}
else if (content.type == "file")
{
Expand All @@ -63,9 +71,9 @@ public async Task ParseContents(Dictionary<string, GetContentResponse.Content> c
}
}

private async Task<GetContentResponse> FetchFolderContentAsync(string folderName, string folderId, Config config)
private async Task<GetContentResponse?> FetchFolderContentAsync(string folderName, string folderId, Config config)
{
GetContentResponse getContentResponse = await aPIHelper.GetContent(folderId, config);
GetContentResponse? getContentResponse = await aPIHelper.GetContent(folderId, config);
if (getContentResponse != null && getContentResponse.status == "ok")
{
return getContentResponse;
Expand Down
Loading

0 comments on commit ba3e57e

Please sign in to comment.