biz9-logic 4.8.297 → 4.8.299

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/biz9_config CHANGED
@@ -1,4 +1,4 @@
1
- VERSION='7.7.7'
1
+ VERSION='7.7.9'
2
2
  TITLE='BiZ9-Logic';
3
3
  REPO='git@github.com:biz9framework/biz9-logic.git';
4
4
  BRANCH='main';
package/index.js CHANGED
@@ -5,6 +5,8 @@ License GNU General Public License v3.0
5
5
  Description: BiZ9 Framework: Logic-JS
6
6
  */
7
7
  const moment = require('moment');
8
+ const { exec } = require('child_process');
9
+ const sharp = require('sharp');
8
10
  const { get_new_item_main,get_data_config_main,get_cloud_url_main,get_biz_item_main,get_cloud_filter_obj_main,get_new_full_item_main } = require('./main');
9
11
  const { Log,Str,DateTime,Num,Obj } = require('/home/think2/www/doqbox/biz9-framework/biz9-utility/code');
10
12
  class Message {
@@ -1896,6 +1898,191 @@ class App_Logic {
1896
1898
  return app;
1897
1899
  }
1898
1900
  }
1901
+
1902
+ class Image_Logic {
1903
+ static get_url = (host,image_filename,size) =>{
1904
+ return host+"/"+size + "_"+image_filename;
1905
+ }
1906
+ static get_new_by_base64 = (base64) =>{
1907
+ return DataItem.get_new(DataType.IMAGE,0,
1908
+ {
1909
+ mime_type:!Str.check_is_null(Str.get_file_type_from_base64(base64)) ? Str.get_file_type_from_base64(base64).mimeType : 'image/jpeg',
1910
+ extension:!Str.check_is_null(Str.get_file_type_from_base64(base64)) ? Str.get_file_type_from_base64(base64).extension : 'jpeg',
1911
+ image_filename:!Str.check_is_null(Str.get_file_type_from_base64(base64)) ? Str.get_guid()+"."+Str.get_file_type_from_base64(base64).extension : 'not_found.jpeg',
1912
+ buffer:!Str.check_is_null(Str.get_file_type_from_base64(base64)) ? Buffer.from(base64.split(';base64,').pop(), 'base64') : null,
1913
+ });
1914
+ }
1915
+ static get_cloud_flare_batch_token = (cloud_flare_account_id,cloud_flare_api_token) => {
1916
+ return new Promise((callback) => {
1917
+ let data_batch,error=null;
1918
+ const url = "https://api.cloudflare.com/client/v4/accounts/"+cloud_flare_account_id+"/images/v1/batch_token";
1919
+ const headers = {
1920
+ "Accept": "application/json",
1921
+ "Authorization": "Bearer " +cloud_flare_api_token
1922
+ };
1923
+ let curlCommand = `curl -s -H "Accept: ${headers.Accept}"`;
1924
+ if (headers.Authorization) {
1925
+ curlCommand += ` -H "Authorization: ${headers.Authorization}"`;
1926
+ }
1927
+ curlCommand += ` "${url}"`;
1928
+ exec(curlCommand,async(err,stdout,stderr) => {
1929
+ if (err) {
1930
+ err = `1 Error executing curl command: ${error.message}`;
1931
+ console.error(err);
1932
+ error=Log.append(error,err);
1933
+ return;
1934
+ }
1935
+ if (stderr) {
1936
+ err = `2 Curl stderr: ${stderr}`;
1937
+ console.error(err);
1938
+ error=Log.append(error,err);
1939
+ return;
1940
+ }
1941
+ try {
1942
+ const jsonData =await JSON.parse(stdout);
1943
+ data_batch = jsonData.result.token;
1944
+ if(data_batch!== null){
1945
+ callback([error,data_batch]);
1946
+ }
1947
+ } catch (parseError) {
1948
+ console.error(`Error parsing JSON response: ${parseError.message}`);
1949
+ console.log('Raw Response:', stdout);
1950
+ callback([parseError,null]);
1951
+ }
1952
+ });
1953
+ });
1954
+ };
1955
+ static post_cloud_flare_batch_image = (cloud_flare_api_token,batch_token,image_filename,item_file_path) => {
1956
+ let error = null;
1957
+ return new Promise((callback) => {
1958
+ async.series([
1959
+ async function(call){
1960
+ const post_url = "https://batch.imagedelivery.net/images/v1";
1961
+ const headers = {
1962
+ "Accept": "application/json",
1963
+ "Authorization": "Bearer " +batch_token
1964
+ };
1965
+ let curlCommand = `curl -s -H "Accept: ${headers.Accept}"`;
1966
+ curlCommand += ` -H "Authorization: ${headers.Authorization}"`;
1967
+ curlCommand += " -H X-Auth-Key: "+ cloud_flare_api_token;
1968
+ curlCommand += " -F requireSignedURLs=false";
1969
+ curlCommand += " -F id="+image_filename;
1970
+ curlCommand += " -F file=@"+item_file_path;
1971
+ curlCommand += ` "${post_url}"`;
1972
+ exec(curlCommand, (err, stdout, stderr) => {
1973
+ if (err) {
1974
+ err = `Error executing curl command: ${err.message}`;
1975
+ console.error(err);
1976
+ error=Log.append(error,err);
1977
+ }
1978
+ if (stderr) {
1979
+ err = `Curl stderr: ${stderr}`;
1980
+ console.error(err);
1981
+ error=Log.append(error,err);
1982
+ }
1983
+ try {
1984
+ const jsonData = JSON.parse(stdout);
1985
+ console.log('cool');
1986
+ console.log(jsonData);
1987
+ console.log('bean');
1988
+ if(jsonData!== null){
1989
+ callback([error,jsonData]);
1990
+ }
1991
+ } catch (parseError) {
1992
+ console.error(`Error parsing JSON response: ${parseError.message}`);
1993
+ console.log('Raw Response:', stdout);
1994
+ error=Log.append(error,parseError);
1995
+ callback([error,null]);
1996
+ }
1997
+ });
1998
+ },
1999
+ ])
2000
+ });
2001
+ };
2002
+
2003
+ static post_write = (buffer,size,path_filename,is_square) => {
2004
+ return new Promise((callback) => {
2005
+ let data,error=null;
2006
+ if(is_square){
2007
+ sharp(buffer)
2008
+ .resize(size)
2009
+ .toFile(path_filename,(err, info) => {
2010
+ if(err){
2011
+ error=Log.append(error,'Error thumb saving file:');
2012
+ console.error('Error thumb saving file:', err);
2013
+ }
2014
+ if(info!==null){
2015
+ callback([error,true]);
2016
+ }
2017
+ });
2018
+ }else{
2019
+ sharp(buffer)
2020
+ .resize(size,size,{fit:sharp.fit.fill,quality:100})
2021
+ .toFile(path_filename,(err, info) => {
2022
+ if(err){
2023
+ error=Log.append(error,'Error thumb saving file:');
2024
+ console.error('Error thumb saving file:', err);
2025
+ }
2026
+ if(info!==null){
2027
+ callback([error,true]);
2028
+ }
2029
+ });
2030
+ }
2031
+ });
2032
+ }
2033
+ static get_process_list = (upload_dir,image_filename) =>{
2034
+ return [
2035
+ {
2036
+ image_filename:FieldType.IMAGE_SIZE_THUMB+"_"+image_filename,
2037
+ path_filename:upload_dir+"/"+FieldType.IMAGE_SIZE_THUMB+"_"+image_filename,
2038
+ size:250,
2039
+ is_square:false,
2040
+ post_file:false,
2041
+ post_cdn:false
2042
+ },
2043
+ {
2044
+ image_filename:FieldType.IMAGE_SIZE_MID+"_"+image_filename,
2045
+ path_filename:upload_dir+"/"+FieldType.IMAGE_SIZE_MID+"_"+image_filename,
2046
+ size:720,
2047
+ is_square:false,
2048
+ post_file:false,
2049
+ post_cdn:false
2050
+ },
2051
+ {
2052
+ image_filename:FieldType.IMAGE_SIZE_LARGE+"_"+image_filename,
2053
+ path_filename:upload_dir+"/"+FieldType.IMAGE_SIZE_LARGE+"_"+image_filename,
2054
+ size:1000,
2055
+ is_square:false,
2056
+ post_file:false,
2057
+ post_cdn:false
2058
+ },
2059
+ {
2060
+ image_filename:FieldType.IMAGE_SIZE_SQUARE_THUMB+"_"+image_filename,
2061
+ path_filename:upload_dir+"/"+FieldType.IMAGE_SIZE_SQUARE_THUMB+"_"+image_filename,
2062
+ size:250,
2063
+ is_square:true,
2064
+ post_file:false,
2065
+ post_cdn:false
2066
+ },
2067
+ {
2068
+ image_filename:FieldType.IMAGE_SIZE_SQUARE_MID+"_"+image_filename,
2069
+ path_filename:upload_dir+"/"+FieldType.IMAGE_SIZE_SQUARE_MID+"_"+image_filename,
2070
+ size:720,
2071
+ is_square:true,
2072
+ post_file:false,
2073
+ post_cdn:false
2074
+ },
2075
+ {
2076
+ image_filename:FieldType.IMAGE_SIZE_SQUARE_LARGE+"_"+image_filename,
2077
+ path_filename:upload_dir+"/"+FieldType.IMAGE_SIZE_SQUARE_LARGE+"_"+image_filename,
2078
+ size:1000,
2079
+ is_square:true,
2080
+ post_file:false,
2081
+ post_cdn:false
2082
+ },
2083
+ ];
2084
+ }
2085
+ }
1899
2086
  module.exports = {
1900
2087
  App_Logic,
1901
2088
  Admin_Logic,
@@ -1916,6 +2103,7 @@ module.exports = {
1916
2103
  Gallery_Logic,
1917
2104
  Gallery_Url,
1918
2105
  Item_Logic,
2106
+ Image_Logic,
1919
2107
  Image_Url,
1920
2108
  Item_Url,
1921
2109
  Event_Logic,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "biz9-logic",
3
- "version": "4.8.297",
3
+ "version": "4.8.299",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -12,7 +12,8 @@
12
12
  "biz9-scriptz": "^5.8.1",
13
13
  "biz9-utility": "^3.8.36",
14
14
  "jest": "^29.7.0",
15
- "moment": "^2.30.1"
15
+ "moment": "^2.30.1",
16
+ "sharp": "^0.34.4"
16
17
  },
17
18
  "repository": {
18
19
  "type": "git",
package/test.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const path = require('path');
2
2
  const series = require('async-series');
3
- const {DataItem,DataType,Url,Obj,BiZ_Url,Cat,Stock,Schedule,Storage,Business,Product,Service,Event,Template,Page,Category,Review,Blog_Post,Faq_Logic,Category_Url,Blank_Url,Blank_Logic,Item_Logic,Service_Logic,Template_Logic,Page_Logic,Product_Logic,Event_Logic,Blog_Post_Logic,Content_Logic,Category_Logic,Team_Logic,Business_Logic,PageType,Sub_Item_Logic,Page_Url,Review_Logic,User_Logic,Field_Logic,Order_Logic,Cart_Logic,Faq_Url,App_Logic,FieldType,Product_Url,Gallery_Logic} = require('./index');
3
+ const {DataItem,DataType,Url,Obj,BiZ_Url,Cat,Stock,Schedule,Storage,Business,Product,Service,Event,Template,Page,Category,Review,Blog_Post,Faq_Logic,Category_Url,Blank_Url,Blank_Logic,Item_Logic,Service_Logic,Template_Logic,Page_Logic,Product_Logic,Event_Logic,Blog_Post_Logic,Content_Logic,Category_Logic,Team_Logic,Business_Logic,PageType,Sub_Item_Logic,Page_Url,Review_Logic,User_Logic,Field_Logic,Order_Logic,Cart_Logic,Faq_Url,App_Logic,FieldType,Product_Url,Gallery_Logic,Image_Logic} = require('./index');
4
4
  const {Log,Num} = require('biz9-utility');
5
5
  const {Scriptz}= require('biz9-scriptz');
6
6
 
@@ -36,17 +36,18 @@ describe("connect", () => {
36
36
  //console.log(gallery);
37
37
  //console.log('ITEM-END');
38
38
  console.log('cool');
39
- console.log(DataType.get_title(DataType.TEMPLATE,true));
39
+ console.log(Image_Logic.get_process_list('upload/photos','apple'));
40
+ //console.log(DataType.get_title(DataType.TEMPLATE,true));
40
41
  //console.log(FieldType.get_title(FieldType.USER_ROLE_ADMIN));
41
- console.log('bbbbbb');
42
- let page = Page_Logic.get_test();
42
+ //console.log('bbbbbb');
43
+ //let page = Page_Logic.get_test();
43
44
  //page[Item_Logic.get_field_value_title(FieldType.ITEM_FIELD_VALUE_TYPE_TEXT,1)] = 'apple';
44
45
  //page[Item_Logic.get_field_value_title(FieldType.ITEM_FIELD_VALUE_TYPE_LIST,1,1)] = 'cool';
45
46
  //page[Item_Logic.get_field_value_title('list',1,2)] = 'apple';
46
47
  //page[Item_Logic.get_field_value_title('list',1,3)] = 'sauce';
47
48
  //Log.w('page',page);
48
49
  //Log.w('text_1_value',Item_Logic.get_field_value_value(FieldType.ITEM_FIELD_VALUE_TYPE_TEXT,page,1));
49
- Log.w('list_1_value',Item_Logic.get_field_value_value(FieldType.ITEM_FIELD_VALUE_TYPE_LIST,page,1));
50
+ //Log.w('list_1_value',Item_Logic.get_field_value_value(FieldType.ITEM_FIELD_VALUE_TYPE_LIST,page,1));
50
51
 
51
52
 
52
53
  //console.log(Page_Logic.get_page_value_field_title('text',1));