diff --git a/back/models/image.js b/back/models/image.js index f7fb08bfa..fd3535e46 100644 --- a/back/models/image.js +++ b/back/models/image.js @@ -74,15 +74,12 @@ module.exports = Self => { Self.createLink = async(parent, child = null) => { try { const exists = await fs.exists(parent); - if (exists) - await fs.unlink(parent); + exists && await fs.unlink(parent); } catch (e) { throw new Error(e); } try { await fs.symlink(child, parent); - const link = await fs.readlink(parent); - console.log(link); } catch (e) { throw new Error(e); } @@ -96,17 +93,16 @@ module.exports = Self => { }) { const {name, dstDir} = await Self.handleFolderDestination(fileName); try { - await models.Image.upsertWithWhere({ + const baseUpsert = { name, collectionFk: collectionName, - }, - { - name, - collectionFk: collectionName, - updated: Date.vnNow() / 1000, - }); + }; + await models.Image.upsertWithWhere(baseUpsert, + { + ...baseUpsert, + updated: Date.vnNow() / 1000, + }); } catch (e) { - debugger; throw new Error(e); } const collection = await Self.getCollection(collectionName); @@ -130,7 +126,6 @@ module.exports = Self => { try { await fs.mkdir(fullSizePath, {recursive: true}); } catch (e) { - debugger; throw new Error(e); } const gmInstance = gm(srcFile); @@ -138,7 +133,7 @@ module.exports = Self => { let fileHeight = null; gmInstance.size(function(err, size) { - if (err) console.error(err); + if (err) throw new Error(err); [fileWidth, fileHeight] = parseSize(size); }); try { @@ -153,23 +148,10 @@ module.exports = Self => { }); }); } catch (e) { - debugger; throw new Error(e); } await Self.createLink(toFullSizeOriginalPath, toFullSizePath); - /* try { - await fs.unlink(toFullSizeOriginalPath); - } catch (e) { - debugger; - throw new Error(e); - } - try { - await fs.symlink(toFullSizeOriginalPath, toFullSizePath, 'file'); - } catch (e) { - debugger; - throw new Error(e); - }*/ // To collection sizes for (const size of collection.sizes()) { const [width, height] = parseSize(size); @@ -182,7 +164,6 @@ module.exports = Self => { try { await fs.mkdir(sizePath, {recursive: true}); } catch (e) { - debugger; throw new Error(e); } @@ -216,7 +197,6 @@ module.exports = Self => { const toSizeOriginalPath = `${sizeOriginalPath}/${fileName}`; - // if (fileWidth > width && fileHeight < height) await Self.createLink(toSizeOriginalPath, toSizePath); } };