|
| 1 | +// drpy.js: 封装模块,包含处理逻辑 |
| 2 | + |
| 3 | +import * as utils from '../utils/utils.js'; // 使用 import 引入工具类 |
| 4 | +const { req } = await import('../utils/req.js'); |
| 5 | + |
| 6 | +export async function init(rule) { |
| 7 | + // 假设我们传入的 moduleObject 是 js/360.js 中的 rule 对象 |
| 8 | + const moduleObject = utils.deepCopy(rule) |
| 9 | + try { |
| 10 | + // 读取并修改传入的对象 |
| 11 | + if (moduleObject && moduleObject.title) { |
| 12 | + moduleObject.title += ' (drpy)'; // 修改 title 属性 |
| 13 | + } |
| 14 | + |
| 15 | + // 你可以根据需要修改其他属性 |
| 16 | + if (moduleObject && moduleObject.description) { |
| 17 | + moduleObject.description += ' [Modified]'; |
| 18 | + } |
| 19 | + const title = moduleObject.title |
| 20 | + console.log(moduleObject) |
| 21 | + const titleLength = utils.getTitleLength(title); // 使用 utils.js 中的方法 |
| 22 | + |
| 23 | + |
| 24 | + Object.assign(moduleObject, { |
| 25 | + message: `Module initialized with title: ${title}`, |
| 26 | + titleLength: titleLength |
| 27 | + }) |
| 28 | + |
| 29 | + console.log(typeof moduleObject.一级) |
| 30 | + if( typeof moduleObject.一级 === 'function'){ |
| 31 | + let html = await moduleObject.一级(req) |
| 32 | + console.log(html) |
| 33 | + moduleObject.html = html |
| 34 | + } |
| 35 | + |
| 36 | + // 返回修改后的对象 |
| 37 | + return moduleObject; |
| 38 | + } catch (error) { |
| 39 | + console.error('Error in drpy.init:', error); |
| 40 | + throw new Error('Failed to initialize module'); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +// 其他方法可以依照需求继续添加 |
| 45 | +export async function home() { |
| 46 | + return {message: 'Home method'}; |
| 47 | +} |
| 48 | + |
| 49 | +export async function cate() { |
| 50 | + return {message: 'Cate method'}; |
| 51 | +} |
| 52 | + |
| 53 | +export async function detail() { |
| 54 | + return {message: 'Detail method'}; |
| 55 | +} |
| 56 | + |
| 57 | +export async function play() { |
| 58 | + return {message: 'Play method'}; |
| 59 | +} |
| 60 | + |
| 61 | +export async function search() { |
| 62 | + return {message: 'Search method'}; |
| 63 | +} |
0 commit comments