From 5d53b51c9143ba928ef3d676156173c1cdef2f26 Mon Sep 17 00:00:00 2001 From: JustOff Date: Sun, 7 Oct 2018 00:25:10 +0300 Subject: [PATCH] Switch download links from AMO to cloud storage --- README.md | 2 +- bootstrap.js | 43 ++++++++++++++++++++++++++++++++++++++++++- content/about.js | 5 ++--- content/addon.js | 5 +++-- content/list.js | 2 +- content/versions.js | 8 +++++--- install.rdf | 2 +- 7 files changed, 55 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 746076a..9bb0b89 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bootstrap.js b/bootstrap.js index 8617cec..6da7acf 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -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); @@ -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); @@ -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 @@ -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()); diff --git a/content/about.js b/content/about.js index 47d30ba..a82b116 100644 --- a/content/about.js +++ b/content/about.js @@ -85,10 +85,9 @@ let About = {

Who creates these add-ons?

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.

The source of data

-

All the data contained in this catalog was obtained from publicly available sources such as AMO, Wayback Machine 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, Wayback Machine and other open Internet directories and collections. Cloud storage is kindly provided by Waterfox Project.

Legal notices

-

Except as noted below, this catalog is released under Mozilla Public License, version 2.0. The design is based on AMO website by Mozilla and adapted by JustOff under CC-BY-SA-3.0. 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.

- +

Except as noted below, this catalog is released under Mozilla Public License, version 2.0. The design is based on AMO website by Mozilla and adapted by JustOff under CC-BY-SA-3.0. 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.

diff --git a/content/addon.js b/content/addon.js index 514437f..6868c29 100644 --- a/content/addon.js +++ b/content/addon.js @@ -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' }); diff --git a/content/list.js b/content/list.js index 5ba91a0..6caa286 100644 --- a/content/list.js +++ b/content/list.js @@ -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"); diff --git a/content/versions.js b/content/versions.js index 9b0ac10..6449cf4 100644 --- a/content/versions.js +++ b/content/versions.js @@ -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 = ""; @@ -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; } diff --git a/install.rdf b/install.rdf index ee07c12..181af85 100644 --- a/install.rdf +++ b/install.rdf @@ -10,7 +10,7 @@ Catalog of classic Firefox add-ons created before WebExtensions apocalypse Off JustOff <Off.Just.Off@gmail.com> https://github.com/JustOff/ca-archive/ - https://raw.githubusercontent.com/JustOff/ca-archive/master/update.xml + https://ca-archive.biz.tm/update.xml {ec8030f7-c20a-464f-9b0e-13a3a9e97384}