Comparing version 0.5.10 to 1.0.0
@@ -26,4 +26,4 @@ #!/usr/bin/env node | ||
if (args[0] == "--help" || args[0] == "-h" || args[0] == "-help" || args[0] == "--h" || !args[0] || !args[1]) { | ||
if (args[0] == "--help" || args[0] == "-h" || args[0] == "-help" || args[0] == "--h" || ((!args[0] && !process.env.AST_STYLIZE_FILENAME) || | ||
(!args[1] && !process.env.AST_STYLIZE_PORT ))) { | ||
console.log(` | ||
@@ -74,3 +74,3 @@ ------------------------------------- | ||
---- Run Meta server | ||
docker run -d --restart unless-stopped --name ast_meta_server -p 8999:8080 -v /a/src/rwml__adaptive_style_transfer:/work -v /www/astia/info:/wwwmeta docker.io/guillaumeai/server:http-server http-server -p 8080 /wwwmeta | ||
docker run -d --restart unless-stopped --name ast_meta_server -p 8999:8080 -v /a/src/rwml__adaptive_style_transfer:/work -v $HOME/.gia/ast/www/meta:/wwwmeta docker.io/guillaumeai/server:http-server http-server -p 8080 /wwwmeta | ||
## Works with : github.com:GuillaumeAI/rwml__adaptive_style_transfer.git | ||
@@ -95,3 +95,3 @@ | ||
const envListHelp = ` | ||
vi ~/.bash_env | ||
vi ~/.env | ||
#export asthostname="orko.guillaumeisabelle.com" | ||
@@ -238,3 +238,4 @@ asthostname=localhost | ||
var imgFile = args[0]; | ||
var x1, x2, x3 = -1; | ||
var x1, x2 = 0; | ||
var c1 = 0; | ||
var xname = ""; | ||
@@ -254,19 +255,31 @@ var autosuffix = false; | ||
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 | ||
if (args[2]) { x1 = Number(args[2]); } else x1 = 0 | ||
if (args[3]) { x2 = Number(args[3]); } else x2 = 0 | ||
if (args[4]) { c1 = Number(args[4]); } else c1 = 0 | ||
var autosuffixSuffix = "__"; | ||
if (args[5] && args[5] == "-a") { autosuffix = true; } else autosuffix = false; | ||
if (args[6]) { autosuffixSuffix = args[6]; } | ||
if (x2 < 99 && x2 > -99 && c1 == 0) c1 = x2; | ||
// console.log(` | ||
// x1:${x1} | ||
// x2:${x2} | ||
// x3:${x3} | ||
// `); | ||
//process.exit(1); | ||
var autosuffixSuffix = "__";//DEPRECATED | ||
if (args[5] && args[4] && args[3] && (args[5] == "-a" || args[4] == "-a" || args[3] == "-a")) { autosuffix = true; } else autosuffix = false; | ||
if (args[6]) { autosuffixSuffix = args[6]; } //DEPRECATED | ||
//ModelID is related to a port will use | ||
var modelid = args[1]; | ||
var modelid,portnum = 0; | ||
if (args[1]) { | ||
modelid = args[1]; | ||
} | ||
else { | ||
//read AST_MODEL_PORT | ||
if (process.env.AST_MODEL_PORT) | ||
modelid = process.env.AST_MODEL_PORT; | ||
} | ||
if (modelid.length > 2) | ||
portnum = modelid; //Enable full use of the Port on another range than the port base | ||
else if (modelid.length == 2) portnum = config.portbase + modelid; | ||
var targetOutput = imgFileNameOnly + config.outsuffix + modelid + ext; | ||
@@ -277,19 +290,18 @@ | ||
var x2str = x2 != -1 ? x2 + "x" : ""; | ||
var x3str = x3 != -1 ? x3 + "x" : ""; | ||
if (x3 == -1) x2str = x2; | ||
xname = x1str + x2str + x3str; | ||
xname = x1str + x2str; | ||
targetOutput = imgFileNameOnly + "__" + xname + autosuffixSuffix + modelid + ext; | ||
} | ||
//@STCGoal Stuff we do not really want be removed from filename | ||
if (config.astcleanname) { //astcleanname | ||
//@STCGoal Stuff we do not really want be removed from filename | ||
if (config.astcleanname) { //astcleanname | ||
targetOutput = make_astcleanname(targetOutput); | ||
} | ||
targetOutput = make_astcleanname(targetOutput); | ||
} | ||
//console.log("TargetOutput: " + targetOutput); | ||
var portnum = config.portbase + modelid; | ||
if (modelid.length > 2) portnum = modelid; //Enable full use of the Port on another range than the port base | ||
const callurl = `${config.callprotocol}://${config.hostname}:${portnum}/${config.callmethod.replace("/", "")}`; | ||
@@ -357,23 +369,23 @@ const callurlmeta = `${config.callprotocol}://${config.hostname}:${config.metaportnum}/${portnum}.json`; | ||
function make_astcleanname(_targetOutput) { | ||
var r = _targetOutput | ||
.replace("model_gia-ds-", "") | ||
.replace("_ast_", "") | ||
.replace("gia-ds-", "") | ||
.replace("model_gia-", "") | ||
.replace("model_", "") | ||
.replace("-1-1-", "_") | ||
.replace("-1-", "_") | ||
.replace("-1", "_") | ||
.replace("-x_", "_") | ||
.replace("___", "__") | ||
.replace("-864x_new", "") | ||
.replace("-864x_", ""); | ||
.replace("model_gia-ds-", "") | ||
.replace("_ast_", "") | ||
.replace("gia-ds-", "") | ||
.replace("model_gia-", "") | ||
.replace("model_", "") | ||
.replace("-1-1-", "_") | ||
.replace("-1-", "_") | ||
.replace("-1", "_") | ||
.replace("-x_", "_") | ||
.replace("___", "__") | ||
.replace("-864x_new", "") | ||
.replace("-864x_", ""); | ||
// console.log("Cleaning the name: " + _targetOutput); | ||
return r; | ||
return r; | ||
} | ||
var metaretry=3; | ||
var metaretry = 3; | ||
function doTheWork(cFile, config, portnum, callurl, callurlmeta, targetOutput, x1 = -1, x2 = -1, x3 = -1, autosuffix = false) { | ||
function doTheWork(cFile, config, portnum, callurl, callurlmeta, targetOutput, x1 = 0, x2 = 0, c1 = 0, use_meta_filename_v2 = true, autosuffix = false, suffix = "") { | ||
try { | ||
@@ -384,3 +396,3 @@ | ||
data = giaenc. | ||
encFileToJSONStringifyBase64PropWithOptionalResolutions(cFile, "contentImage", x1, x2, x3); | ||
encFileToJSONStringifyBase64PropWithX2Abc(cFile, "contentImage", x1, x2, c1, suffix); | ||
@@ -435,3 +447,5 @@ } catch (error) { | ||
if (!config.usemetasvr) { | ||
if (!config.usemetasvr || (use_meta_filename_v2 && data["filename"] != null)) { | ||
if (use_meta_filename_v2 && data["filename"] != null) | ||
targetOutput = data["filename"]; | ||
saveStylizedResult(stylizedImage, data, targetOutput, config); | ||
@@ -469,3 +483,3 @@ } | ||
} | ||
// console.log(targetOutput); | ||
// console.log(targetOutput); | ||
@@ -478,9 +492,8 @@ // targetOutput = imgFileNameOnly + "__" + mtag + autosuffixSuffix + modelid + ext; | ||
.catch(function (errMeta) { | ||
if (metaretry> 0) | ||
{ | ||
//Launch the docker container | ||
startmeta(); | ||
metaretry = metaretry -1; | ||
console.log("\t Retrying to launch this function to do the work with the Meta hopefully started"); | ||
doTheWork(cFile, config, portnum, callurl, callurlmeta, targetOutput, x1 , x2 , x3 , autosuffix ); | ||
if (metaretry > 0) { | ||
//Launch the docker container | ||
startmeta(); | ||
metaretry = metaretry - 1; | ||
console.log("\t Retrying to launch this function to do the work with the Meta hopefully started"); | ||
doTheWork(cFile, config, portnum, callurl, callurlmeta, targetOutput, x1, x2, x3, autosuffix); | ||
@@ -494,3 +507,3 @@ } | ||
console.log("---------------------------------------------------"); | ||
console.log("---------------------------------------------------"); | ||
@@ -503,9 +516,9 @@ console.log("---------TRYING TO SAVE WITHOUT META SERVER DATA----------"); | ||
console.log("---------------------------------------------------"); | ||
saveStylizedResult(stylizedImage, data, targetOutput, config); | ||
process.exit(3); | ||
} | ||
}); | ||
//@a then save result | ||
}); | ||
//@a then save result | ||
// saveStylizedResult(stylizedImage, targetOutput, config); | ||
@@ -571,17 +584,17 @@ } | ||
function startmeta(){ | ||
function startmeta() { | ||
const { exec } = require("child_process"); | ||
exec("docker start ast_meta_server", (error, stdout, stderr) => { | ||
exec("docker start ast_meta_server", (error, stdout, stderr) => { | ||
if (error) { | ||
console.log(`error: ${error.message}`); | ||
return; | ||
console.log(`error: ${error.message}`); | ||
return; | ||
} | ||
if (stderr) { | ||
console.log(`stderr: ${stderr}`); | ||
return; | ||
console.log(`stderr: ${stderr}`); | ||
return; | ||
} | ||
console.log(`stdout: ${stdout}`); | ||
}); | ||
}); | ||
} |
#!/usr/bin/env node | ||
var fs = require('fs'); | ||
//Run server hosted on HuggingFace | ||
@@ -11,3 +13,4 @@ | ||
//docker rm astpicasso --force | ||
var valid_choices_are = "picasso,van-gogh,roerich,pollock,peploe,munch,monet,kirchner,gauguin,el-greco,cezanne,morisot,pikawill02b"; | ||
var valid_choices_are = "picasso,van-gogh,roerich,pollock,peploe,munch,monet,kirchner,gauguin,el-greco,cezanne,morisot,pikawill02b,pikawill02b-285ik"; | ||
//if env var AST_SERVER_CHOICES is set, use that instead | ||
@@ -30,11 +33,55 @@ if (process.env.AST_SERVER_CHOICES) { | ||
//AST_META_SERVER_ROOT $HOME/.gia/ast/www/astia | ||
var ast_meta_server_root = process.env.HOME + "/.gia/ast/www/meta"; | ||
if (process.env.AST_META_SERVER_ROOT) { | ||
ast_meta_server_root = process.env.AST_META_SERVER_ROOT; | ||
} | ||
//mkdir | ||
if (!fs.existsSync(ast_meta_server_root)) { | ||
fs.mkdirSync(ast_meta_server_root, { recursive: true }); | ||
} | ||
//AST_NS guillaumeai | ||
var ast_ns = "guillaumeai"; | ||
if (process.env.AST_NS) { | ||
ast_ns = process.env.AST_NS; | ||
} | ||
//sregistry = "registry.hf.space" | ||
var sregistry = "registry.hf.space"; | ||
if (process.env.AST_SREGISTRY) { | ||
sregistry = process.env.AST_SREGISTRY; | ||
} | ||
const { exec } = require('child_process'); | ||
function main() { | ||
var keep_going = false; | ||
console.log(process.argv[2] ); | ||
if (process.argv[2] && (process.argv[2] == "--list" || process.argv[2] == "-l")){ | ||
exec("docker ps|grep ast-", (err, stdout, stderr) => { | ||
if (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
console.log(stdout); | ||
process.exit(1); | ||
}); | ||
} | ||
else { | ||
keep_going = true; | ||
} | ||
//if cli called with "--picasso", run command above | ||
if (process.argv[2]) { | ||
if (process.argv[2] && keep_going) { | ||
model_name = process.argv[2].replace("--", "").replace("ast-", "").replace("ast", ""); | ||
container_name = "ast-" + model_name; | ||
var container_name = "ast-" + model_name; | ||
@@ -49,3 +96,3 @@ //if the argument is not in the list of valid choices, exit | ||
//remove the container | ||
repo_tag = get_huggingface_repo_tag(model_name); | ||
var repo_tag = get_huggingface_repo_tag(model_name, ast_ns, sregistry); | ||
if (process.argv[3] == "--pull") { | ||
@@ -87,3 +134,3 @@ exec("docker pull " + repo_tag, (err, stdout, stderr) => { | ||
exit_if_is_container_running(container_name, local_port) | ||
run_container_exit_if_running(container_name, local_port) | ||
@@ -96,4 +143,5 @@ | ||
else { | ||
if (keep_going){ | ||
show_valid_choices(); | ||
process.exit(1); | ||
process.exit(1);} | ||
} | ||
@@ -124,3 +172,3 @@ } | ||
post_launch_output(stdout, local_port); | ||
post_launch_output(stdout, local_port,container_name,ns); | ||
}); | ||
@@ -134,7 +182,33 @@ } | ||
function post_launch_output(stdout, local_port) { | ||
function post_launch_output(stdout, local_port,container_name,ns="guillaumeai",sregistry="registry.hf.space") { | ||
console.log(stdout + "\n---------------\n>docker container named: " + container_name + " launched on port :" + local_port); | ||
const cname = container_name.replace("ast", ""); | ||
//console.log("docker stop " + container_name + " --force #to remove"); | ||
console.log("> to stop the container, run : gia-ast-server --" + container_name.replace("ast", "") + " --rm"); | ||
console.log("> to stop the container, run : gia-ast-server --" + cname + " --rm"); | ||
console.log("> the likely url for the API is http://localhost:" + local_port + "/stylize" + "\n> gia-ast my_image.jpg " + local_port); | ||
// //@STCGoal MetaData for the server | ||
// const checkpoint_no = get_ik_from_container_name(cname); | ||
// const cname_no_ik = cname.replace("-"+checkpoint_no+"ik", ""); | ||
// const repo_tag = get_huggingface_repo_tag(ast_model, ns, sregistry); | ||
// const metadata = createMetaData( | ||
// modelname= cname, | ||
// fname= cname_no_ik, | ||
// containername= cname, | ||
// containertag= repo_tag, | ||
// checkpointno= checkpoint_no, | ||
// svrtype= "s1", | ||
// mtype= "ast", | ||
// type= "singleone", | ||
// autoabc= "", | ||
// callurl= "http://localhost:"+local_port+"/stylize", | ||
// PASS1IMAGESIZE= "2048", | ||
// getmetaurl= "http://localhost/"+local_port+".json", | ||
// created= new Date().toUTCString() | ||
// ); | ||
// saveMetadata(local_port, metadata); | ||
// console.log("Metadata saved to " + ast_meta_server_root + "/" + local_port + ".json"); | ||
} | ||
@@ -153,6 +227,9 @@ | ||
AST_SERVER_STARTING_BASE_PORT=7860 | ||
#default is $HOME/.gia/ast/www/meta | ||
#AST_META_SERVER_ROOT=/www/astia/info | ||
`; | ||
} | ||
function create_docker_run(ast_model = "ast-picasso", local_port = 7860, ns = "jgwill") { | ||
function create_docker_run(ast_model = "ast-picasso", local_port = 7860, ns = "guillaumeai", sregistry = "registry.hf.space") { | ||
@@ -167,3 +244,3 @@ //check if local port is available, if not, increment by 1 until one is available | ||
repo_tag = get_huggingface_repo_tag(ast_model, ns); | ||
repo_tag = get_huggingface_repo_tag(ast_model, ns, sregistry); | ||
@@ -175,4 +252,5 @@ result = "docker run -d --rm --name " + ast_model + " -p " + t_port + ":7860 --platform=linux/amd64 " + repo_tag; | ||
function get_huggingface_repo_tag(ast_model, ns = "guillaumeai") { | ||
res = "registry.hf.space/" + ns + "-ast-" + ast_model + ":latest "; | ||
function get_huggingface_repo_tag(ast_model, ns = "guillaumeai",sregistry = "registry.hf.space") { | ||
res = sregistry + "/" + ns + "-ast-" + ast_model + ":latest "; | ||
@@ -182,3 +260,3 @@ return res.replace("ast-ast-", "ast-"); | ||
function exit_if_is_container_running(container_name, local_port, callback_not_running, verbose = true) { | ||
function run_container_exit_if_running(container_name, local_port, callback_not_running, verbose = true) { | ||
@@ -215,33 +293,75 @@ var cmd_launcher = "echo $(for i in $(docker ps|grep " + container_name + ");do echo $i|grep \"0.0.0.0:\";done)|tr \":\" \" \"|tr \"-\" \" \"|awk '{print $2}'" | ||
function get_available_port(local_port) { | ||
//check if local port is available, if not, increment by 1 until one is available | ||
//docker ps -f publish=$port|grep $port | ||
used = true; | ||
while (used) { | ||
//var cmd = "bash -c \"tst=$(docker ps -q -f publish=" + local_port + ");if [ ! -n \"$tst\" ];then echo not used;else echo used;fi\"";// + "|grep " + local_port; | ||
// var cmd = "docker ps -q -f publish=" + local_port;// + "|grep " + local_port; | ||
var cmd = "docker ps|grep \":" + local_port + "\"";// + "|grep " + local_port; | ||
//console.log(cmd); | ||
// function get_available_port(local_port) { | ||
// //check if local port is available, if not, increment by 1 until one is available | ||
// //docker ps -f publish=$port|grep $port | ||
// used = true; | ||
// while (used) { | ||
// //var cmd = "bash -c \"tst=$(docker ps -q -f publish=" + local_port + ");if [ ! -n \"$tst\" ];then echo not used;else echo used;fi\"";// + "|grep " + local_port; | ||
// // var cmd = "docker ps -q -f publish=" + local_port;// + "|grep " + local_port; | ||
// var cmd = "docker ps|grep \":" + local_port + "\"";// + "|grep " + local_port; | ||
// //console.log(cmd); | ||
var stdout = exec(cmd, (err, stdout, stderr) => { | ||
if (err) { | ||
console.error(err); | ||
return; | ||
} | ||
console.log(stdout); | ||
return stdout; | ||
}); | ||
// var stdout = exec(cmd, (err, stdout, stderr) => { | ||
// if (err) { | ||
// console.error(err); | ||
// return; | ||
// } | ||
// console.log(stdout); | ||
// return stdout; | ||
// }); | ||
if (stdout == "") { | ||
used = false; | ||
} | ||
else { | ||
local_port++; | ||
} | ||
// if (stdout == "") { | ||
// used = false; | ||
// } | ||
// else { | ||
// local_port++; | ||
// } | ||
// } | ||
// } | ||
function get_ik_from_container_name(cname) { | ||
if (cname.includes( 'ik')) { | ||
console.log('contains ik'); | ||
var ik = cname.match(/-(\d+)ik/); | ||
if (ik[1]) { | ||
return ik[1]; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
return 0; | ||
} | ||
// function createMetaData(modelname, fname, containername, containertag, checkpointno, svrtype, mtype, type, autoabc, callurl, PASS1IMAGESIZE, getmetaurl, created) { | ||
// return { | ||
// modelname, | ||
// fname, | ||
// containername, | ||
// containertag, | ||
// checkpointno, | ||
// svrtype, | ||
// mtype, | ||
// type, | ||
// autoabc, | ||
// callurl, | ||
// PASS1IMAGESIZE, | ||
// getmetaurl, | ||
// created | ||
// }; | ||
// } | ||
// function saveMetadata(local_port, data) { | ||
// const { toASTMetaServer, aSTMetaServerToJson } = require('./AstMetaServer.js'); | ||
// var filename = local_port + ".json"; | ||
// const astMetaServerObject = toASTMetaServer(JSON.stringify(data)); | ||
// const json = aSTMetaServerToJson(astMetaServerObject); | ||
// var full_path = ast_meta_server_root + "/" + filename; | ||
// fs.writeFileSync(full_path, json); | ||
// } | ||
main(); |
{ | ||
"name": "gia-ast-util", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "CLI wrapper of utilities for AST Servers", | ||
@@ -35,2 +35,3 @@ "main": "ast", | ||
"dependencies": { | ||
"gia-lib-encoding-base64": "^0.1.4", | ||
"node-cmd": "^4.0.0", | ||
@@ -37,0 +38,0 @@ "node-powershell": "^4.0.0", |
@@ -124,2 +124,5 @@ // | ||
* @param {string} targetProp | ||
* @param {number} x1 | ||
* @param {number} x2 | ||
* @param {number} x3 | ||
*/ | ||
@@ -141,4 +144,32 @@ function (filename, targetProp, x1 = -1, x2 = -1, x3 = -1) { | ||
} | ||
}, | ||
encFileToJSONStringifyBase64PropWithX2Abc: | ||
/** | ||
* Encode an image file into base64 JSON file under a target property | ||
* @param {string} filename | ||
* @param {string} targetProp | ||
* @param {number} x1 Resolution 1 | ||
* @param {number} x2 Resolution 2 | ||
* @param {number} c1 ABC Correction | ||
*/ | ||
function (filename, targetProp, x1 = -1, x2 = -1, c1 = 0,suffix="none") { | ||
var base64 = this.encFileToBase64String(filename); | ||
//console.log(base64); | ||
var jsonRequest = new Object(); | ||
jsonRequest[targetProp] = base64; | ||
jsonRequest.x1 = x1; | ||
jsonRequest.x2 = x2; | ||
jsonRequest.c1 = c1; | ||
jsonRequest.fn=filename; | ||
jsonRequest.suffix=suffix; | ||
var jsonData = JSON.stringify(jsonRequest); | ||
return jsonData; | ||
} | ||
} |
{ | ||
"name": "gia-lib-encoding-base64", | ||
"version": "0.1.2", | ||
"version": "0.1.4", | ||
"description": "GIA Encoding-decoding base64 string utilities", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
138
gia-ast.js
@@ -8,4 +8,4 @@ #!/usr/bin/env node | ||
//console.log("gia-ast.js - 240329"); | ||
const http = require('http'); | ||
@@ -197,4 +197,5 @@ const https = require('https'); | ||
if (args[0] == "--help" || args[0] == "-h" || args[0] == "-help" || args[0] == "--h" || !args[0] || !args[1]) { | ||
//AST_STYLIZE_PORT | ||
if (args[0] == "--help" || args[0] == "-h" || args[0] == "-help" || args[0] == "--h" || ((!args[0] && !process.env.AST_STYLIZE_FILENAME) || | ||
(!args[1] && !process.env.AST_STYLIZE_PORT ))) { | ||
console.log(` | ||
@@ -223,2 +224,12 @@ ------------------------------------- | ||
export AST_STYLIZE_PORT=9860 | ||
export AST_STYLIZE_RES=1500 | ||
export AST_STYLIZE_ABC=34 | ||
gia-ast mycontent.jpg | ||
export AST_STYLIZE_FILENAME=image.png | ||
gia-ast | ||
# Open the image with feh | ||
FEH=1 gia-ast mycontent.jpg 9101 | ||
see also: | ||
@@ -236,4 +247,5 @@ gia-ast-server --help | ||
var stylizedImage; | ||
var imgFile = args[0]; | ||
var x1, x2, x3 = -1; | ||
var imgFile = args[0]|| process.env.AST_STYLIZE_FILENAME; | ||
var x1, x2 = 0; | ||
var c1 = 0; | ||
var autosuffix = false; | ||
@@ -251,38 +263,67 @@ var ext = path.extname(imgFile); | ||
// } | ||
if (args[2]) { x1 = Number(args[2]); } else x1 = 0 | ||
if (args[3]) { x2 = Number(args[3]); } else x2 = 0 | ||
if (args[4]) { c1 = Number(args[4]); } else c1 = 0 | ||
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 | ||
if (x1 == 0 && (process.env.AST_STYLIZE_RES1 || process.env.AST_STYLIZE_RES) ) x1= process.env.AST_STYLIZE_RES1 || process.env.AST_STYLIZE_RES; | ||
var autosuffixSuffix = "__"; | ||
if (args[5] && args[5] == "-a") { autosuffix = true; } else autosuffix = false; | ||
if (args[6]) { autosuffixSuffix = args[6] ; } | ||
if (x2 == 0 && process.env.AST_STYLIZE_RES2 ) x2= process.env.AST_STYLIZE_RES2 ; | ||
// console.log(` | ||
// x1:${x1} | ||
// x2:${x2} | ||
// x3:${x3} | ||
// `); | ||
//process.exit(1); | ||
if (c1 == 0 && process.env.AST_STYLIZE_ABC ) c1= process.env.AST_STYLIZE_ABC; | ||
if (x2 < 99 && x2 > -99 && c1 == 0) c1 = x2; | ||
var autosuffixSuffix = "__";//DEPRECATED | ||
if (args[5] && args[4] && args[3] && (args[5] == "-a" || args[4] == "-a"|| args[3] == "-a")) { autosuffix = true; } else autosuffix = false; | ||
if (args[6]) { autosuffixSuffix = args[6] ; } //DEPRECATED | ||
//ModelID is related to a port will use | ||
var modelid = args[1]; | ||
//ModelID is related to a port will use | ||
var modelid,portnum = 0; | ||
if (args[1]) { | ||
modelid = args[1]; | ||
} | ||
else { | ||
//read AST_STYLIZE_PORT | ||
if (process.env.AST_STYLIZE_PORT) | ||
modelid = process.env.AST_STYLIZE_PORT; | ||
} | ||
if (modelid.length > 2) | ||
portnum = modelid; //Enable full use of the Port on another range than the port base | ||
else if (modelid.length == 2) portnum = config.portbase + modelid; | ||
var targetOutput = imgFileNameOnly + config.outsuffix + modelid + ext; | ||
if (autosuffix) | ||
{ | ||
var x1str = x1 != -1 ? x1+"x":""; | ||
var x2str = x2 != -1 ? x2+"x":""; | ||
var x3str = x3 != -1 ? x3+"x":""; | ||
if (x3== -1) x2str = x2; | ||
targetOutput = imgFileNameOnly + "__" +x1str + x2str + x3str + autosuffixSuffix + modelid + ext; | ||
} | ||
if (autosuffix) //@STCIssue DEPRECATED | ||
{ | ||
var x1str = x1 != 0 ? x1+"x":""; | ||
var x2str = x2 != 0 ? x2+"x":""; | ||
if (c1 != 0) | ||
{ | ||
x1str = x1str + c1; | ||
} | ||
targetOutput = imgFileNameOnly + "__" +x1str + x2str + autosuffixSuffix + modelid + ext; | ||
} | ||
console.log("TargetOutput: " + targetOutput); | ||
var portnum = modelid; | ||
//if length is 2, we will use the full port number | ||
if (modelid.length == 2) | ||
portnum = config.portbase + modelid; | ||
//console.log(" TargetOutput: " + targetOutput); | ||
@@ -293,3 +334,3 @@ const callurl = config.callprotocol + "://" + config.hostname + ":" + portnum + "/" + config.callmethod.replace("/", ""); | ||
console.log("Processing: " + imgFile + " at port :" + portnum); | ||
//console.log(" : " + imgFile + " at port :" + portnum) +" with targetoutput:"+ targetOutput; | ||
@@ -307,3 +348,3 @@ /* | ||
// doWeResize(imgFile, config, portnum, callurl, targetOutput, resizeSwitch, targetResolutionX); | ||
doTheWork(imgFile, config, portnum, callurl, targetOutput, x1, x2, x3, autosuffix); | ||
doTheWork(imgFile, config, portnum, callurl, targetOutput, x1, x2, c1, autosuffix); | ||
@@ -350,7 +391,9 @@ | ||
function doTheWork(cFile, config, portnum, callurl, targetOutput, x1 = -1, x2 = -1, x3 = -1, autosuffix = false) { | ||
function doTheWork(cFile, config, portnum, callurl, targetOutput, x1 = 0, x2 = 0, c1 = 0, autosuffix = false,use_meta_filename_v2=true,suffix="none") { | ||
try { | ||
if (x2 == c1 ) x2 = 0; | ||
var data = giaenc. | ||
encFileToJSONStringifyBase64PropWithOptionalResolutions(cFile, "contentImage", x1, x2, x3); | ||
encFileToJSONStringifyBase64PropWithX2Abc(cFile, "contentImage", x1, x2, c1, suffix); | ||
// if (x1 != -1) data.x1= x1; | ||
@@ -379,3 +422,3 @@ // if (x2 != -1) data.x2= x2; | ||
console.log("Calling : " + config.hostname + ":" + portnum); | ||
//console.log("Calling : " + config.hostname + ":" + portnum); | ||
@@ -391,4 +434,9 @@ axios.post(callurl, data, options) | ||
// decode_base64_to_file(stylizedImage, targetOutput); | ||
if (config.debug == "true") fs.writeFileSync("__stylizedImage.json", JSON.stringify(data)); | ||
if (config.debug == "true") | ||
fs.writeFileSync("__stylizedImage.json", JSON.stringify(data)); | ||
//if use_meta_name, use the meta name included in the data response | ||
if (use_meta_filename_v2 && data["filename"] != null) | ||
targetOutput = data["filename"]; | ||
giaenc.dec64_StringToFile(stylizedImage, targetOutput); | ||
@@ -401,3 +449,15 @@ | ||
console.log("A stylizedImage should be available at that path :\n feh " + targetOutput); | ||
const feh_cmd = "A stylizedImage should be available at that path :\n feh " + targetOutput; | ||
//if env FEH=1, run feh | ||
if (process.env.FEH == 1) { | ||
const { exec } = require('child_process'); | ||
exec("feh " + targetOutput, (error, stdout, stderr) => { | ||
if (error) { | ||
console.error(`exec error: ${error}`); | ||
return; | ||
} | ||
}); | ||
} | ||
else console.log(feh_cmd); | ||
@@ -404,0 +464,0 @@ |
{ | ||
"name": "gia-ast", | ||
"version": "0.5.10", | ||
"version": "1.0.0", | ||
"description": "A CLI Wrapping AST Web API calls to servers", | ||
@@ -36,4 +36,7 @@ "main": "index.js", | ||
"axios": "^0.21.1", | ||
"cheerio": "^1.0.0-rc.12", | ||
"dockerode": "^4.0.2", | ||
"dotenv": "^10.0.0", | ||
"gia-lib-encoding-base64": "^0.1.2", | ||
"gia-ast-util": "^0.1.7", | ||
"gia-lib-encoding-base64": "^0.1.4", | ||
"http": "^0.0.1-security", | ||
@@ -40,0 +43,0 @@ "node-fetch": "^2.6.1", |
@@ -0,0 +0,0 @@ |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 11 instances 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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1941420
73
12679
0
15
150
21
+ Addedcheerio@^1.0.0-rc.12
+ Addeddockerode@^4.0.2
+ Addedgia-ast-util@^0.1.7
+ Added@balena/dockerignore@1.0.2(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedboolbase@1.0.0(transitive)
+ Addedbuildcheck@0.0.6(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcheerio@1.0.0(transitive)
+ Addedcheerio-select@2.1.0(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcpu-features@0.0.10(transitive)
+ Addedcss-select@5.1.0(transitive)
+ Addedcss-what@6.1.0(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addeddocker-modem@5.0.3(transitive)
+ Addeddockerode@4.0.2(transitive)
+ Addeddom-serializer@2.0.0(transitive)
+ Addeddomelementtype@2.3.0(transitive)
+ Addeddomhandler@5.0.3(transitive)
+ Addeddomutils@3.1.0(transitive)
+ Addedencoding-sniffer@0.2.0(transitive)
+ Addedentities@4.5.0(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedgia-ast-util@0.1.8(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedhtmlparser2@9.1.0(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedms@2.1.3(transitive)
+ Addednan@2.22.0(transitive)
+ Addednanoid@2.1.11(transitive)
+ Addednode-cmd@4.0.0(transitive)
+ Addednode-powershell@4.0.0(transitive)
+ Addednth-check@2.1.1(transitive)
+ Addedparse5@7.2.1(transitive)
+ Addedparse5-htmlparser2-tree-adapter@7.1.0(transitive)
+ Addedparse5-parser-stream@7.1.2(transitive)
+ Addedshortid@2.2.16(transitive)
+ Addedsplit-ca@1.0.1(transitive)
+ Addedssh2@1.16.0(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedtar-fs@2.0.1(transitive)
+ Addedundici@6.21.0(transitive)
+ Addedwhatwg-encoding@3.1.1(transitive)
+ Addedwhatwg-mimetype@4.0.0(transitive)