fix(core): update
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartjimp',
|
||||
version: '1.0.5',
|
||||
name: '@push.rocks/smartjimp',
|
||||
version: '1.0.6',
|
||||
description: 'a tool fr working with images in TypeScript'
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ export class SmartJimp {
|
||||
* get a key that is unique for a wanted asset variation
|
||||
*/
|
||||
private getCacheKey(
|
||||
sourceTypeArg: 'path' | 'url' | 'smartfile',
|
||||
sourceTypeArg: 'streamfile' | 'smartfile',
|
||||
sourceIdArg: string,
|
||||
wantedDimensionsArg?: IDimensions
|
||||
) {
|
||||
@ -33,47 +33,15 @@ export class SmartJimp {
|
||||
}
|
||||
let sharpImage = plugins.sharp(assetBuffer);
|
||||
sharpImage = sharpImage.resize(wantedDimensions.width, wantedDimensions.height);
|
||||
const result = await sharpImage.resize(wantedDimensions.width, wantedDimensions.height).jpeg().toBuffer();
|
||||
const result = await sharpImage.resize(wantedDimensions.width, wantedDimensions.height).avif().toBuffer();
|
||||
return result;
|
||||
}
|
||||
|
||||
public async getFromPath(pathArg: string, wantedDimensionsArg?: IDimensions) {
|
||||
const cacheKey = this.getCacheKey('path', pathArg, wantedDimensionsArg);
|
||||
const existingCacheEntry = await this.levelCache.retrieveCacheEntryByKey(cacheKey);
|
||||
if (existingCacheEntry) {
|
||||
return existingCacheEntry.contents;
|
||||
} else {
|
||||
const originalAssetSmartfile = await plugins.smartfile.Smartfile.fromFilePath(pathArg);
|
||||
const computedAssetBuffer = await this.computeAssetVariation(originalAssetSmartfile.contentBuffer, wantedDimensionsArg);
|
||||
this.levelCache.storeCacheEntryByKey(cacheKey, new plugins.levelcache.CacheEntry({
|
||||
contents: computedAssetBuffer,
|
||||
ttl: 600000
|
||||
}));
|
||||
return computedAssetBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
public async getFromUrl(urlArg: string, wantedDimensionsArg?: IDimensions) {
|
||||
const cacheKey = this.getCacheKey('url', urlArg, wantedDimensionsArg);
|
||||
const existingCacheEntry = await this.levelCache.retrieveCacheEntryByKey(cacheKey);
|
||||
if (existingCacheEntry) {
|
||||
return existingCacheEntry.contents;
|
||||
} else {
|
||||
const originalAssetBuffer = (await plugins.smartrequest.getBinary(urlArg)).body;
|
||||
const computedAssetBuffer = await this.computeAssetVariation(originalAssetBuffer, wantedDimensionsArg);
|
||||
this.levelCache.storeCacheEntryByKey(cacheKey, new plugins.levelcache.CacheEntry({
|
||||
contents: computedAssetBuffer,
|
||||
ttl: 600000
|
||||
}));
|
||||
return computedAssetBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
public async getFromSmartfile(
|
||||
smartfileArg: plugins.smartfile.Smartfile,
|
||||
smartfileArg: plugins.smartfile.SmartFile,
|
||||
wantedDimensionsArg?: IDimensions
|
||||
) {
|
||||
const cacheKey = this.getCacheKey('url', await smartfileArg.getHash(), wantedDimensionsArg);
|
||||
const cacheKey = this.getCacheKey('smartfile', await smartfileArg.getHash(), wantedDimensionsArg);
|
||||
const existingCacheEntry = await this.levelCache.retrieveCacheEntryByKey(cacheKey);
|
||||
if (existingCacheEntry) {
|
||||
return existingCacheEntry.contents;
|
||||
@ -86,4 +54,11 @@ export class SmartJimp {
|
||||
return computedAssetBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
public async createAvifImageFromBuffer(bufferArg: Buffer) {
|
||||
const sharpImage = plugins.sharp(bufferArg);
|
||||
const result = await sharpImage.avif().toBuffer();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,11 +4,11 @@ import * as path from 'path';
|
||||
export { path };
|
||||
|
||||
// @pushrocks scope
|
||||
import * as levelcache from '@pushrocks/levelcache';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smarthash from '@pushrocks/smarthash';
|
||||
import * as smartpath from '@pushrocks/smartpath';
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
import * as levelcache from '@push.rocks/levelcache';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smarthash from '@push.rocks/smarthash';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
import * as smartrequest from '@push.rocks/smartrequest';
|
||||
|
||||
export { levelcache, smartpath, smarthash, smartfile, smartrequest };
|
||||
|
||||
|
Reference in New Issue
Block a user