biz9-logic 4.8.297 → 4.8.298

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.
Files changed (3) hide show
  1. package/biz9_config +1 -1
  2. package/index.js +194 -0
  3. package/package.json +3 -2
package/biz9_config CHANGED
@@ -1,4 +1,4 @@
1
- VERSION='7.7.7'
1
+ VERSION='7.7.8'
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,9 @@ License GNU General Public License v3.0
5
5
  Description: BiZ9 Framework: Logic-JS
6
6
  */
7
7
  const moment = require('moment');
8
+ const path = require('path');
9
+ const { exec } = require('child_process');
10
+ const sharp = require('sharp');
8
11
  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
12
  const { Log,Str,DateTime,Num,Obj } = require('/home/think2/www/doqbox/biz9-framework/biz9-utility/code');
10
13
  class Message {
@@ -1896,6 +1899,196 @@ class App_Logic {
1896
1899
  return app;
1897
1900
  }
1898
1901
  }
1902
+
1903
+ class Image_Logic {
1904
+ static get_url = (host,image_filename,size) =>{
1905
+ return host+"/"+size + "_"+image_filename;
1906
+ }
1907
+ static get_new_by_base64 = (base64) =>{
1908
+ return DataItem.get_new(DataType.IMAGE,0,
1909
+ {
1910
+ mime_type:!Str.check_is_null(Str.get_file_type_from_base64(base64)) ? Str.get_file_type_from_base64(base64).mimeType : 'image/jpeg',
1911
+ extension:!Str.check_is_null(Str.get_file_type_from_base64(base64)) ? Str.get_file_type_from_base64(base64).extension : 'jpeg',
1912
+ 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',
1913
+ buffer:!Str.check_is_null(Str.get_file_type_from_base64(base64)) ? Buffer.from(base64.split(';base64,').pop(), 'base64') : null,
1914
+ });
1915
+ }
1916
+ static get_cloud_flare_batch_token = (cloud_flare_account_id,cloud_flare_api_token) => {
1917
+ return new Promise((callback) => {
1918
+ let data_batch,error=null;
1919
+ const url = "https://api.cloudflare.com/client/v4/accounts/"+cloud_flare_account_id+"/images/v1/batch_token";
1920
+ const headers = {
1921
+ "Accept": "application/json",
1922
+ "Authorization": "Bearer " +cloud_flare_api_token
1923
+ };
1924
+ let curlCommand = `curl -s -H "Accept: ${headers.Accept}"`;
1925
+ if (headers.Authorization) {
1926
+ curlCommand += ` -H "Authorization: ${headers.Authorization}"`;
1927
+ }
1928
+ curlCommand += ` "${url}"`;
1929
+ exec(curlCommand,async(err,stdout,stderr) => {
1930
+ if (err) {
1931
+ err = `1 Error executing curl command: ${error.message}`;
1932
+ console.error(err);
1933
+ error=Log.append(error,err);
1934
+ return;
1935
+ }
1936
+ if (stderr) {
1937
+ err = `2 Curl stderr: ${stderr}`;
1938
+ console.error(err);
1939
+ error=Log.append(error,err);
1940
+ return;
1941
+ }
1942
+ try {
1943
+ const jsonData =await JSON.parse(stdout);
1944
+ data_batch = jsonData.result.token;
1945
+ if(data_batch!== null){
1946
+ callback([error,data_batch]);
1947
+ }
1948
+ } catch (parseError) {
1949
+ console.error(`Error parsing JSON response: ${parseError.message}`);
1950
+ console.log('Raw Response:', stdout);
1951
+ callback([parseError,null]);
1952
+ }
1953
+ });
1954
+ });
1955
+ };
1956
+ static post_cloud_flare_batch_image = (cloud_flare_api_token,batch_token,image_filename,item_file_path) => {
1957
+ let error = null;
1958
+ return new Promise((callback) => {
1959
+ async.series([
1960
+ async function(call){
1961
+ const post_url = "https://batch.imagedelivery.net/images/v1";
1962
+ const headers = {
1963
+ "Accept": "application/json",
1964
+ "Authorization": "Bearer " +batch_token
1965
+ };
1966
+ let curlCommand = `curl -s -H "Accept: ${headers.Accept}"`;
1967
+ curlCommand += ` -H "Authorization: ${headers.Authorization}"`;
1968
+ curlCommand += " -H X-Auth-Key: "+ cloud_flare_api_token;
1969
+ curlCommand += " -F requireSignedURLs=false";
1970
+ curlCommand += " -F id="+image_filename;
1971
+ curlCommand += " -F file=@"+item_file_path;
1972
+ curlCommand += ` "${post_url}"`;
1973
+ exec(curlCommand, (err, stdout, stderr) => {
1974
+ if (err) {
1975
+ err = `Error executing curl command: ${err.message}`;
1976
+ console.error(err);
1977
+ error=Log.append(error,err);
1978
+ }
1979
+ if (stderr) {
1980
+ err = `Curl stderr: ${stderr}`;
1981
+ console.error(err);
1982
+ error=Log.append(error,err);
1983
+ }
1984
+ try {
1985
+ const jsonData = JSON.parse(stdout);
1986
+ console.log('cool');
1987
+ console.log(jsonData);
1988
+ console.log('bean');
1989
+ if(jsonData!== null){
1990
+ callback([error,jsonData]);
1991
+ }
1992
+ } catch (parseError) {
1993
+ console.error(`Error parsing JSON response: ${parseError.message}`);
1994
+ console.log('Raw Response:', stdout);
1995
+ error=Log.append(error,parseError);
1996
+ callback([error,null]);
1997
+ }
1998
+ });
1999
+ },
2000
+ ])
2001
+ });
2002
+ };
2003
+
2004
+ static post_write = (buffer,size,path_filename,is_square) => {
2005
+ return new Promise((callback) => {
2006
+ let data,error=null;
2007
+ if(is_square){
2008
+ sharp(buffer)
2009
+ .resize(size)
2010
+ .toFile(path_filename,(err, info) => {
2011
+ if(err){
2012
+ error=Log.append(error,'Error thumb saving file:');
2013
+ console.error('Error thumb saving file:', err);
2014
+ }
2015
+ if(info!==null){
2016
+ callback([error,true]);
2017
+ }
2018
+ });
2019
+ }else{
2020
+ sharp(buffer)
2021
+ .resize(size,size,{fit:sharp.fit.fill,quality:100})
2022
+ .toFile(path_filename,(err, info) => {
2023
+ if(err){
2024
+ error=Log.append(error,'Error thumb saving file:');
2025
+ console.error('Error thumb saving file:', err);
2026
+ }
2027
+ if(info!==null){
2028
+ callback([error,true]);
2029
+ }
2030
+ });
2031
+ }
2032
+ });
2033
+
2034
+ }
2035
+ static get_process_list = (upload_dir,image_filename) =>{
2036
+ return [
2037
+ {
2038
+ image_filename:FieldType.IMAGE_SIZE_THUMB+"_"+image_filename,
2039
+ path_filename:path.join(upload_dir,FieldType.IMAGE_SIZE_THUMB+"_"+image_filename),
2040
+ size:250,
2041
+ is_square:false,
2042
+ post_file:false,
2043
+ post_cdn:false
2044
+ },
2045
+ {
2046
+ image_filename:FieldType.IMAGE_SIZE_MID+"_"+image_filename,
2047
+ path_filename:path.join(upload_dir,FieldType.IMAGE_SIZE_MID+"_"+image_filename),
2048
+ size:720,
2049
+ is_square:false,
2050
+ post_file:false,
2051
+ post_cdn:false
2052
+ },
2053
+ {
2054
+ image_filename:FieldType.IMAGE_SIZE_LARGE+"_"+image_filename,
2055
+ path_filename:path.join(upload_dir,FieldType.IMAGE_SIZE_LARGE+"_"+image_filename),
2056
+ size:1000,
2057
+ is_square:false,
2058
+ post_file:false,
2059
+ post_cdn:false
2060
+ },
2061
+ {
2062
+ image_filename:FieldType.IMAGE_SIZE_SQUARE_THUMB+"_"+image_filename,
2063
+ path_filename:path.join(upload_dir,FieldType.IMAGE_SIZE_SQUARE_THUMB+"_"+image_filename),
2064
+ size:250,
2065
+ is_square:true,
2066
+ post_file:false,
2067
+ post_cdn:false
2068
+ },
2069
+ {
2070
+ image_filename:FieldType.IMAGE_SIZE_SQUARE_MID+"_"+image_filename,
2071
+ path_filename:path.join(upload_dir,FieldType.IMAGE_SIZE_SQUARE_MID+"_"+image_filename),
2072
+ size:720,
2073
+ is_square:true,
2074
+ post_file:false,
2075
+ post_cdn:false
2076
+ },
2077
+ {
2078
+ image_filename:FieldType.IMAGE_SIZE_SQUARE_LARGE+"_"+image_filename,
2079
+ path_filename:path.join(upload_dir,FieldType.IMAGE_SIZE_SQUARE_LARGE+"_"+image_filename),
2080
+ size:1000,
2081
+ is_square:true,
2082
+ post_file:false,
2083
+ post_cdn:false
2084
+ },
2085
+ ];
2086
+ }
2087
+ static get_process_square_list = (upload_dir,image_filename,path) =>{
2088
+ return [
2089
+ ];
2090
+ }
2091
+ }
1899
2092
  module.exports = {
1900
2093
  App_Logic,
1901
2094
  Admin_Logic,
@@ -1916,6 +2109,7 @@ module.exports = {
1916
2109
  Gallery_Logic,
1917
2110
  Gallery_Url,
1918
2111
  Item_Logic,
2112
+ Image_Logic,
1919
2113
  Image_Url,
1920
2114
  Item_Url,
1921
2115
  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.298",
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",