Plugin ProvidersCreating a plugin provider using the sdk

Using createPlugin

Overview

The createPlugin function is the core component of the Falkor Plugin SDK that helps you create and configure plugins. This guide will walk you through how to use it effectively.

Basic Usage

Here’s a basic example of how to create a plugin:

import { createPlugin } from '@team-falkor/plugin-sdk';
 
const plugin = createPlugin({
  setup: {
    id: "my.plugin.id",      // Must follow format: name.plugin.id
    version: "1.0.0",
    multiple_choice: false,  // Set to true if your plugin needs multiple steps
    name: 'My Plugin',
    description: 'A description of what your plugin does',
    logo: "https://example.com/logo.png",
    banner: "https://example.com/banner.png" // Optional
  },
  port: 3000,  // The port your plugin will run on
  handleSearch: async (query) => {
    // Implement your search logic here
    return [];
  },
  handleReturn: async (data) => {
    // Optional: Handle return data for multiple choice plugins
    return [];
  },
  options: {
    debug: true  // Optional: Enable debug mode
  }
});

Configuration Options

Required Fields

  • setup: The basic configuration for your plugin

    • id: A unique identifier following the format name.plugin.id
    • version: Your plugin’s version number
    • multiple_choice: Set to true if your plugin needs multiple steps
    • name: The display name of your plugin
    • description: A brief description of what your plugin does
    • logo: URL to your plugin’s logo
    • banner: (Optional) URL to your plugin’s banner image
  • port: The port number your plugin will run on

  • handleSearch: The main search function that processes queries

    handleSearch: async (query: string) => {
      // Your search logic here
      return [
        {
          type: "ddl", // or "torrent", "magnet"
          name: "Example Result",
          return: "https://example.com/download",
          size: 1024,
          multiple_choice: false // Override setup.multiple_choice if needed
        }
      ];
    }

Optional Fields

  • handleReturn: Required only if multiple_choice is true

    handleReturn: async (data: string) => {
      // Process the return data
      return ["final-download-link"];
    }
  • options: Additional configuration options

    options: {
      debug: true  // Enable debug logging
    }

Response Formats

Search Response

Your handleSearch function should return an array of objects following these formats:

For Direct Downloads (DDL)

{
  type: "ddl",
  name: "Example Game",
  return: "https://example.com/download",
  size: 1024,
  multiple_choice: false
}

For Torrents or Magnets

{
  type: "torrent", // or "magnet"
  seeds: 100,
  name: "Example Game",
  uploader: "example",
  return: "base64-string",
  size: 1024,
  multiple_choice: false
}

Return Response

If your plugin uses multiple_choice, your handleReturn function should return:

["final-download-link"]

Best Practices

  1. Error Handling: Always implement proper error handling in your search and return functions.

  2. Debug Mode: Use the debug option during development to get detailed logs:

    options: { debug: true }
  3. Multiple Choice: Only enable multiple_choice if your plugin genuinely needs a two-step process.

  4. Port Selection: Choose a port number that’s unlikely to conflict with other services.