mirror of
https://github.com/zotero/zotero.git
synced 2026-09-28 01:31:40 +00:00
Rename attachments imported from stream (#5148)
This commit is contained in:
parent
cc87ff3af6
commit
f2a86e4af9
1 changed files with 12 additions and 6 deletions
|
|
@ -1010,21 +1010,27 @@ Zotero.Attachments = new function () {
|
|||
let collections = options.collections;
|
||||
let title = options.title;
|
||||
let saveOptions = options.saveOptions;
|
||||
|
||||
if (!title) {
|
||||
// TODO Better attachment name
|
||||
title = Zotero.getString('itemFields.attachmentPDF');
|
||||
}
|
||||
|
||||
if (parentItemID && collections) {
|
||||
throw new Error("parentItemID and collections cannot both be provided");
|
||||
}
|
||||
|
||||
// Create a temporary file
|
||||
let filename;
|
||||
if (parentItemID) {
|
||||
let parentItem = Zotero.Items.get(parentItemID);
|
||||
let fileBaseName = this.getFileBaseNameFromItem(parentItem, { attachmentTitle: title });
|
||||
let ext = this._getExtensionFromURL(url, contentType);
|
||||
filename = fileBaseName + (ext != '' ? '.' + ext : '');
|
||||
}
|
||||
else {
|
||||
filename = Zotero.File.truncateFileName(this._getFileNameFromURL(url, contentType), 100);
|
||||
}
|
||||
|
||||
let tmpDirectory = (await this.createTemporaryStorageDirectory()).path;
|
||||
let destDirectory;
|
||||
let attachmentItem;
|
||||
try {
|
||||
let filename = Zotero.File.truncateFileName(this._getFileNameFromURL(url, contentType), 100);
|
||||
let tmpFile = OS.Path.join(tmpDirectory, filename);
|
||||
await Zotero.File.putNetworkStream(tmpFile, stream, options.byteCount);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue