Merge branch 'dev' into 2358-route_download_pdf
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
7e494962cd
|
@ -55,8 +55,9 @@ module.exports = Self => {
|
|||
};
|
||||
|
||||
await fs.mkdir(dstDir, {recursive: true});
|
||||
await sharp(srcFilePath)
|
||||
await sharp(srcFilePath, {failOnError: false})
|
||||
.resize(collection.maxWidth, collection.maxHeight, resizeOpts)
|
||||
.png()
|
||||
.toFile(dstFile);
|
||||
|
||||
const sizes = collection.sizes();
|
||||
|
@ -69,8 +70,9 @@ module.exports = Self => {
|
|||
};
|
||||
|
||||
await fs.mkdir(dstDir, {recursive: true});
|
||||
await sharp(srcFilePath)
|
||||
await sharp(srcFilePath, {failOnError: false})
|
||||
.resize(size.width, size.height, resizeOpts)
|
||||
.png()
|
||||
.toFile(dstFile);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,45 +20,48 @@ module.exports = Self => {
|
|||
const models = Self.app.models;
|
||||
|
||||
try {
|
||||
const imageQueue = await Self.find({where: {error: null}, limit: 25});
|
||||
/* const tempPath = path.join('/tmp/salix-image'); */
|
||||
const rootPath = models.Image.getPath();
|
||||
const tempPath = path.join(rootPath, 'temp');
|
||||
const tempPath = path.join('/tmp/salix-image');
|
||||
|
||||
// Create temporary path
|
||||
await fs.mkdir(tempPath, {recursive: true});
|
||||
|
||||
for (let image of imageQueue) {
|
||||
const timer = setInterval(async() => {
|
||||
const image = await Self.findOne({where: {error: null}});
|
||||
|
||||
// Exit loop
|
||||
if (!image) return clearInterval(timer);
|
||||
|
||||
const fileName = `${image.itemFk}.png`;
|
||||
const filePath = path.join(tempPath, fileName);
|
||||
const file = fs.createWriteStream(filePath);
|
||||
|
||||
https.get(image.url, async response => {
|
||||
if (response.statusCode != 200) {
|
||||
const error = new Error(`Could not download the image. Status code ${response.statusCode}`);
|
||||
const writeStream = fs.createWriteStream(filePath);
|
||||
writeStream.on('open', () => {
|
||||
https.get(image.url, async response => {
|
||||
if (response.statusCode != 200) {
|
||||
const error = new Error(`Could not download the image. Status code ${response.statusCode}`);
|
||||
|
||||
file.close();
|
||||
await errorHandler(image.itemFk, error, filePath);
|
||||
}
|
||||
|
||||
response.pipe(file);
|
||||
|
||||
file.on('error', async error => {
|
||||
await errorHandler(image.itemFk, error, filePath);
|
||||
});
|
||||
|
||||
file.on('finish', async function() {
|
||||
try {
|
||||
await models.Image.registerImage('catalog', fileName, filePath);
|
||||
await image.destroy();
|
||||
} catch (error) {
|
||||
await errorHandler(image.itemFk, error, filePath);
|
||||
return await errorHandler(image.itemFk, error, filePath);
|
||||
}
|
||||
|
||||
response.pipe(writeStream);
|
||||
}).on('error', async error => {
|
||||
await errorHandler(image.itemFk, error, filePath);
|
||||
});
|
||||
}).on('error', async error => {
|
||||
});
|
||||
|
||||
writeStream.on('error', async error => {
|
||||
await errorHandler(image.itemFk, error, filePath);
|
||||
});
|
||||
}
|
||||
|
||||
writeStream.on('finish', async function() {
|
||||
try {
|
||||
await models.Image.registerImage('catalog', fileName, filePath);
|
||||
await image.destroy();
|
||||
} catch (error) {
|
||||
await errorHandler(image.itemFk, error, filePath);
|
||||
}
|
||||
});
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
await errorHandler(image.itemFk, error);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue