Skip to content

如何编写插件

1. 如何编写插件

1.1 基本结构

每个插件应当是一个符合 IPluginDefine 规范的对象,导出后可被 App 识别和加载。

示例插件结构:

ts
module.exports = {
    name: "示例插件",
    from: "https://example.com",
    version: "1.0.0",
    srcUrl: "https://example.com/plugin-update.json",
    author: "开发者",
    async initRotationData() {
        return []; // 返回轮播数据
    },
    async initWeekData() {
        return [[]]; // 返回每周数据
    },
    async getDetailData(movieItem) {
        return { ...movieItem, description: "影片详情" }; // 返回影片详细信息
    },
    async search(query, page = 1) {
        return { results: [], total: 0 }; // 返回搜索结果
    },
    async play(url, movieItem) {
        return { source: url, type: "mp4" }; // 返回播放源信息
    }
};