fix(core): update
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user