Skip to content

Commit

Permalink
Switch download links from AMO to cloud storage
Browse files Browse the repository at this point in the history
  • Loading branch information
JustOff committed Oct 6, 2018
1 parent 0d6e08b commit 5d53b51
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The add-ons listed here have been created by a wide range of developers from ind

### The source of data

All the data contained in this catalog was obtained from publicly available sources such as [AMO](https://addons.mozilla.org/), [Wayback Machine](http://web.archive.org/) and other open Internet directories and collections. All download links currently also point to AMO, an independent repository is under way. Any help with hosting the main data storage or mirror is highly welcomed.
All the data contained in this catalog was obtained from publicly available sources such as [AMO](https://addons.mozilla.org/), [Wayback Machine](http://web.archive.org/) and other open Internet directories and collections. Cloud storage is kindly provided by [Waterfox Project](https://www.waterfoxproject.org/).

### Legal notices

Expand Down
43 changes: 42 additions & 1 deletion bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const CAA_MODULES = [
"chrome://ca-archive/content/versions.js"
];

let factory, gWindowListener = null, branch = "extensions.ca-archive.";
let factory, storageHost, gWindowListener = null, branch = "extensions.ca-archive.";

let styleSheetService = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
let styleSheetURI = Services.io.newURI("chrome://ca-archive/skin/button.css", null, null);
Expand Down Expand Up @@ -293,6 +293,43 @@ function Factory(component) {
this.register();
}

let httpObserver = {
observe: function(subject, topic, data) {
if (topic == "http-on-examine-response" || topic == "http-on-examine-cached-response") {
subject.QueryInterface(Ci.nsIHttpChannel);
if (subject.URI.host == storageHost) {
if (/origin=caa&action=install$/.test(subject.URI.path)) {
subject.setResponseHeader("Content-Disposition", "", false);
} else if (/origin=caa&action=download$/.test(subject.URI.path)) {
subject.setResponseHeader("Content-Disposition", "attachment", false);
}
} else if (subject.URI.host == "ca-archive.biz.tm") {
if (subject.responseStatus == "302" && /^\/storage\//.test(subject.URI.path)) {
let redirect;
if ((redirect = /^https?:\/\/(.+?)\//.exec(subject.getResponseHeader("Location"))) !== null) {
storageHost = redirect[1];
}
}
}
}
},
QueryInterface: function(aIID) {
if (aIID.equals(Ci.nsIObserver) || aIID.equals(Ci.nsISupports)) {
return this;
} else {
throw Cr.NS_NOINTERFACE;
}
},
register: function() {
Services.obs.addObserver(this, "http-on-examine-response", false);
Services.obs.addObserver(this, "http-on-examine-cached-response", false);
},
unregister: function() {
Services.obs.removeObserver(this, "http-on-examine-response");
Services.obs.removeObserver(this, "http-on-examine-cached-response");
}
}

function startup(data, reason) {
if (!styleSheetService.sheetRegistered(styleSheetURI, styleSheetService.USER_SHEET)) {
styleSheetService.loadAndRegisterSheet(styleSheetURI, styleSheetService.USER_SHEET);
Expand All @@ -305,6 +342,8 @@ function startup(data, reason) {
defaultBranch.setCharPref("before", "");
defaultBranch.setCharPref("url", "caa:about");

httpObserver.register();

gWindowListener = new BrowserWindowObserver({
onStartup: browserWindowStartup,
onShutdown: browserWindowShutdown
Expand All @@ -323,6 +362,8 @@ function shutdown(data, reason) {
Services.ww.unregisterNotification(gWindowListener);
gWindowListener = null;

httpObserver.unregister();

let winenu = Services.wm.getEnumerator("navigator:browser");
while (winenu.hasMoreElements()) {
browserWindowShutdown(winenu.getNext());
Expand Down
5 changes: 2 additions & 3 deletions content/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ let About = {
<h2>Who creates these add-ons?</h2>
<p>The add-ons listed here have been created by a wide range of developers from individual hobbyists to large corporations and were reviewed by a team of AMO editors before being released. Add-ons marked as Experimental have not been reviewed and should be installed with caution.</p>
<h2>The source of data</h2>
<p>All the data contained in this catalog was obtained from publicly available sources such as <a target="_blank" href="https://addons.mozilla.org">AMO</a>, <a target="_blank" href="http://web.archive.org/">Wayback Machine</a> and other open Internet directories and collections. All download links currently also point to AMO, an independent repository is under way. Any help with hosting the main data storage or mirror is highly welcomed.</p>
<p>All the data contained in this catalog was obtained from publicly available sources such as <a target="_blank" href="https://addons.mozilla.org">AMO</a>, <a target="_blank" href="http://web.archive.org/">Wayback Machine</a> and other open Internet directories and collections. Cloud storage is kindly provided by <a target="_blank" href="https://www.waterfoxproject.org/">Waterfox Project</a>.</p>
<h2>Legal notices</h2>
<p>Except as noted below, this catalog is released under <a target="_blank" href="http://www.mozilla.org/MPL/2.0/">Mozilla Public License, version 2.0</a>. The design is based on AMO website by <a target="_blank" href="https://www.mozilla.org">Mozilla</a> and adapted by JustOff under <a target="_blank" href="http://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA-3.0</a>. All product names, logos and brands are property of their respective owners, specific licenses are indicated in the description of each add-on. All company, product and service names used in this catalog are for identification purposes only. </p>
<p>Except as noted below, this catalog is released under <a target="_blank" href="http://www.mozilla.org/MPL/2.0/">Mozilla Public License, version 2.0</a>. The design is based on AMO website by <a target="_blank" href="https://www.mozilla.org">Mozilla</a> and adapted by JustOff under <a target="_blank" href="http://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA-3.0</a>. All product names, logos and brands are property of their respective owners, specific licenses are indicated in the description of each add-on. All company, product and service names used in this catalog are for identification purposes only.</p>
</div>
</div>
Expand Down
5 changes: 3 additions & 2 deletions content/addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,15 @@ let Addon = {
} else if (Services.appinfo.name != "SeaMonkey") {
appver = Services.appinfo.version;
}
data.downurl = "https://ca-archive.biz.tm/storage/" + Math.trunc(dbQuery.row.addon_id/1000) + "/" + dbQuery.row.addon_id + "/" + dbQuery.row.url.replace(/^\d+\/(.*)/,"$1") + "?origin=caa&action=";
if (appver && Services.vc.compare(dbQuery.row.min, appver) <= 0 && Services.vc.compare(appver, dbQuery.row.max) <= 0) {
data.compat = "add";
data.action = "Install Now";
data.downurl = "https://addons.mozilla.org/firefox/downloads/file/" + dbQuery.row.url;
data.downurl += "install";
} else {
data.compat = "download";
data.action = "Download";
data.downurl = "https://addons.mozilla.org/firefox/downloads/file/" + dbQuery.row.url.replace("/", "/type:attachment/");
data.downurl += "download";
}
let created = new Date(dbQuery.row.created*1000);
data.created = created.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
Expand Down
2 changes: 1 addition & 1 deletion content/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ let List = {
if (appver && Services.vc.compare(dbQuery.row.min, appver) <= 0 && Services.vc.compare(appver, dbQuery.row.max) <= 0) {
item = item.replace("%COMPAT%", "add");
item = item.replace("%ACTION%", "Install Now");
item = item.replace("%DOWNURL%", "https://addons.mozilla.org/firefox/downloads/file/" + dbQuery.row.url);
item = item.replace("%DOWNURL%", "https://ca-archive.biz.tm/storage/" + Math.trunc(dbQuery.row.addon_id/1000) + "/" + dbQuery.row.addon_id + "/" + dbQuery.row.url.replace(/^\d+\/(.*)/,"$1") + "?origin=caa&action=install");
} else {
item = item.replace("%COMPAT%", "download");
item = item.replace("%ACTION%", "List Versions");
Expand Down
8 changes: 5 additions & 3 deletions content/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ let Versions = {
data.next = parseInt(page) + 1;
}

dbQuery = db.createStatement("SELECT is_experimental, version, platform, release_notes, is_restart_required, versions.url AS url, min, max, size, created, licenses.name AS lic_name, licenses.url AS lic_url FROM addons INNER JOIN versions ON addons.addon_id = versions.addon_id LEFT JOIN licenses ON licenses.license_id = versions.license_id WHERE addons." + col + " = :query ORDER BY created DESC LIMIT 30 OFFSET :offset");
dbQuery = db.createStatement("SELECT addons.addon_id AS addon_id, is_experimental, version, platform, release_notes, is_restart_required, versions.url AS url, min, max, size, created, licenses.name AS lic_name, licenses.url AS lic_url FROM addons INNER JOIN versions ON addons.addon_id = versions.addon_id LEFT JOIN licenses ON licenses.license_id = versions.license_id WHERE addons." + col + " = :query ORDER BY created DESC LIMIT 30 OFFSET :offset");
dbQuery.params.query = query;
dbQuery.params.offset = pfrom - 1;
data.items = "";
Expand Down Expand Up @@ -113,15 +113,17 @@ let Versions = {
} else if (Services.appinfo.name != "SeaMonkey") {
appver = Services.appinfo.version;
}
let downurl = "https://ca-archive.biz.tm/storage/" + Math.trunc(dbQuery.row.addon_id/1000) + "/" + dbQuery.row.addon_id + "/" + dbQuery.row.url.replace(/^\d+\/(.*)/,"$1") + "?origin=caa&action=";
if (appver && Services.vc.compare(dbQuery.row.min, appver) <= 0 && Services.vc.compare(appver, dbQuery.row.max) <= 0) {
item = item.replace("%COMPAT%", "add");
item = item.replace("%ACTION%", "Install Now");
item = item.replace("%DOWNURL%", "https://addons.mozilla.org/firefox/downloads/file/" + dbQuery.row.url);
downurl += "install";
} else {
item = item.replace("%COMPAT%", "download");
item = item.replace("%ACTION%", "Download");
item = item.replace("%DOWNURL%", "https://addons.mozilla.org/firefox/downloads/file/" + dbQuery.row.url.replace("/", "/type:attachment/"));
downurl += "download";
}
item = item.replace("%DOWNURL%", downurl);

data.items += item;
}
Expand Down
2 changes: 1 addition & 1 deletion install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<em:description>Catalog of classic Firefox add-ons created before WebExtensions apocalypse</em:description>
<em:creator>Off JustOff &lt;[email protected]&gt;</em:creator>
<em:homepageURL>https://github.com/JustOff/ca-archive/</em:homepageURL>
<em:updateURL>https://raw.githubusercontent.com/JustOff/ca-archive/master/update.xml</em:updateURL>
<em:updateURL>https://ca-archive.biz.tm/update.xml</em:updateURL>
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
Expand Down

0 comments on commit 5d53b51

Please sign in to comment.