Comparing version 0.2.3 to 0.2.4
171
gia-ast.js
@@ -95,21 +95,21 @@ #!/bin/env node | ||
try { | ||
var tst=require('dotenv').config() | ||
if (tst.parsed) | ||
{ | ||
config = new Object() | ||
var {asthostname,astoutsuffix,astportbase,astcallprotocol,astcallmethod} = tst.parsed; | ||
config.hostname = asthostname; config.outsuffix = astoutsuffix; config.portbase = astportbase; config.callmethod = astcallmethod;config.callprotocol = astcallprotocol; | ||
config.src=".env";} | ||
var tst = require('dotenv').config() | ||
if (tst.parsed) { | ||
config = new Object() | ||
var { asthostname, astoutsuffix, astportbase, astcallprotocol, astcallmethod } = tst.parsed; | ||
config.hostname = asthostname; config.outsuffix = astoutsuffix; config.portbase = astportbase; config.callmethod = astcallmethod; config.callprotocol = astcallprotocol; | ||
config.src = ".env"; | ||
} | ||
} catch (error) { } | ||
try { | ||
//@a Init if we did not had a .env | ||
if (config == null ) { | ||
config = require('./config'); | ||
//@a Init if we did not had a .env | ||
if (config == null) { | ||
config = require('./config'); | ||
config.src="config"; | ||
} | ||
config.src = "config"; | ||
} | ||
@@ -131,17 +131,17 @@ | ||
if (process.env.asthostname) | ||
config.hostname = process.env.asthostname; | ||
config.hostname = process.env.asthostname; | ||
else envErr++; | ||
if (process.env.astoutsuffix) | ||
config.outsuffix = process.env.astoutsuffix; | ||
config.outsuffix = process.env.astoutsuffix; | ||
else envErr++; | ||
if ( process.env.astportbase) | ||
config.portbase = process.env.astportbase; | ||
if (process.env.astportbase) | ||
config.portbase = process.env.astportbase; | ||
else envErr++; | ||
if (process.env.astcallprotocol) | ||
config.callprotocol = process.env.astcallprotocol; | ||
config.callprotocol = process.env.astcallprotocol; | ||
else envErr++; | ||
if (process.env.astcallmethod) | ||
config.callmethod = process.env.astcallmethod; | ||
if (process.env.astcallmethod) | ||
config.callmethod = process.env.astcallmethod; | ||
else envErr++; | ||
config.src="var"; | ||
config.src = "var"; | ||
if (envErr > 0) { | ||
@@ -153,3 +153,3 @@ console.log("Env require setup"); | ||
//----grab-the-env | ||
} catch (error) { | ||
@@ -165,7 +165,7 @@ console.error("Require config.js or env var to be set"); | ||
if (args[0] == "--help" || args[0] == "-h" || args[0] == "-help" || args[0] == "--h" || !args[0] || !args[1]) { | ||
console.log(` | ||
console.log(` | ||
------------------------------------- | ||
AST Web API Stylizer CLI Wrapper | ||
by Guillaume D-Isabelle, 2021 | ||
Version 0.2.1 | ||
Version 0.2.4 | ||
-------------------------------------- | ||
@@ -176,3 +176,3 @@ -------------HELP---------------------- | ||
Synopsis: | ||
gia-ast [IMAGE] [ModelID] | ||
gia-ast <IMAGE-FILENAME> <ModelID> [x1] [x2] [x3] | ||
@@ -186,3 +186,3 @@ usage : | ||
`); | ||
if (!args[0] || !args[1]) console.log("MISSING ARGUMENTS"); | ||
if (!args[0] || !args[1]) console.log("MISSING ARGUMENTS"); | ||
} | ||
@@ -194,2 +194,3 @@ else // Lets do the work | ||
var imgFile = args[0]; | ||
var x1,x2,x3 = -1; | ||
var ext = path.extname(imgFile); | ||
@@ -199,10 +200,21 @@ var imgFileBasename = path.basename(imgFile); | ||
var resizeSwitch = false; | ||
var targetResolutionX = 768; | ||
if (args[2]) { | ||
resizeSwitch = true; | ||
targetResolutionX = Number(args[2]); | ||
} | ||
var targetResolutionX = 768; //DEPRECATING | ||
// if (args[2]) { | ||
// resizeSwitch = true; | ||
// targetResolutionX = Number(args[2]); | ||
// } | ||
if (args[2]) { x1 = Number(args[2]);} else x1 = -1 | ||
if (args[3]) { x2 = Number(args[3]);} else x2 = -1 | ||
if (args[4]) { x3 = Number(args[4]);} else x3 = -1 | ||
// console.log(` | ||
// x1:${x1} | ||
// x2:${x2} | ||
// x3:${x3} | ||
// `); | ||
//process.exit(1); | ||
//ModelID is related to a port will use | ||
@@ -213,27 +225,38 @@ var modelid = args[1]; | ||
var portnum = config.portbase + modelid; | ||
const callurl = config.callprotocol + "://" + config.hostname + ":" + portnum +"/" + config.callmethod.replace("/",""); | ||
const callurl = config.callprotocol + "://" + config.hostname + ":" + portnum + "/" + config.callmethod.replace("/", ""); | ||
console.log("Processing: " + imgFile + " at port :" + portnum); | ||
/* | ||
//Use later to resized the image if switch used | ||
sharp('input.jpg') | ||
.rotate() | ||
.resize(200) | ||
.jpeg({ mozjpeg: true }) | ||
.toBuffer() | ||
.then( data => { ... }) | ||
.catch( err => { ... }); | ||
*/ | ||
doWeResize(imgFile,config,portnum,callurl,targetOutput,resizeSwitch,targetResolutionX); | ||
/* | ||
//Use later to resized the image if switch used | ||
sharp('input.jpg') | ||
.rotate() | ||
.resize(200) | ||
.jpeg({ mozjpeg: true }) | ||
.toBuffer() | ||
.then( data => { ... }) | ||
.catch( err => { ... }); | ||
*/ | ||
// doWeResize(imgFile, config, portnum, callurl, targetOutput, resizeSwitch, targetResolutionX); | ||
doTheWork(imgFile, config, portnum, callurl, targetOutput,x1,x2,x3); | ||
} | ||
function doWeResize(imgFile,config,portnum,callurl,targetOutput,resizeSwitch=false,targetResolutionX=512) | ||
{ | ||
/** | ||
* | ||
* DEPRECATED | ||
* @param {*} imgFile | ||
* @param {*} config | ||
* @param {*} portnum | ||
* @param {*} callurl | ||
* @param {*} targetOutput | ||
* @param {*} resizeSwitch | ||
* @param {*} targetResolutionX | ||
*/ | ||
function doWeResize(imgFile, config, portnum, callurl, targetOutput, resizeSwitch = false, targetResolutionX = 512) { | ||
if (resizeSwitch) | ||
@@ -243,3 +266,3 @@ { | ||
//console.log("Tempfile:" + tfile); | ||
sharp(imgFile) | ||
@@ -256,3 +279,6 @@ .resize(targetResolutionX) | ||
} else //no resize command | ||
doTheWork(imgFile,config,portnum,callurl,targetOutput); | ||
{ | ||
console.log("Normal mode"); | ||
doTheWork(imgFile, config, portnum, callurl, targetOutput,x1,x2,x3); | ||
} | ||
@@ -263,8 +289,11 @@ | ||
function doTheWork(cFile,config,portnum,callurl,targetOutput) | ||
{ | ||
function doTheWork(cFile, config, portnum, callurl, targetOutput,x1=-1,x2=-1,x3=-1) { | ||
try { | ||
var data = giaenc. | ||
encFileToJSONStringifyBase64PropWithOptionalResolutions(cFile, "contentImage",x1,x2,x3); | ||
// if (x1 != -1) data.x1= x1; | ||
// if (x2 != -1) data.x2= x2; | ||
// if (x3 != -1) data.x3= x3; | ||
var data = giaenc. | ||
encFileToJSONStringifyBase64Prop(cFile,"contentImage"); | ||
//console.log(data); | ||
@@ -284,4 +313,4 @@ //var unparsedData = JSON.parse(data); | ||
}, | ||
responseType: 'json', | ||
httpsAgent: new https.Agent({ rejectUnauthorized: false }) | ||
responseType: 'json', | ||
httpsAgent: new https.Agent({ rejectUnauthorized: false }) | ||
@@ -301,6 +330,6 @@ }; | ||
// decode_base64_to_file(stylizedImage, targetOutput); | ||
giaenc.dec64_StringToFile(stylizedImage,targetOutput); | ||
giaenc.dec64_StringToFile(stylizedImage, targetOutput); | ||
console.log("A stylizedImage should be available at that path :\n feh " + targetOutput); | ||
//console.log(stylizedImage); | ||
@@ -311,11 +340,15 @@ }) | ||
console.log(err.message); | ||
console.log("---------arrrr 2"); | ||
}); | ||
//----------------------- | ||
} catch (error) { | ||
console.log("something went wrong: "); | ||
console.log(error); | ||
}} | ||
//----------------------- | ||
} catch (error) { | ||
console.log("something went wrong: "); | ||
console.log(error); | ||
console.log(error.message); | ||
console.log("---------arrrr 1"); | ||
} | ||
} |
{ | ||
"name": "gia-ast", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "A CLI Wrapping AST Web API calls to servers", | ||
@@ -35,3 +35,3 @@ "main": "index.js", | ||
"dotenv": "^10.0.0", | ||
"gia-lib-encoding-base64": "^0.1.0", | ||
"gia-lib-encoding-base64": "^0.1.1", | ||
"http": "^0.0.1-security", | ||
@@ -38,0 +38,0 @@ "node-fetch": "^2.6.1", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
133148
2921
28