web_jsx

2025-12-07 0 749

web_jsx

web_jsx *.wjsx, *.wjsxh(服务器端JavaScript)Web扩展名处理程序(使用IIS,Apache,nginx运行)

阅读帖子数据

 let payload = \"\" ;
context . request . read_payload ( ( buff , len ) => {
	payload += buff ;
} ) ;

或者

 let http_payload = context . request . read_posted_file ( context . request . content_length , context . request . content_type ) ;
if ( http_payload . is_multipart ( ) ) {
    let temp_dir = context . root_dir + \"/temp/\" ;
    sys . create_directory ( \"/temp/\" ) ;
    let rs = http_payload . read_all ( temp_dir ) ;
	let count = 1 ;
    context . response . write ( \"<ul>\" ) ;
	let upload_dir = context . root_dir + \"/upload/\" ;
    sys . create_directory ( \"/upload/\" ) ;
    try {
        http_payload . read_files ( ( file ) => {
            try {
                context . response . write ( `<li>SL: ${ count } </li>` ) ;
                context . response . write ( `<li>content_type: ${ file . get_content_type ( ) } </li>` ) ;
                context . response . write ( `<li>name: ${ file . get_name ( ) } </li>` ) ;
                context . response . write ( `<li>file_name: ${ file . get_file_name ( ) } </li>` ) ;
                context . response . write ( `<li>content_disposition: ${ file . get_content_disposition ( ) } </li>` ) ;
                context . response . write ( `<li>file Size: ${ parseFloat ( file . get_file_size ( ) / 1024 ) . toFixed ( 4 ) } Kb</li>` ) ;
                context . response . write ( `<li>Writing file ${ file . get_file_name ( ) } </li>` ) ;
                file . save_as ( ` ${ upload_dir } ${ file . get_file_name ( ) } ` ) ;
            } catch ( e ) {
                context . response . write ( `<li style=\"color:red;\">Error: ${ e . message } </li>` ) ;
            }
            count ++ ;
        } ) ;
    } catch ( e ) {
        context . response . write ( `<li style=\"color:red;\">Error: ${ e . message } </li>` ) ;
    }
    context . response . write ( \"</ul>\" ) ;
    context . response . write ( `Total ${ rs } file(s) saved...` ) ;
    //Or Save all file to $upload_dir
    http_payload . save_to_file ( upload_dir ) ;
	
} else {
	http_payload . read_line ( ( buff , len ) => {
		context . response . write ( buff ) ;
	} ) ;
}
http_payload . release ( ) ;

将有效载荷写入文件

 let temp_dir = context . root_dir + \"/temp/\" ;
sys . create_directory ( \"/temp/\" ) ;
let c = context . request . write_file_from_payload ( temp_dir ) ;

#内容编码GZIP(ZLIB)响应

 context . response . as_gzip ( )

这个Zlib压缩直接在上游写

web_jsx.jpg\”, zlib.Z_FINISH );
compress.flush();
//Or If you like to response compressed string
let compress = new zlib.compress();
context.response.header( \”Content-Type\”, \”text/plain\” );
compress.flush_header();
compress.write( `Welcome to`, zlib.Z_NO_FLUSH );
compress.write( `WebJsx`, zlib.Z_NO_FLUSH );
compress.write_from_file( \”context.json\”, zlib.Z_NO_FLUSH );
compress.write( `You should write finsh stream`, zlib.Z_FINISH );
compress.flush();\”>

 //If you like to response compressed file
let compress = new zlib . compress ( ) ;
context . response . header ( \"Content-Type\" , \"image/jpeg\" ) ;
compress . flush_header ( ) ;
compress . write_from_file ( \"/images/ web_jsx .jpg\" , zlib . Z_FINISH ) ;
compress . flush ( ) ;
//Or If you like to response compressed string
let compress = new zlib . compress ( ) ;
context . response . header ( \"Content-Type\" , \"text/plain\" ) ;
compress . flush_header ( ) ;
compress . write ( `Welcome to` , zlib . Z_NO_FLUSH ) ;
compress . write ( `WebJsx` , zlib . Z_NO_FLUSH ) ;
compress . write_from_file ( \"context.json\" , zlib . Z_NO_FLUSH ) ;
compress . write ( `You should write finsh stream` , zlib . Z_FINISH ) ;
compress . flush ( ) ;

用zlib充气/放气文件

 //Compress file with zlib
let ret = zlib . deflate ( \"/input.file\" , \"/output.gzip\" , zlib . Z_BEST_SPEED ) ;
//Decompress file with zlib
let ret = zlib . inflate ( \"/input.gzip\" , \"/output_unzip.file\" ) ;

直接写入向上

 let cout = new stdout ( ) ;
context . response . header ( \"Content-Type\" , \"text/plain\" ) ;
cout . flush_header ( ) ;
cout . write ( \"Hello world...\\r\\n\" ) ;
//Or you may write file directly outstream
cout . write_from_file ( \"context.json\" ) ;
cout . flush ( ) ;

将WebJSX与PostgreSQL连接

 //Read data from Postgres SQL
let resp = npgsql . execute_io ( \"Server=localhost; Port=5432; UserId=postgres;Password=1##$1@6Z;Database=sow; keepalive=10; CommandTimeout=100000;\" , 
	\"__sql_execute\" , JSON . stringify ( { } ) , JSON . stringify ( {
		\"sql\" : \"select * from jsx.community\"
	} )
) ;
__print ( JSON . stringify ( resp ) ) ;
/** read web config module **/
let cfg = require ( \"/addon/web.conf.js\" ) ;
/** get pgsql addon **/
const { pgSql , npgsql_db_type , npgsql_parameter_direction , npgsql_createParam } = require ( \"/addon/pgsql.js\" ) ;
/** initialize pgSql instance **/
let _pgsql = new pgSql ( cfg . database . db_conn , JSON . stringify ( { login_id : \"system\" } ) ) ;

context . response . write ( \'<table><tbody>\' ) ;
/** Read row(s) from PostgreSQL with plain text quary **/
let res = _pgsql . data_reader ( \"select * from auth.login where login_id ={0}\" , [ \"rajibs\" ] , ( i , row ) => {
    let _row = JSON . parse ( row ) ;
    context . response . write ( \"<tr>\" ) ;
    _row . forEach ( ( val ) => {
        context . response . write ( `<td> ${ val } </td>` ) ;
    } ) ;
    context . response . write ( \"</tr>\" ) ;
} ) ;
context . response . write ( \'</tbody></table>\' ) ;

/** Execute INSERT statement and get last sequence number**/
let designation_sid = _pgsql . execute_query ( \"INSERT INTO c_type.designation(designation_id, title)VALUES ({0},{1}) returning designation_sid\" , [ \"NO_ADMIN\" , \"NO_DSG\" ] ) ;

/** Execute DELETE statement**/
_pgsql . execute_query ( \"delete from c_type.designation where designation_sid > {0}  and designation_sid not in({1})\" , [ 2 , designation_sid ] ) ;

/** Execute SCALAR statement**/
let params = [ ] ;
params . push ( npgsql_createParam ( \"ct\" , npgsql_db_type . Jsonb , npgsql_parameter_direction . Input , { login_id : \"system\" } ) ) ;
params . push ( npgsql_createParam ( \"obj\" , npgsql_db_type . Jsonb , npgsql_parameter_direction . Input , { } ) ) ;
params . push ( npgsql_createParam ( \"ret_data_table\" , npgsql_db_type . Jsonb , npgsql_parameter_direction . Output ) ) ;
params . push ( npgsql_createParam ( \"ret_val\" , npgsql_db_type . Bigint , npgsql_parameter_direction . Output ) ) ;
params . push ( npgsql_createParam ( \"ret_msg\" , npgsql_db_type . Varchar , npgsql_parameter_direction . Output ) ) ;
let res = _pgsql . execute_scalar ( \"data_storage.__get__historical_data\" , params ) ;
context . response . write ( res . ret_val ) ;
context . response . write ( res . ret_msg ) ;
context . response . write ( JSON . stringify ( res . ret_data_table ) ) ;
//Or Create new Instance and execute multiple quary
let pgsql = new PgSql ( ) ;
//Connect database once and execute multiple quary
pgsql . connect ( cfg . database . db_conn ) ;
//Execute stored procedure
let resp = pgsql . execute_io (
	\"aut.user_info\" ,
	JSON . stringify ( { } ) ,
	JSON . stringify ( { } )
) ;
//Release all Active Connection and release all resource
pgsql . exit_nicely ( ) ;

将WebJSX与MySQL连接

web_jsx_db\”,
user: \”root\”,
password: \”mysql123\”,
port: 0
} );
//Drop Database
mysql.exec( \’DROP DATABASE IF EXISTS web_jsx _db_2\’ );
//Create Database
mysql.exec( \’CREATE DATABASE IF NOT EXISTS web_jsx _db_2\’ );
//Switch Database
mysql.switch_database(\” web_jsx _db_2\”);
//Create TABLE
mysql.exec(\’CREATE TABLE IF NOT EXISTS Persons ( PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255), City varchar(255))\’);
//Truncate TABLE
mysql.exec( \”truncate table Persons\” );
//Execute Insert statement
mysql.exec( \”INSERT INTO Persons (`PersonID`, `LastName`, `FirstName`, `Address`, `City`)VALUES (11, \’Rajib\’, \’Chy\’, \’Panchlaish, katalgong\’, \’Chittagong\’);\” );
//Execute multiple row select statement
mysql.execute_query( \”select * from Persons\”, ( i, row ) => {
print( row );
} );
//Execute 1 cell select statement
let address = mysql.exec(\’select Address from Persons limit 1\’);
//Release all Active Connection and release all resource
mysql.clear();\”>

 let mysql = new MySql ( ) ;
mysql . connect ( {
	host : \"localhost\" ,
	database : \" web_jsx _db\" ,
	user : \"root\" ,
	password : \"mysql123\" ,
	port : 0
} ) ;
//Drop Database
mysql . exec ( \'DROP DATABASE IF EXISTS web_jsx _db_2\' ) ;
//Create Database
mysql . exec ( \'CREATE DATABASE IF NOT EXISTS web_jsx _db_2\' ) ;
//Switch Database
mysql . switch_database ( \" web_jsx _db_2\" ) ;
//Create TABLE
mysql . exec ( \'CREATE TABLE IF NOT EXISTS Persons ( PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255), City varchar(255))\' ) ;
//Truncate TABLE
mysql . exec ( \"truncate table Persons\" ) ;
//Execute Insert statement
mysql . exec ( \"INSERT INTO Persons (`PersonID`, `LastName`, `FirstName`, `Address`, `City`)VALUES (11, \'Rajib\', \'Chy\', \'Panchlaish, katalgong\', \'Chittagong\');\" ) ;
//Execute multiple row select statement
mysql . execute_query ( \"select * from Persons\" , ( i , row ) => {
	print ( row ) ;
} ) ;
//Execute 1 cell select statement
let address = mysql . exec ( \'select Address from Persons limit 1\' ) ;
//Release all Active Connection and release all resource
mysql . clear ( ) ;

发送@email和web_jsx

web_jsx\” );
/* Add your CC, BCC @address. You can add multiple address*/
msg.cc( \”cc@address\” ).bcc( \”bcc@address\” );
/* Add your mail body here and can set it body is html */
msg.body( `@body`,/*is html body*/ false );
/* Add your attachment. you can add multiple attachment here*/
msg.attachment( {
name: \”test\”,
path: context.server_map_path( \”test.zip\” ),
mime_type: mime_type.application.zip,
encoder: mime_encoder.base64
} );
/* Send email here with MailMessage instance */
let rs = smtp.sendMail( msg );
/* Read your response, whether it was sent or failed..*/
/*{success:true|false, msg: reason}*/
context.response.write( JSON.stringify( rs ) );\”>

 /* Import SMTP Addon*/
const { Smtp , MailMessage , mime_type , mime_encoder } = require ( \"/addon/smtp.js\" ) ;
/* Create SMTP instance*/
let smtp = new Smtp ( \"smtp://my_smtp.com\" , \"smtp_user\" , \"smtp_password\" ) ;
/* If you use CLI, you can enable debug mood*/
smtp . debug ( ) ;
/* You may enable TLS mood */
smtp . enableTls ( ) ;
/* If you enable TLS you need to add CERT */
smtp . cert ( context . server_map_path ( \"/mycert.pem\" ) ) ;
/* Create MailMessage Instance */
let msg = new MailMessage ( \"from@address\" , \"to@address\" ) ;
/* Add your mail subject */
msg . subject ( \"Your subject Test mail from web_jsx \" ) ;
/* Add your CC, BCC @address. You can add multiple address*/
msg . cc ( \"cc@address\" ) . bcc ( \"bcc@address\" ) ;
/* Add your mail body here and can set it body is html */
msg . body ( `@body` , /*is html body*/ false ) ;
/* Add your attachment. you can add multiple attachment here*/
msg . attachment ( {
    name : \"test\" ,
    path : context . server_map_path ( \"test.zip\" ) ,
    mime_type : mime_type . application . zip ,
    encoder : mime_encoder . base64
} ) ;
/* Send email here with MailMessage instance */
let rs = smtp . sendMail ( msg ) ;
/* Read your response, whether it was sent or failed..*/
/*{success:true|false, msg: reason}*/
context . response . write ( JSON . stringify ( rs ) ) ;

使用web_jsx中的图像(支持:.bmp,.png,.jpeg,.jpg,.gif,.gif,.tiff,.tif)

 function resize_to ( source , dest ) {
    source . lock_bits ( image_mood . READ ) ; dest . lock_bits ( image_mood . WRITE ) ;
    let swidth = source . get_width ( ) ;
    let sheight = source . get_height ( ) ;
    let width = dest . get_width ( ) ;
    let height = dest . get_height ( ) ;
    let scale_width = width / swidth , scale_height = height / sheight ;
    for ( let y = 0 ; y < height ; y ++ ) {
        for ( let x = 0 ; x < width ; x ++ ) {
            let pixel_color = source . get_pixel ( parseInt ( x / scale_width ) , parseInt ( y / scale_height ) ) ;
            dest . set_pixel ( pixel_color , x , y ) ;
        }
    }
    source . unlock_bits ( ) ; dest . unlock_bits ( ) ;
    return ;
}
let full_img = new Image ( ) ;
full_img . load ( ` ${ env . root_dir } test.bmp` ) ;
let width = full_img . get_width ( ) ;
let height = full_img . get_height ( ) ;
let thumb_img = new Image ( ) ;
thumb_img . create_canvas ( width / 2 , height / 2 ) ;
//resize to another Image object
resize_to ( full_img , thumb_img ) ;
//read base64 image data
let base64_data = thumb_img . to_base64 ( image_format 

下载源码

通过命令行克隆项目:

git clone https://github.com/rktuxyn/web_jsx.git

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

申明:本文由第三方发布,内容仅代表作者观点,与本网站无关。对本文以及其中全部或者部分内容的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。本网发布或转载文章出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,也不代表本网对其真实性负责。

左子网 开发教程 web_jsx https://www.zuozi.net/31592.html

md color picker
上一篇: md color picker
analyze github.org
下一篇: analyze github.org
常见问题
  • 1、自动:拍下后,点击(下载)链接即可下载;2、手动:拍下后,联系卖家发放即可或者联系官方找开发者发货。
查看详情
  • 1、源码默认交易周期:手动发货商品为1-3天,并且用户付款金额将会进入平台担保直到交易完成或者3-7天即可发放,如遇纠纷无限期延长收款金额直至纠纷解决或者退款!;
查看详情
  • 1、描述:源码描述(含标题)与实际源码不一致的(例:货不对板); 2、演示:有演示站时,与实际源码小于95%一致的(但描述中有”不保证完全一样、有变化的可能性”类似显著声明的除外); 3、发货:不发货可无理由退款; 4、安装:免费提供安装服务的源码但卖家不履行的; 5、收费:价格虚标,额外收取其他费用的(但描述中有显著声明或双方交易前有商定的除外); 6、其他:如质量方面的硬性常规问题BUG等。 注:经核实符合上述任一,均支持退款,但卖家予以积极解决问题则除外。
查看详情
  • 1、左子会对双方交易的过程及交易商品的快照进行永久存档,以确保交易的真实、有效、安全! 2、左子无法对如“永久包更新”、“永久技术支持”等类似交易之后的商家承诺做担保,请买家自行鉴别; 3、在源码同时有网站演示与图片演示,且站演与图演不一致时,默认按图演作为纠纷评判依据(特别声明或有商定除外); 4、在没有”无任何正当退款依据”的前提下,商品写有”一旦售出,概不支持退款”等类似的声明,视为无效声明; 5、在未拍下前,双方在QQ上所商定的交易内容,亦可成为纠纷评判依据(商定与描述冲突时,商定为准); 6、因聊天记录可作为纠纷评判依据,故双方联系时,只与对方在左子上所留的QQ、手机号沟通,以防对方不承认自我承诺。 7、虽然交易产生纠纷的几率很小,但一定要保留如聊天记录、手机短信等这样的重要信息,以防产生纠纷时便于左子介入快速处理。
查看详情

相关文章

猜你喜欢
发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务