refs #5576 perf: remove bad try/catch declarations
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Javier Segarra 2024-01-20 11:22:41 +00:00
parent 55b737f376
commit 16cb42761e
1 changed files with 23 additions and 36 deletions

View File

@ -62,10 +62,6 @@ module.exports = Self => {
Self.removeLink = async(child, parent = null) => {
try {
await fs.unlink(child);
} catch (e) {
throw new Error(e);
}
try {
await fs.symlink(parent, child);
} catch (e) {
throw new Error(e);
@ -75,10 +71,6 @@ module.exports = Self => {
try {
const exists = await fs.exists(parent);
exists && await fs.unlink(parent);
} catch (e) {
throw new Error(e);
}
try {
await fs.symlink(child, parent);
} catch (e) {
throw new Error(e);
@ -102,41 +94,36 @@ module.exports = Self => {
...baseUpsert,
updated: Date.vnNow() / 1000,
});
} catch (e) {
throw new Error(e);
}
const collection = await Self.getCollection(collectionName);
const {maxWidth, maxHeight} = collection;
// Update entity image file name
const model = models[collection.model];
if (!model) throw new Error('No matching model found');
const collection = await Self.getCollection(collectionName);
const {maxWidth, maxHeight} = collection;
const entity = await model.findById(entityId);
if (entity)
await entity.updateAttribute(collection.property, name);
// Update entity image file name
const model = models[collection.model];
if (!model) throw new Error('No matching model found');
// Resize
const collectionDir = await Self.getCollectionDir(collectionName);
const entity = await model.findById(entityId);
if (entity)
await entity.updateAttribute(collection.property, name);
// To max size
const _fullSizePath = Self.getFullSizePath(fileName, collectionDir, dstDir);
// Resize
const collectionDir = await Self.getCollectionDir(collectionName);
// To max size
const _fullSizePath = Self.getFullSizePath(fileName, collectionDir, dstDir);
const {fullSizePath, toFullSizePath, toFullSizeOriginalPath} = _fullSizePath;
const {fullSizePath, toFullSizePath, toFullSizeOriginalPath} = _fullSizePath;
try {
await fs.mkdir(fullSizePath, {recursive: true});
} catch (e) {
throw new Error(e);
}
const gmInstance = gm(srcFile);
let fileWidth = null;
let fileHeight = null;
gmInstance.size(function(err, size) {
if (err) throw new Error(err);
[fileWidth, fileHeight] = parseSize(size);
});
try {
const gmInstance = gm(srcFile);
let fileWidth = null;
let fileHeight = null;
gmInstance.size(function(err, size) {
if (err) throw new Error(err);
[fileWidth, fileHeight] = parseSize(size);
});
await new Promise((resolve, reject) => {
gmInstance
.resize(maxWidth, maxHeight, '>')