refs #5576 feat update db/change version
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
9cbf30d17c
commit
f6d0cf7817
|
@ -49,15 +49,19 @@ module.exports = Self => {
|
|||
};
|
||||
|
||||
Self.getFullSizePath = (fileName, collectionDir, dstDir) => {
|
||||
const fullSizePath = path.join(collectionDir, `full/${dstDir}`);
|
||||
const fullSizeOriginalPath = path.join(collectionDir, `full`);
|
||||
const toFullSizePath = `${fullSizePath}/${fileName}`;
|
||||
const toFullSizeOriginalPath = `${fullSizeOriginalPath}/${fileName}`;
|
||||
return {
|
||||
fullSizePath,
|
||||
toFullSizePath,
|
||||
toFullSizeOriginalPath
|
||||
};
|
||||
try {
|
||||
const fullSizePath = path.join(collectionDir, `full/${dstDir}`);
|
||||
const fullSizeOriginalPath = path.join(collectionDir, `full`);
|
||||
const toFullSizePath = `${fullSizePath}/${fileName}`;
|
||||
const toFullSizeOriginalPath = `${fullSizeOriginalPath}/${fileName}`;
|
||||
return {
|
||||
fullSizePath,
|
||||
toFullSizePath,
|
||||
toFullSizeOriginalPath
|
||||
};
|
||||
} catch (e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
};
|
||||
Self.removeLink = async(child, parent = null) => {
|
||||
try {
|
||||
|
@ -94,7 +98,7 @@ module.exports = Self => {
|
|||
...baseUpsert,
|
||||
updated: Date.vnNow() / 1000,
|
||||
});
|
||||
|
||||
|
||||
const collection = await Self.getCollection(collectionName);
|
||||
const {maxWidth, maxHeight} = collection;
|
||||
|
||||
|
@ -113,9 +117,9 @@ module.exports = Self => {
|
|||
const _fullSizePath = Self.getFullSizePath(fileName, collectionDir, dstDir);
|
||||
|
||||
const {fullSizePath, toFullSizePath, toFullSizeOriginalPath} = _fullSizePath;
|
||||
|
||||
|
||||
await fs.mkdir(fullSizePath, {recursive: true});
|
||||
|
||||
|
||||
const gmInstance = gm(srcFile);
|
||||
let fileWidth = null;
|
||||
let fileHeight = null;
|
||||
|
@ -134,57 +138,57 @@ module.exports = Self => {
|
|||
if (!err) resolve(data);
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
|
||||
await Self.createLink(toFullSizeOriginalPath, toFullSizePath);
|
||||
// To collection sizes
|
||||
for (const size of collection.sizes()) {
|
||||
const [width, height] = parseSize(size);
|
||||
await Self.createLink(toFullSizeOriginalPath, toFullSizePath);
|
||||
// To collection sizes
|
||||
for (const size of collection.sizes()) {
|
||||
const [width, height] = parseSize(size);
|
||||
|
||||
const sizePath = path.join(
|
||||
collectionDir,
|
||||
`${formatWidthHeight(width, height)}/${dstDir}`
|
||||
);
|
||||
const sizePath = path.join(
|
||||
collectionDir,
|
||||
`${formatWidthHeight(width, height)}/${dstDir}`
|
||||
);
|
||||
|
||||
try {
|
||||
await fs.mkdir(sizePath, {recursive: true});
|
||||
} catch (e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
try {
|
||||
await fs.mkdir(sizePath, {recursive: true});
|
||||
} catch (e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
|
||||
const toSizePath = `${sizePath}/${fileName}`;
|
||||
if (+fileWidth < +width && +fileHeight < +height) {
|
||||
await new Promise((resolve, reject) => {
|
||||
if (size.crop) {
|
||||
gmInstance
|
||||
.resize(width, height, '^')
|
||||
.gravity(DEFAULT_GRAVITY)
|
||||
.crop(width, height).res(function(err, data) {
|
||||
if (err) reject(err);
|
||||
if (!err) resolve(data);
|
||||
});
|
||||
} else gmInstance.resize(width, height, '>');
|
||||
|
||||
const toSizePath = `${sizePath}/${fileName}`;
|
||||
if (+fileWidth < +width && +fileHeight < +height) {
|
||||
await new Promise((resolve, reject) => {
|
||||
if (size.crop) {
|
||||
gmInstance
|
||||
.resize(width, height, '^')
|
||||
.gravity(DEFAULT_GRAVITY)
|
||||
.crop(width, height).res(function(err, data) {
|
||||
.setFormat(PNG)
|
||||
.quality(DEFAULT_QUALITY)
|
||||
.write(toSizePath + `.${FORMAT}`, function(err, data) {
|
||||
if (err) reject(err);
|
||||
if (!err) resolve(data);
|
||||
});
|
||||
} else gmInstance.resize(width, height, '>');
|
||||
});
|
||||
}
|
||||
|
||||
gmInstance
|
||||
.setFormat(PNG)
|
||||
.quality(DEFAULT_QUALITY)
|
||||
.write(toSizePath + `.${FORMAT}`, function(err, data) {
|
||||
if (err) reject(err);
|
||||
if (!err) resolve(data);
|
||||
});
|
||||
});
|
||||
const sizeOriginalPath = path.join(
|
||||
collectionDir,
|
||||
formatWidthHeight(width, height)
|
||||
);
|
||||
|
||||
const toSizeOriginalPath = `${sizeOriginalPath}/${fileName}`;
|
||||
|
||||
await Self.createLink(toSizeOriginalPath, toSizePath);
|
||||
}
|
||||
|
||||
const sizeOriginalPath = path.join(
|
||||
collectionDir,
|
||||
formatWidthHeight(width, height)
|
||||
);
|
||||
|
||||
const toSizeOriginalPath = `${sizeOriginalPath}/${fileName}`;
|
||||
|
||||
await Self.createLink(toSizeOriginalPath, toSizePath);
|
||||
} catch (e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -35,24 +35,32 @@ describe('loopback model Image', () => {
|
|||
});
|
||||
|
||||
it('should handle folder destination', async() => {
|
||||
const {name, dstDir} = await models.Image.handleFolderDestination(obj.fileName);
|
||||
try {
|
||||
const {name, dstDir} = await models.Image.handleFolderDestination(obj.fileName);
|
||||
|
||||
expect(name).toEqual(nameItem);
|
||||
expect(dstDir).toEqual(`${_23_F2}`);
|
||||
const collectionDir = await models.Image.getCollectionDir(collectionName);
|
||||
expect(name).toEqual(nameItem);
|
||||
expect(dstDir).toEqual(`${_23_F2}`);
|
||||
const collectionDir = await models.Image.getCollectionDir(collectionName);
|
||||
|
||||
expect(collectionDir).toEqual(`${STORAGE_IMAGE_USER}`);
|
||||
expect(collectionDir).toEqual(`${STORAGE_IMAGE_USER}`);
|
||||
} catch (e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
});
|
||||
|
||||
it('should handle full size path', async() => {
|
||||
const {dstDir} = await models.Image.handleFolderDestination(obj.fileName);
|
||||
const collectionDir = await models.Image.getCollectionDir(collectionName);
|
||||
const _fullSizePath = models.Image.getFullSizePath(obj.fileName, collectionDir, dstDir);
|
||||
const {fullSizePath, toFullSizePath, toFullSizeOriginalPath} = _fullSizePath;
|
||||
try {
|
||||
const {dstDir} = await models.Image.handleFolderDestination(obj.fileName);
|
||||
const collectionDir = await models.Image.getCollectionDir(collectionName);
|
||||
const _fullSizePath = models.Image.getFullSizePath(obj.fileName, collectionDir, dstDir);
|
||||
const {fullSizePath, toFullSizePath, toFullSizeOriginalPath} = _fullSizePath;
|
||||
|
||||
expect(fullSizePath).toEqual(`${STORAGE_IMAGE_USER}/${FULL_23_F2}`);
|
||||
expect(toFullSizePath).toEqual(`${STORAGE_IMAGE_USER}/${FULL_23_F2}/${nameItem}`);
|
||||
expect(toFullSizeOriginalPath).toEqual(`${STORAGE_IMAGE_USER}/full/${nameItem}`);
|
||||
expect(fullSizePath).toEqual(`${STORAGE_IMAGE_USER}/${FULL_23_F2}`);
|
||||
expect(toFullSizePath).toEqual(`${STORAGE_IMAGE_USER}/${FULL_23_F2}/${nameItem}`);
|
||||
expect(toFullSizeOriginalPath).toEqual(`${STORAGE_IMAGE_USER}/full/${nameItem}`);
|
||||
} catch (e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
});
|
||||
|
||||
it('should resize', async() => {
|
||||
|
@ -71,10 +79,14 @@ describe('loopback model Image', () => {
|
|||
});
|
||||
|
||||
afterAll(async() => {
|
||||
await fs.unlink(`${STORAGE_IMAGE_USER}/full/${nameItem}`);
|
||||
try {
|
||||
await fs.unlink(`${STORAGE_IMAGE_USER}/full/${nameItem}`);
|
||||
|
||||
await fs.unlink(`${STORAGE_IMAGE_USER}/520x520/${nameItem}`);
|
||||
await fs.unlink(`${STORAGE_IMAGE_USER}/520x520/${nameItem}`);
|
||||
|
||||
await fs.unlink(`${STORAGE_IMAGE_USER}/1600x1600/${nameItem}`);
|
||||
await fs.unlink(`${STORAGE_IMAGE_USER}/1600x1600/${nameItem}`);
|
||||
} catch (e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
ALTER TABLE `hedera`.`imageConfig` ADD dirLevels INT UNSIGNED NOT NULL DEFAULT 2;
|
||||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||
VALUES
|
||||
('ImageConfig', '*', 'READ', 'ALLOW', 'ROLE', 'employee');
|
Loading…
Reference in New Issue