Categories management plugin

Hi there,

I’m starting the development of a « categories management plugin ». This is my first Peertube plugin and since this is a contract, I’m planning to start with a naïve implementation to get something up and running quickly.

Naïve implementation

UI will only consists in an upload button. The uploaded file will be a json file with the following format :

{
  added: [
    { key: 42, label: "Truth" }
  ],
  deleted: [
    1, // Music
  ]
}

The idea is to be as close as possible to the video constants customization API :
PeerTube/register-helpers.ts at v3.2.1 · Chocobozzz/PeerTube · GitHub

Better implementation

For the next implementation I’m planning to have a better UI with a table representation of the categories and their customization, something which would abstract the implementation details of the video constants customization system.

A PeerTube plugin exposing the whole video constants customization system with a nice UI would probably be useful. But this is out of my current scope.

From what I gathered the plugin system doesn’t allow to --strictly speaking – delete existing constants but rather hide them.

One issue I saw with the current system is, it doesn’t allow to delete an added constant (I’m not sure if it’s the expected behavior or not).

If we call deleteConstant it won’t look for (and delete) a constant which was previouslyadded with addConstant.

See PeerTube/register-helpers.ts at v3.2.1 · Chocobozzz/PeerTube · GitHub
If it’s not intentional let me know and I might post an issue about this and submit a PR.

Otherwise I’ll probably store the added and deleted categories in the plugin settings and reset the video constants customization via reinitVideoConstants each time the settings are changing.

What do you think would be the best course of action @Chocobozzz ?

One last question… which Controller/Page/UI should I pick as a reference implementation for this category management page?

Hello,

It’s not really convenient to not be able to delete a constant we added, so I changed this beheviour in Add ability to delete previously added constants · Chocobozzz/PeerTube@799ece6 · GitHub

You should be able in peertube 3.3 to remove categories you added previously.

The plugin system is not designed (yet?) to handle custom pages. But I think you can create dedicated SPA/HTML pages using the router provided by peertube.

From what I gathered the plugin system doesn’t allow to --strictly speaking – delete existing constants but rather hide them.

I figured out I was wrong. AlterableVideoConstant are actually updated in memory… this bring even more questions :thinking:
The good news is, I’ll actually be able to delete a previously added constant with deleteConstant.

The reset part is trickier tho. I noticed when the server instance restart, every modifications done on the constants are wiped out. But didn’t figure a way to trigger it with code yet.

But I think you can create dedicated SPA/HTML pages using the router provided by peertube.

Thanks! I’ll dig down this if I need more complex stuff…

It’s not really convenient to not be able to delete a constant we added, so I changed this beheviour in Add ability to delete previously added constants · Chocobozzz/PeerTube@799ece6 · GitHub

You should be able in peertube 3.3 to remove categories you added previously.

Nice! Thanks!

I previously raised this issue while reading the code, but now that I did experiment with it and noticed the changes are done in memory… I’m not so sure this was an issue :thinking:
I’ll play with the new version and see where it goes :wink:

A first version of the plugin is out:

This is quite basic and not very handy but it suits our basic needs for now :

Next version will probably get rid of the Json textarea and add more behavior to the « data-grid » - table - below.

I encountered a few issues on the way tho… I’m creating a dedicated topic about the plugin system and I’ll ping you there.

2 Likes

thanks my issue has been fixed.

thanks for the awesome information.