expanse icon indicating copy to clipboard operation
expanse copied to clipboard

Plugins!

Open QtFuta opened this issue 2 years ago • 1 comments

Work for #5 and (possible duplicate) #29

Created a base system to have plugins :D

Plugins will be located in backend/plugins, they need to be added to the index.mjs file so expanse can read them.
Comments with an example were included :P

I required the plugins to have some functions that expanse will call at some point.
The current ones are:

  • getId() to identify the plugin (ideally would be unique for future usages)
  • receiveItem(item) for the plugin to process items that are saved in the DB, regardless of from which user it came from
  • receiveUserItem(user, category, item, config) for the plugin to process items of a user.
  • getAvailableConfig() for future usage to be able to template a config screen for the user.

An example of how it works can be found in my fork for ImgBB :3

So, this is a base implementation, there is some stuff that I want to improve/implement:

  • Currently plugins will be called for all new items and for all users, there needs to be a way to let the user decide which items they want to let the plugin process. This is where the uniqueness of getId() will be in play.
  • Allow users to configure the plugin, since in the example in my fork I'm only processing items that have been saved, but user might want to dynamically update this and would be different for each user.
    This is where getAvailableConfig() to get an object with the possible properties to configure plus possible values and more stuff to create a dynamic form for the user.
    Also in here the DB will need to be updated with a new table to store the plugin configuration for each user, then it'll be sent as the last parameter of receiveUserItem

I need help with something! 😓
In my fork I'm using SQLite, so can someone please test that the function get_items(ids) works well with postgres?

QtFuta avatar Jan 17 '23 03:01 QtFuta

Improved it a bit 😅

Now the item it's a custom own for expanse, and the item from reddit (snoowrap) is a property of it.
This will allow us add more functionality that plugins might have in common.
For example, I added a way to know if a post is text, image, gif, video or a link 😃

Also included a way to defer plugin initialization in case is needed for expanse to initialize something first.
This way we can ensure that expanse is ready before the plugins start (for example in my fork I need to wait for dotenv to load the variables)

My fork has been updated with the example usage of this 😄

QtFuta avatar Jan 18 '23 22:01 QtFuta