Asynced credits and more (#223)

* let me cook

* shut up

* offline part but cached bitmaps wont work raaaaaah

* bitch it works

* github node in credits.xml and more

have to finish the no api method

* non api method working

im baaack, ive been kinda busy these days

* balls

* done ig

* non api method first

* less tries

* forgor to update the non github part
This commit is contained in:
⍚~Nex
2024-02-04 00:52:05 -07:00
committed by GitHub
parent 38ea98c52e
commit a71a02ea94
10 changed files with 251 additions and 52 deletions
+80 -6
View File
@@ -9,8 +9,8 @@ import haxe.Http;
class GitHub {
/**
* Gets all the releases from a specific GitHub repository using the GitHub API.
* @param user
* @param repository
* @param user The user/group that owns the repository
* @param repository The repository name
* @return Releases
*/
public static function getReleases(user:String, repository:String, ?onError:Exception->Void):Array<GitHubRelease> {
@@ -29,6 +29,12 @@ class GitHub {
return [];
}
/**
* Gets the contributors list from a specific GitHub repository using the GitHub API.
* @param user The user/group that owns the repository
* @param repository The repository name
* @return Contributors List
*/
public static function getContributors(user:String, repository:String, ?onError:Exception->Void):Array<GitHubContributor> {
try {
var url = 'https://api.github.com/repos/${user}/${repository}/contributors';
@@ -45,6 +51,27 @@ class GitHub {
return [];
}
/**
* Gets a specific GitHub user/group using the GitHub API.
* @param user The user/group to get
* @return User/Group
*/
public static function getUser(user:String, ?onError:Exception->Void):GitHubUser {
try {
var url = 'https://api.github.com/users/$user';
var data = Json.parse(__requestOnGitHubServers(url));
if (Reflect.hasField(data, "documentation_url"))
throw __parseGitHubException(data);
return data;
} catch(e) {
if (onError != null)
onError(e);
}
return null;
}
/**
* Filters all releases gotten by `getReleases`
* @param releases Releases
@@ -58,29 +85,52 @@ class GitHub {
public static function __requestOnGitHubServers(url:String) {
var h = new Http(url);
h.setHeader("User-Agent", "request");
var r = null;
h.onStatus = function(s) {
if(isRedirect(s))
r = __requestOnGitHubServers(h.responseHeaders.get("Location"));
};
h.onData = function(d) {
r = d;
if(r == null) r = d;
}
h.onError = function(e) {
throw e;
}
h.request(false);
return r;
}
public static function __requestBytesOnGitHubServers(url:String) {
var h = new Http(url);
h.setHeader("User-Agent", "request");
var r = null;
h.onStatus = function(s) {
if(isRedirect(s))
r = __requestBytesOnGitHubServers(h.responseHeaders.get("Location"));
};
h.onBytes = function(d) {
r = d;
if(r == null) r = d;
}
h.onError = function(e) {
throw e;
}
h.request(false);
return r;
}
private static function isRedirect(status:Int):Bool {
switch (status) {
// 301: Moved Permanently, 302: Found (Moved Temporarily), 307: Temporary Redirect, 308: Permanent Redirect - Nex_isDumb
case 301 | 302 | 307 | 308 :
trace("Redirected with status code: " + status);
return true;
}
return false;
}
private static function __parseGitHubException(obj:Dynamic):GitHubException {
var msg:String = "(No message)";
var url:String = "(No API url)";
@@ -99,18 +149,33 @@ import haxe.Exception;
class GitHub {
/**
* Gets all the releases from a specific GitHub repository using the GitHub API.
* @param user
* @param repository
* @param user The user/group that owns the repository
* @param repository The repository name
* @return Releases
*/
public static function getReleases(user:String, repository:String, ?onError:Exception->Void):Array<GitHubRelease> {
return [];
}
/**
* Gets the contributors list from a specific GitHub repository using the GitHub API.
* @param user The user/group that owns the repository
* @param repository The repository name
* @return Contributors List
*/
public static function getContributors(user:String, repository:String, ?onError:Exception->Void):Array<GitHubContributor> {
return [];
}
/**
* Gets a specific GitHub user/group using the GitHub API.
* @param user The user/group to get
* @return User/Group
*/
public static function getUser(user:String, ?onError:Exception->Void):GitHubUser {
return null;
}
/**
* Filters all releases gotten by `getReleases`
* @param releases Releases
@@ -130,5 +195,14 @@ class GitHub {
private static function __parseGitHubException(obj:Dynamic):GitHubException {
return null;
}
private static function isRedirect(status:Int):Bool {
switch (status) {
// 301: Moved Permanently, 302: Found (Moved Temporarily), 307: Temporary Redirect, 308: Permanent Redirect - Nex_isDumb
case 301 | 302 | 307 | 308 :
trace("Redirected with status code: " + status);
return true;
}
return false;
}
}
#end