Я новичок в веб-разработке (или программировании в целом) и пишу коды для своего личного проекта. Я пишу код облачной функции Firebase в Javascript для автоматического поворота, сжатия и преобразования в прогрессивный JPEG после загрузки изображения с использованием ImageMagick. Но приведенная ниже часть кода создает бесконечное l oop в бэкэнде после загрузки изображения и запуска функции.
Любой совет, что пошло не так? Я предполагаю, что это должно что-то делать с Javascript Promise, и мне, вероятно, придется возвращать что-то в конце каждого случая if / else, но не уверен, куда смотреть ... может кто-нибудь помочь?
if (metadata.autoOrient) { //Check if the image is already rotated and skip auto-rotation
console.log('This is already rotated');
return mkdirp(tempLocalDir).then(() => {
// Download file from bucket.
return bucket.file(filePath).download({destination: tempLocalFile})
}).then(() => {
// Convert the image using ImageMagick.
return spawn('convert', [tempLocalFile, '-quality', '85', '-interlace', 'plane', tempLocalFile])
}).then(() => {
metadata.autoOrient = true
return bucket.upload(tempLocalFile, {
destination: filePath,
metadata: {metadata: metadata}
})
}).then(() => {
// Once the image has been converted delete the local files to free up disk space.
fs.unlinkSync(tempLocalFile)
console.log('Compression and PJPEG convsersion successful');
})
}
else { //Image is not rotated, thus do all the operations
return mkdirp(tempLocalDir).then(() => {
// Download file from bucket.
return bucket.file(filePath).download({destination: tempLocalFile})
}).then(() => {
// Convert the image using ImageMagick.
return spawn('convert', [tempLocalFile, '-auto-orient', '-quality', '85', '-interlace', 'plane', tempLocalFile])
}).then(() => {
metadata.autoOrient = true
return bucket.upload(tempLocalFile, {
destination: filePath,
metadata: {metadata: metadata}
})
}).then(() => {
// Once the image has been converted delete the local files to free up disk space.
fs.unlinkSync(tempLocalFile)
console.log('Auto rotation, compression and PJPEG convsersion successful')
})
}