From b5264f5c46211ebc5e45926d4cde31c167a1ba1b Mon Sep 17 00:00:00 2001
From: Unknown
Date: Sat, 16 Jun 2018 11:25:14 +0100
Subject: try to fix a bug...and fail
---
pkg93.js | 111 ++++++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 67 insertions(+), 44 deletions(-)
diff --git a/pkg93.js b/pkg93.js
index 3861991..a73e908 100644
--- a/pkg93.js
+++ b/pkg93.js
@@ -94,7 +94,6 @@ var _abarpkg93uses = (width, percent) => {
return pbar;
};
-
var pkg93 = {
getConfig: function() {
try {
@@ -107,42 +106,57 @@ var pkg93 = {
cli = cli || {log: (i) => {$log(i);}};
var config = pkg93.getConfig();
config.pkglist = [];
- for (let source of config.repos) {
- cli.log("GET " + source + "/repo.json");
- var bardiv = cli.log(_abarpkg93uses(60, 0));
- var xhr = new XMLHttpRequest();
- xhr.open("GET", source + "/repo.json", true);
- xhr.onprogress = e => {
- bardiv.innerHTML = _abarpkg93uses(60, e.loaded / e.total);
- };
- return new Promise((res, rej) => {
- xhr.onerror = () => {
- cli.log("ERR Fatal error while retriving package.json.");
- rej();
- };
- xhr.onload = () => {
- var json = JSON.parse(xhr.responseText);
- cli.log("NAME " + json.name);
- cli.log("MSG " + json.msg);
- for (let item of json.packages) {
+ return new Promise((res, rej) => {
+ for (let source of config.repos) {
+ try {
+ console.log(source);
+ cli.log("GET " + source + "/repo.json");
+ var bardiv = cli.log(_abarpkg93uses(60, 0));
+ var xhr = new XMLHttpRequest();
+ xhr.open("GET", source + "/repo.json", true);
+ xhr.onprogress = e => {
+ bardiv.innerHTML = _abarpkg93uses(60, e.loaded / e.total);
+ };
+ xhr.onerror = () => {
+ cli.log("ERR Fatal error while retriving package.json.");
+ };
+ xhr.onload = () => {
try {
- config.pkglist.push(item + "@" + source);
- cli.log("OK " + item + "@" + source);
+ console.log(xhr.responseText);
+ var json = JSON.parse(xhr.responseText);
+ cli.log("NAME " + json.name);
+ cli.log("MSG " + json.msg);
+ for (let item of json.packages) {
+ try {
+ config.pkglist.push(item + "@" + source);
+ cli.log("OK " + item + "@" + source);
+ } catch (err) {
+ cli.log("ERR " + err.message);
+ }
+ }
} catch (err) {
+ console.error(err);
cli.log("ERR " + err.message);
+ console.log(xhr.responseText);
+ rej();
}
- }
- localStorage[".pkg93/config.json"] = JSON.stringify(config);
- res();
- };
- xhr.send();
- });
- }
+ };
+ xhr.send();
+ } catch (err) {
+ cli.log("ERR " + err.message);
+ } finally {
+ delete window.xhr;
+ }
+ }
+ localStorage[".pkg93/config.json"] = JSON.stringify(config);
+ res();
+ });
},
- get: async function(pkg, cli) {
+ get: async function(pkg, ver, cli) {
cli = cli || {log: (i) => {$log(i);}};
+ ver = ver || "latest";
var config = pkg93.getConfig();
- cli.log("SRCH " + pkg);
+ cli.log("SRCH " + pkg + "@" + ver);
var index = config.pkglist.findIndex(function(string) {
return string.split("@")[0] == pkg;
});
@@ -153,10 +167,11 @@ var pkg93 = {
cli.log("OK Found!");
var pkgname = config.pkglist[index].split("@")[0];
var pkgsource = config.pkglist[index].split("@")[1];
- cli.log("GET " + pkgsource + "/" + pkgname + "/package.json");
+ var dest = pkgsource + "/" + pkgname + "/package.json";
+ cli.log("GET " + dest);
var bardiv = cli.log(_abarpkg93uses(60, 0));
var xhr = new XMLHttpRequest();
- xhr.open("GET", pkgsource + "/" + pkgname + "/package.json", true);
+ xhr.open("GET", dest, true);
xhr.setRequestHeader("X-Requested-With", "pkg93");
xhr.onprogress = e => {
try {
@@ -172,13 +187,20 @@ var pkg93 = {
};
xhr.onload = () => {
try {
- cli.log("DONE " + pkgsource + "/" + pkgname + "/package.json");
+ if (xhr.status != 200) {
+ throw new Error("Got status " + xhr.status + " from server.");
+ }
+ cli.log("DONE " + dest);
var json = JSON.parse(xhr.responseText);
localStorage[".pkg93/packages/" + pkgname + ".json"] = JSON.stringify(json);
- cli.log("GET " + pkgsource + "/" + pkgname + "/" + json.inject);
+ if (ver == "latest") {
+ ver = json.versions[0];
+ }
+ var dest2 = pkgsource + "/" + pkgname + "/" + ver + "/" + json.inject;
+ cli.log("GET " + dest2);
var bardiv2 = cli.log(_abarpkg93uses(60, 0));
var xhr2 = new XMLHttpRequest();
- xhr2.open("GET", pkgsource + "/" + pkgname + "/" + json.inject);
+ xhr2.open("GET", dest2, true);
xhr2.setRequestHeader("X-Requested-With", "pkg93");
xhr2.onprogress = e => {
try {
@@ -188,18 +210,21 @@ var pkg93 = {
}
};
xhr2.onerror = () => {
- cli.log("ERR Fatal error while retriving " + pkgsource + "/" + pkgname + "/" + json.inject);
+ cli.log("ERR Fatal error while retriving " + dest2);
rej();
};
xhr2.onload = async () => {
try {
- cli.log("DONE " + pkgsource + "/" + pkgname + "/" + json.inject);
+ if (xhr2.status != 200) {
+ throw new Error("Got status " + xhr2.status + " from server.");
+ }
+ cli.log("DONE " + dest2);
var script = xhr2.responseText;
localStorage[".pkg93/packages/" + pkgname + ".js"] = script;
eval(script);
if (json.uninstall) {
// no xhr this time
- var uninst = await (await (fetch(pkgsource + "/" + pkgname + "/" + json.uninstall))).text();
+ var uninst = await (await (fetch(pkgsource + "/" + pkgname + "/" + ver + "/" + json.uninstall))).text();
localStorage[".pkg93/packages/" + pkgname + ".rm.js"] = uninst;
}
cli.log("OK Injected package!");
@@ -310,15 +335,12 @@ async function _pkg93execdonotcallplsusetheapi(cli) {
rm-repo [id] Removes a repository
info [pkg] Gets information on a package
ls [pkgs|installed|repos] Lists packages, installed
- packages or repositories.
+ packages or repositories.
credits Displays the credits
+
Color meanings
Executing OK Error Warning Info
-Examples
-pkg93 get gud
-pkg93 rm kebab
-
If you find my software useful, consider donating here.
`;
if (localStorage[".pkg93/config.json"] === undefined) {
@@ -339,7 +361,8 @@ If you find my software useful, consider donating ERR You're trying to modify a pre-installed Windows93 app.\n Don't do that!");
} else {
- await pkg93.get(args[1], cli);
+ var split = args[1].split("@");
+ await pkg93.get(split[0], split[1], cli);
}
} else if (args[0] == "rm") {
if (args.length < 2) {
--
cgit v1.2.3