Fix uploading of embedded-image attachments
This commit is contained in:
parent
51f760fe1a
commit
60cb299f40
4 changed files with 37 additions and 7 deletions
|
@ -2291,6 +2291,9 @@ Zotero.Attachments = new function(){
|
||||||
case Zotero.Attachments.LINK_MODE_IMPORTED_FILE:
|
case Zotero.Attachments.LINK_MODE_IMPORTED_FILE:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Zotero.Attachments.LINK_MODE_EMBEDDED_IMAGE:
|
||||||
|
return false;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error("Invalid attachment link mode");
|
throw new Error("Invalid attachment link mode");
|
||||||
}
|
}
|
||||||
|
|
|
@ -2319,8 +2319,7 @@ Zotero.Item.prototype.getFilePath = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Imported file with relative path
|
// Imported file with relative path
|
||||||
if (linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_URL ||
|
if (this.isStoredFileAttachment()) {
|
||||||
linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_FILE) {
|
|
||||||
if (!path.includes("storage:")) {
|
if (!path.includes("storage:")) {
|
||||||
Zotero.logError("Invalid attachment path '" + path + "'");
|
Zotero.logError("Invalid attachment path '" + path + "'");
|
||||||
this._updateAttachmentStates(false);
|
this._updateAttachmentStates(false);
|
||||||
|
@ -3035,8 +3034,7 @@ Zotero.defineProperty(Zotero.Item.prototype, 'attachmentPath', {
|
||||||
val = Zotero.Attachments.resolveRelativePath(val) || val;
|
val = Zotero.Attachments.resolveRelativePath(val) || val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_URL ||
|
else if (this.isStoredFileAttachment()) {
|
||||||
linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_FILE) {
|
|
||||||
if (val && !val.startsWith('storage:')) {
|
if (val && !val.startsWith('storage:')) {
|
||||||
let storagePath = Zotero.Attachments.getStorageDirectory(this).path;
|
let storagePath = Zotero.Attachments.getStorageDirectory(this).path;
|
||||||
if (!val.startsWith(storagePath)) {
|
if (!val.startsWith(storagePath)) {
|
||||||
|
|
|
@ -502,13 +502,14 @@ Zotero.Sync.Storage.Local = {
|
||||||
*/
|
*/
|
||||||
getFilesToUpload: function (libraryID) {
|
getFilesToUpload: function (libraryID) {
|
||||||
var sql = "SELECT itemID FROM itemAttachments JOIN items USING (itemID) "
|
var sql = "SELECT itemID FROM itemAttachments JOIN items USING (itemID) "
|
||||||
+ "WHERE libraryID=? AND syncState IN (?,?) AND linkMode IN (?,?)";
|
+ "WHERE libraryID=? AND syncState IN (?,?) AND linkMode IN (?,?,?)";
|
||||||
var params = [
|
var params = [
|
||||||
libraryID,
|
libraryID,
|
||||||
this.SYNC_STATE_TO_UPLOAD,
|
this.SYNC_STATE_TO_UPLOAD,
|
||||||
this.SYNC_STATE_FORCE_UPLOAD,
|
this.SYNC_STATE_FORCE_UPLOAD,
|
||||||
Zotero.Attachments.LINK_MODE_IMPORTED_FILE,
|
Zotero.Attachments.LINK_MODE_IMPORTED_FILE,
|
||||||
Zotero.Attachments.LINK_MODE_IMPORTED_URL
|
Zotero.Attachments.LINK_MODE_IMPORTED_URL,
|
||||||
|
Zotero.Attachments.LINK_MODE_EMBEDDED_IMAGE,
|
||||||
];
|
];
|
||||||
return Zotero.DB.columnQueryAsync(sql, params);
|
return Zotero.DB.columnQueryAsync(sql, params);
|
||||||
},
|
},
|
||||||
|
@ -566,12 +567,13 @@ Zotero.Sync.Storage.Local = {
|
||||||
|
|
||||||
return Zotero.DB.executeTransaction(async function () {
|
return Zotero.DB.executeTransaction(async function () {
|
||||||
var sql = "SELECT itemID FROM items JOIN itemAttachments USING (itemID) "
|
var sql = "SELECT itemID FROM items JOIN itemAttachments USING (itemID) "
|
||||||
+ "WHERE libraryID=? AND itemTypeID=? AND linkMode IN (?, ?)";
|
+ "WHERE libraryID=? AND itemTypeID=? AND linkMode IN (?, ?, ?)";
|
||||||
var params = [
|
var params = [
|
||||||
libraryID,
|
libraryID,
|
||||||
Zotero.ItemTypes.getID('attachment'),
|
Zotero.ItemTypes.getID('attachment'),
|
||||||
Zotero.Attachments.LINK_MODE_IMPORTED_FILE,
|
Zotero.Attachments.LINK_MODE_IMPORTED_FILE,
|
||||||
Zotero.Attachments.LINK_MODE_IMPORTED_URL,
|
Zotero.Attachments.LINK_MODE_IMPORTED_URL,
|
||||||
|
Zotero.Attachments.LINK_MODE_EMBEDDED_IMAGE,
|
||||||
];
|
];
|
||||||
var itemIDs = await Zotero.DB.columnQueryAsync(sql, params);
|
var itemIDs = await Zotero.DB.columnQueryAsync(sql, params);
|
||||||
for (let itemID of itemIDs) {
|
for (let itemID of itemIDs) {
|
||||||
|
|
|
@ -854,6 +854,33 @@ describe("Zotero.Item", function () {
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
describe("#getFilePath()", function () {
|
||||||
|
it("should return the absolute path for an embedded image", async function () {
|
||||||
|
var note = await createDataObject('item', { itemType: 'note' });
|
||||||
|
|
||||||
|
var path = OS.Path.join(getTestDataDirectory().path, 'test.png');
|
||||||
|
var imageData = await Zotero.File.getBinaryContentsAsync(path);
|
||||||
|
var array = new Uint8Array(imageData.length);
|
||||||
|
for (let i = 0; i < imageData.length; i++) {
|
||||||
|
array[i] = imageData.charCodeAt(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
var blob = new Blob([array], { type: 'image/png' });
|
||||||
|
var attachment = await Zotero.Attachments.importEmbeddedImage({
|
||||||
|
blob,
|
||||||
|
parentItemID: note.id
|
||||||
|
});
|
||||||
|
|
||||||
|
var storageDir = Zotero.getStorageDirectory().path;
|
||||||
|
assert.equal(
|
||||||
|
OS.Path.join(storageDir, attachment.key, 'image.png'),
|
||||||
|
attachment.getFilePath()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
describe("#attachmentCharset", function () {
|
describe("#attachmentCharset", function () {
|
||||||
it("should get and set a value", function* () {
|
it("should get and set a value", function* () {
|
||||||
var charset = 'utf-8';
|
var charset = 'utf-8';
|
||||||
|
|
Loading…
Reference in a new issue