diff --git a/peertube-plugin-auto-mute/README.md b/peertube-plugin-auto-mute/README.md index aba8743..516732d 100644 --- a/peertube-plugin-auto-mute/README.md +++ b/peertube-plugin-auto-mute/README.md @@ -2,9 +2,18 @@ Auto mute accounts or instances based on public blocklists. +## Mute lists + +**Add your public list here** + ## Settings -![settings screen](https://lutim.cpy.re/qaFui9N1.png) +You can choose to expose your mute list that will be available on `https://example.com/plugins/plugins/auto-mute/router/api/v1/mute-list`. +Other instances can follow your mute list, but muting removal is not supported yet. For example, if you subscribe to the mute list of `example.com`: + * `example.com` mutes `account1` + * Your instance automatically mutes `account1` + * `example.com` unmutes `account1` + * You instance **will not** unmute `account1` ## Blocklist URL format diff --git a/peertube-plugin-auto-mute/main.js b/peertube-plugin-auto-mute/main.js index 1953dc2..bb1af58 100644 --- a/peertube-plugin-auto-mute/main.js +++ b/peertube-plugin-auto-mute/main.js @@ -13,9 +13,10 @@ async function register ({ settingsManager, storageManager, peertubeHelpers, - registerSetting + registerSetting, + getRouter }) { - const { logger } = peertubeHelpers + const { logger, database, server } = peertubeHelpers registerSetting({ name: 'blocklist-urls', @@ -32,6 +33,14 @@ async function register ({ default: 3600 // 1 Hour }) + registerSetting({ + name: 'expose-mute-list', + label: 'Publicly expose my mute list', + type: 'input-checkbox', + private: true, + default: false + }) + const serverActor = await peertubeHelpers.server.getServerActor() store.serverAccountId = serverActor.Account.id @@ -43,6 +52,44 @@ async function register ({ load(peertubeHelpers, storageManager, settings['blocklist-urls'], settings['check-seconds-interval']) .catch(err => logger.error('Cannot load auto mute plugin.', { err })) }) + + const router = getRouter() + router.get('/api/v1/mute-list', async (req, res) => { + try { + const setting = await settingsManager.getSetting('expose-mute-list') + if (setting !== true) return res.sendStatus(403) + + const serverActor = await server.getServerActor() + const serverAccountId = serverActor.Account.id + + const [ serverMutes, accountMutes ] = await Promise.all([ + database.query( + 'SELECT "server"."host", "serverBlocklist"."updatedAt" FROM "serverBlocklist" ' + + 'INNER JOIN server ON server.id = "serverBlocklist"."targetServerId" WHERE "serverBlocklist"."accountId" = ' + serverAccountId, + { type: 'SELECT' } + ), + + database.query( + 'SELECT "actor"."preferredUsername", "server"."host", "accountBlocklist"."updatedAt" FROM "accountBlocklist" ' + + 'INNER JOIN account ON account.id = "accountBlocklist"."targetAccountId" ' + + 'INNER JOIN actor ON actor.id = account."actorId" ' + + 'INNER JOIN server ON server.id = actor."serverId" WHERE "accountBlocklist"."accountId" = ' + serverAccountId, + { type: 'SELECT' } + ) + ]) + + let result = serverMutes.map(m => ({ value: m.host, updatedAt: m.updatedAt })) + + result = result.concat(accountMutes.map(m => ({ value: `${m.preferredUsername}@${m.host}`, updatedAt: m.updatedAt }))) + + return res.json({ + data: result + }) + } catch (err) { + logger.error('Error in mute list endpoint.', { err }) + res.sendStatus(500) + } + }) } async function unregister () { diff --git a/peertube-plugin-auto-mute/package.json b/peertube-plugin-auto-mute/package.json index 8de6d7b..7cea0ec 100644 --- a/peertube-plugin-auto-mute/package.json +++ b/peertube-plugin-auto-mute/package.json @@ -1,6 +1,6 @@ { "name": "peertube-plugin-auto-mute", - "version": "0.0.3", + "version": "0.0.4", "description": "Auto mute plugin for PeerTube", "engine": { "peertube": ">=2.2.0"