Skip to content

Commit

Permalink
Fixed bug where exported files could be named "null"
Browse files Browse the repository at this point in the history
  • Loading branch information
corbindavenport committed Oct 15, 2021
1 parent 19db3d7 commit 599ae7a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ function importFiles(files, element = null) {
var filename = file.name
if (filename.includes('.')) {
filename = filename.slice(0, filename.indexOf("."))
image.setAttribute('data-file-name', filename)
image.setAttribute('data-filename', filename)
} else {
image.setAttribute('data-file-name', filename)
image.setAttribute('data-filename', filename)
}
// Resolve promise
console.log('Processed image:', file.name)
Expand Down Expand Up @@ -418,9 +418,9 @@ function importFiles(files, element = null) {
var filename = file.name
if (filename.includes('.')) {
filename = filename.slice(0, filename.indexOf("."))
image.setAttribute('data-file-name', filename)
image.setAttribute('data-filename', filename)
} else {
image.setAttribute('data-file-name', filename)
image.setAttribute('data-filename', filename)
}
// Resolve promise
console.log('Processed image:', file.name)
Expand Down Expand Up @@ -477,10 +477,10 @@ function importWebImage(url) {
var filename = url.split('/').pop().split('#')[0].split('?')[0]
filename = decodeURIComponent(filename) // Revert URI encoding
filename = filename.slice(0, filename.indexOf(".")) // Remove file ending
image.setAttribute('data-file-name', filename)
image.setAttribute('data-filename', filename)
} catch (error) {
console.error('Error obtaining filename for image:', error)
image.setAttribute('data-file-name', 'Image ' + (globalFilesCount + 1))
image.setAttribute('data-filename', 'Image ' + (globalFilesCount + 1))
}
// Load image
image.onload = async function () {
Expand Down Expand Up @@ -579,7 +579,6 @@ function asyncExport() {
canvasContainer.appendChild(canvas)
canvas.width = original.naturalWidth
canvas.height = original.naturalHeight
canvas.setAttribute('data-file-name', original.getAttribute('data-file-name'))
canvas.getContext('2d').drawImage(original, 0, 0)
// Apply settings
if (document.getElementById('photostack-watermark-select').value === 'no-watermark') {
Expand All @@ -595,6 +594,8 @@ function asyncExport() {
})
canvas = await applyCanvasSettings(canvas, watermarkObject)
}
// Retain file name
canvas.dataset.filename = original.dataset.filename
// Update progress bar and page title
const previousProgress = parseInt(progressBar.getAttribute('aria-valuenow'))
const newProgress = previousProgress + imgStep
Expand All @@ -610,7 +611,7 @@ function asyncExport() {
var promises = $.map(canvases, function (canvas) {
return new Promise(function (resolve) {
canvas.toBlob(function (blob) {
resolve([blob, canvas.getAttribute('data-file-name')])
resolve([blob, canvas.getAttribute('data-filename')])
}, imgFormat, imgQuality)
})
})
Expand Down

0 comments on commit 599ae7a

Please sign in to comment.