@@ -17,6 +17,10 @@ const _config_path = path.join(__dirname, '../config');
1717const _lib_path = path . join ( __dirname , '../spider/py' ) ;
1818const timeout = 30000 ; // 30秒超时
1919
20+ function stringify ( arg ) {
21+ return Array . isArray ( arg ) || typeof arg == "object" ? JSON . stringify ( arg ) : arg
22+ }
23+
2024const json2Object = function ( json ) {
2125 // console.log('json2Object:', json);
2226 if ( ! json ) {
@@ -107,13 +111,13 @@ const loadEsmWithHash = async function (filePath, fileHash, env) {
107111 `--script-path "${ filePath } "` ,
108112 `--method-name "${ methodName } "` ,
109113 `--env '${ JSON . stringify ( env ) } '` ,
110- ...args . map ( arg => `--arg '${ JSON . stringify ( arg ) } '` )
114+ ...args . map ( arg => `--arg '${ stringify ( arg ) } '` )
111115 ] . join ( ' ' ) ;
112116 // console.log(command);
113117 const cmd_args = [ ] ;
114118 args . forEach ( arg => {
115119 cmd_args . push ( `--arg` ) ;
116- cmd_args . push ( `${ JSON . stringify ( arg ) } ` ) ;
120+ cmd_args . push ( `${ stringify ( arg ) } ` ) ;
117121 } ) ;
118122 const options = {
119123 mode : 'text' ,
@@ -165,7 +169,7 @@ const loadEsmWithHash = async function (filePath, fileHash, env) {
165169 // 定义Spider类的方法
166170 const spiderMethods = [
167171 'init' , 'home' , 'homeVod' , 'homeContent' , 'category' ,
168- 'detail' , 'search' , 'play' , 'proxy' , 'action' , 'initEnv'
172+ 'detail' , 'search' , 'play' , 'proxy' , 'action'
169173 ] ;
170174
171175 // 为代理对象添加方法
@@ -175,11 +179,6 @@ const loadEsmWithHash = async function (filePath, fileHash, env) {
175179 } ;
176180 } ) ;
177181
178- // 处理initEnv调用
179- if ( typeof spiderProxy . initEnv === 'function' && env ) {
180- await spiderProxy . initEnv ( env ) ;
181- }
182-
183182 return spiderProxy ;
184183}
185184
@@ -194,12 +193,12 @@ const init = async function (filePath, env = {}, refresh) {
194193 const fileHash = computeHash ( fileContent ) ;
195194 const moduleName = path . basename ( filePath , '.js' ) ;
196195 let moduleExt = env . ext || '' ;
197- const default_init_cfg = {
198- stype : 4 , //T3/T4 源类型
199- skey : `hipy_${ moduleName } ` ,
200- sourceKey : `hipy_${ moduleName } ` ,
201- ext : moduleExt ,
202- } ;
196+ // const default_init_cfg = { // T3才需要这种结构
197+ // stype: 4, //T3/T4 源类型
198+ // skey: `hipy_${moduleName}`,
199+ // sourceKey: `hipy_${moduleName}`,
200+ // ext: moduleExt,
201+ // };
203202 let SitesMap = getSitesMap ( _config_path ) ;
204203 if ( moduleExt && SitesMap [ moduleName ] ) {
205204 try {
@@ -226,7 +225,8 @@ const init = async function (filePath, env = {}, refresh) {
226225 module = await loadEsmWithHash ( filePath , fileHash , env ) ;
227226 // console.log('module:', module);
228227 const rule = module ;
229- const initValue = await rule . init ( default_init_cfg ) || { } ;
228+ // const initValue = await rule.init(default_init_cfg) || {};
229+ const initValue = await rule . init ( moduleExt ) || { } ;
230230 let t2 = getNowTime ( ) ;
231231 const moduleObject = deepCopy ( rule ) ;
232232 moduleObject . cost = t2 - t1 ;
0 commit comments