Zotero.File.download issues (I think) in version 6

63 views
Skip to first unread message

george.m...@gmail.com

unread,
Mar 24, 2022, 9:08:28 AM3/24/22
to zotero-dev
Hi there. I maintain http://mackerron.com/zot2bib/.

It's not working in Zotero 6 (even after bumping the max Zotero version in install.rdf).

The add-on relies on running an AppleScript, and it seems unable to extract that script from its bundle in order to run it.

This is the code that attempts to do this:

async function extractResource(resource) {
   return new Promise(function (resolve) {
    AddonManager.getAddonByID("zot...@mackerron.com", async function (addon) {
       const scriptURI = addon.getResourceURI(resource);
       const url = scriptURI.spec;

       const tmpDir = OS.Path.join(Zotero.getTempDirectory().path, 'Zot2Bib')
       await OS.File.makeDir(tmpDir);

       const filename = url.match(/\/([^\/]+)$/)[1];
       const path = OS.Path.join(tmpDir, filename);

       await Zotero.File.download(url, path);

       resolve(path);
     });
   });
}

var zoteroCallback = {
   notify: async function(event, type, ids, extraData) {
     if (event == 'add') {
       var items = Zotero.Items.get(ids);
       var script_path = await extractResource('zot2bib.applescript');
       // Zotero.log('AppleScript: ' + script_path);
       /* ... */

And these are the errors I get:

[JavaScript Error: "Error: Download failed with response code null" {file: "chrome://zotero/content/xpcom/file.js" line: 494}]

Any ideas what I can do to fix this?

The complete code is at https://github.com/jawj/Zot2Bib.

Many thanks,
George

george.m...@gmail.com

unread,
Mar 30, 2022, 9:43:34 AM3/30/22
to zotero-dev
I checked https://github.com/zotero/zotero/blob/master/chrome/content/zotero/xpcom/file.js. I see that Zotero.File.download has had some radical changes in the last year or two.

I tried replacing Zotero.File.download with Zotero.File.getContents(path) and Zotero.File.putContents(path, data). This raises no error, but does not appear to actually get and put anything: the tmp directory ~/Zotero/tmp/Zot2Bib remains empty.

I would appreciate some input on the right way to extract a file from an add-on XPI.

Tomasz Najdek

unread,
Mar 30, 2022, 12:45:27 PM3/30/22
to zoter...@googlegroups.com
Thanks for reporting, this problem should be resolved in the next release, here is a relevant commit:


------- Original Message -------
--
You received this message because you are subscribed to the Google Groups "zotero-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zotero-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zotero-dev/2c2abcc2-ae0b-4816-896a-bc91b6660492n%40googlegroups.com.

george.m...@gmail.com

unread,
Mar 30, 2022, 2:50:11 PM3/30/22
to zotero-dev
Thanks Tom, that diff looks very promising!
Reply all
Reply to author
Forward
0 new messages