@resoc/create-img
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -1,2 +0,2 @@ | ||
import { renderTemplateToHtml, ParamType, stringToParamValue } from '@resoc/core'; | ||
import { renderTemplateToHtml, ParamType, paramValueToString, stringToParamValue } from '@resoc/core'; | ||
import { promises } from 'fs'; | ||
@@ -275,3 +275,3 @@ import path from 'path'; | ||
var copyLocalResources = function (parameters, values, tmpDir) { return __awaiter(void 0, void 0, void 0, function () { | ||
var newValues, _i, parameters_1, param, value, dest; | ||
var newValues, _i, parameters_1, param, value, v, dest; | ||
return __generator(this, function (_a) { | ||
@@ -287,5 +287,7 @@ switch (_a.label) { | ||
value = values[param.name]; | ||
if (!(param.type === ParamType.ImageUrl && value && isLocalResource(value))) return [3 /*break*/, 3]; | ||
dest = tmpDir + "/" + v4() + "-" + path.basename(value); | ||
return [4 /*yield*/, promises.copyFile(value, dest)]; | ||
if (!(param.type === ParamType.ImageUrl && value)) return [3 /*break*/, 3]; | ||
v = paramValueToString(param, value); | ||
if (!isLocalResource(v)) return [3 /*break*/, 3]; | ||
dest = tmpDir + "/" + v4() + "-" + path.basename(v); | ||
return [4 /*yield*/, promises.copyFile(v, dest)]; | ||
case 2: | ||
@@ -302,2 +304,3 @@ _a.sent(); | ||
}); }; | ||
var isJpeg = function (imagePath) { return (imagePath && imagePath.toLowerCase().endsWith('.jpg') || imagePath.toLowerCase().endsWith('.jpeg')); }; | ||
var createImageFromTemplate = function (template, paramValues, resolution, imagePath, resourcePath, browser) { return __awaiter(void 0, void 0, void 0, function () { | ||
@@ -312,3 +315,3 @@ var htmlPath; | ||
path: imagePath, | ||
quality: 80, | ||
quality: isJpeg(imagePath) ? 80 : undefined, | ||
fullPage: true | ||
@@ -315,0 +318,0 @@ }, browser)]; |
@@ -287,3 +287,3 @@ 'use strict'; | ||
var copyLocalResources = function (parameters, values, tmpDir) { return __awaiter(void 0, void 0, void 0, function () { | ||
var newValues, _i, parameters_1, param, value, dest; | ||
var newValues, _i, parameters_1, param, value, v, dest; | ||
return __generator(this, function (_a) { | ||
@@ -299,5 +299,7 @@ switch (_a.label) { | ||
value = values[param.name]; | ||
if (!(param.type === core.ParamType.ImageUrl && value && isLocalResource(value))) return [3 /*break*/, 3]; | ||
dest = tmpDir + "/" + uuid.v4() + "-" + path__default['default'].basename(value); | ||
return [4 /*yield*/, fs.promises.copyFile(value, dest)]; | ||
if (!(param.type === core.ParamType.ImageUrl && value)) return [3 /*break*/, 3]; | ||
v = core.paramValueToString(param, value); | ||
if (!isLocalResource(v)) return [3 /*break*/, 3]; | ||
dest = tmpDir + "/" + uuid.v4() + "-" + path__default['default'].basename(v); | ||
return [4 /*yield*/, fs.promises.copyFile(v, dest)]; | ||
case 2: | ||
@@ -314,2 +316,3 @@ _a.sent(); | ||
}); }; | ||
var isJpeg = function (imagePath) { return (imagePath && imagePath.toLowerCase().endsWith('.jpg') || imagePath.toLowerCase().endsWith('.jpeg')); }; | ||
var createImageFromTemplate = function (template, paramValues, resolution, imagePath, resourcePath, browser) { return __awaiter(void 0, void 0, void 0, function () { | ||
@@ -324,3 +327,3 @@ var htmlPath; | ||
path: imagePath, | ||
quality: 80, | ||
quality: isJpeg(imagePath) ? 80 : undefined, | ||
fullPage: true | ||
@@ -327,0 +330,0 @@ }, browser)]; |
{ | ||
"name": "@resoc/create-img", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "Create an image based on a Resoc image template", | ||
@@ -60,3 +60,3 @@ "main": "build/index.js", | ||
}, | ||
"gitHead": "c03dd64ee237cf366de30a56da5fa70a271c7389" | ||
"gitHead": "5816c083a43cd6aaf44fb8cbf7e69b6da72ca927" | ||
} |
@@ -8,3 +8,4 @@ import { | ||
TemplateParam, | ||
ParamType | ||
ParamType, | ||
paramValueToString | ||
} from '@resoc/core' | ||
@@ -94,6 +95,9 @@ import { promises as fs } from 'fs' | ||
const value = values[param.name]; | ||
if (param.type === ParamType.ImageUrl && value && isLocalResource(value)) { | ||
const dest = `${tmpDir}/${uuidv4()}-${path.basename(value)}`; | ||
await fs.copyFile(value, dest); | ||
newValues[param.name] = dest; | ||
if (param.type === ParamType.ImageUrl && value) { | ||
const v = paramValueToString(param, value); | ||
if (isLocalResource(v)) { | ||
const dest = `${tmpDir}/${uuidv4()}-${path.basename(v)}`; | ||
await fs.copyFile(v, dest); | ||
newValues[param.name] = dest; | ||
} | ||
} | ||
@@ -104,2 +108,6 @@ } | ||
const isJpeg = (imagePath: string) => ( | ||
imagePath && imagePath.toLowerCase().endsWith('.jpg') || imagePath.toLowerCase().endsWith('.jpeg') | ||
) | ||
export const createImageFromTemplate = async ( | ||
@@ -113,3 +121,3 @@ template: ImageTemplate, paramValues: ParamValues, resolution: ImageResolution, imagePath: string, resourcePath?: string, browser?: Browser | ||
path: imagePath, | ||
quality: 80, | ||
quality: isJpeg(imagePath) ? 80 : undefined, | ||
fullPage: true | ||
@@ -116,0 +124,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
163675
1622