diff options
Diffstat (limited to 'server')
50 files changed, 879 insertions, 195 deletions
diff --git a/server/controllers/api/abuse.ts b/server/controllers/api/abuse.ts index 72c418e74..a6d0b0512 100644 --- a/server/controllers/api/abuse.ts +++ b/server/controllers/api/abuse.ts | |||
@@ -167,7 +167,11 @@ async function reportAbuse (req: express.Request, res: express.Response) { | |||
167 | const body: AbuseCreate = req.body | 167 | const body: AbuseCreate = req.body |
168 | 168 | ||
169 | const { id } = await sequelizeTypescript.transaction(async t => { | 169 | const { id } = await sequelizeTypescript.transaction(async t => { |
170 | const reporterAccount = await AccountModel.load(res.locals.oauth.token.User.Account.id, t) | 170 | const user = res.locals.oauth.token.User |
171 | // Don't send abuse notification if reporter is an admin/moderator | ||
172 | const skipNotification = user.hasRight(UserRight.MANAGE_ABUSES) | ||
173 | |||
174 | const reporterAccount = await AccountModel.load(user.Account.id, t) | ||
171 | const predefinedReasons = body.predefinedReasons?.map(r => abusePredefinedReasonsMap[r]) | 175 | const predefinedReasons = body.predefinedReasons?.map(r => abusePredefinedReasonsMap[r]) |
172 | 176 | ||
173 | const baseAbuse = { | 177 | const baseAbuse = { |
@@ -184,7 +188,8 @@ async function reportAbuse (req: express.Request, res: express.Response) { | |||
184 | reporterAccount, | 188 | reporterAccount, |
185 | transaction: t, | 189 | transaction: t, |
186 | startAt: body.video.startAt, | 190 | startAt: body.video.startAt, |
187 | endAt: body.video.endAt | 191 | endAt: body.video.endAt, |
192 | skipNotification | ||
188 | }) | 193 | }) |
189 | } | 194 | } |
190 | 195 | ||
@@ -193,7 +198,8 @@ async function reportAbuse (req: express.Request, res: express.Response) { | |||
193 | baseAbuse, | 198 | baseAbuse, |
194 | commentInstance, | 199 | commentInstance, |
195 | reporterAccount, | 200 | reporterAccount, |
196 | transaction: t | 201 | transaction: t, |
202 | skipNotification | ||
197 | }) | 203 | }) |
198 | } | 204 | } |
199 | 205 | ||
@@ -202,7 +208,8 @@ async function reportAbuse (req: express.Request, res: express.Response) { | |||
202 | baseAbuse, | 208 | baseAbuse, |
203 | accountInstance, | 209 | accountInstance, |
204 | reporterAccount, | 210 | reporterAccount, |
205 | transaction: t | 211 | transaction: t, |
212 | skipNotification | ||
206 | }) | 213 | }) |
207 | }) | 214 | }) |
208 | 215 | ||
diff --git a/server/controllers/api/blocklist.ts b/server/controllers/api/blocklist.ts new file mode 100644 index 000000000..1e936ad10 --- /dev/null +++ b/server/controllers/api/blocklist.ts | |||
@@ -0,0 +1,108 @@ | |||
1 | import express from 'express' | ||
2 | import { handleToNameAndHost } from '@server/helpers/actors' | ||
3 | import { AccountBlocklistModel } from '@server/models/account/account-blocklist' | ||
4 | import { getServerActor } from '@server/models/application/application' | ||
5 | import { ServerBlocklistModel } from '@server/models/server/server-blocklist' | ||
6 | import { MActorAccountId, MUserAccountId } from '@server/types/models' | ||
7 | import { BlockStatus } from '@shared/models' | ||
8 | import { asyncMiddleware, blocklistStatusValidator, optionalAuthenticate } from '../../middlewares' | ||
9 | import { logger } from '@server/helpers/logger' | ||
10 | |||
11 | const blocklistRouter = express.Router() | ||
12 | |||
13 | blocklistRouter.get('/status', | ||
14 | optionalAuthenticate, | ||
15 | blocklistStatusValidator, | ||
16 | asyncMiddleware(getBlocklistStatus) | ||
17 | ) | ||
18 | |||
19 | // --------------------------------------------------------------------------- | ||
20 | |||
21 | export { | ||
22 | blocklistRouter | ||
23 | } | ||
24 | |||
25 | // --------------------------------------------------------------------------- | ||
26 | |||
27 | async function getBlocklistStatus (req: express.Request, res: express.Response) { | ||
28 | const hosts = req.query.hosts as string[] | ||
29 | const accounts = req.query.accounts as string[] | ||
30 | const user = res.locals.oauth?.token.User | ||
31 | |||
32 | const serverActor = await getServerActor() | ||
33 | |||
34 | const byAccountIds = [ serverActor.Account.id ] | ||
35 | if (user) byAccountIds.push(user.Account.id) | ||
36 | |||
37 | const status: BlockStatus = { | ||
38 | accounts: {}, | ||
39 | hosts: {} | ||
40 | } | ||
41 | |||
42 | const baseOptions = { | ||
43 | byAccountIds, | ||
44 | user, | ||
45 | serverActor, | ||
46 | status | ||
47 | } | ||
48 | |||
49 | await Promise.all([ | ||
50 | populateServerBlocklistStatus({ ...baseOptions, hosts }), | ||
51 | populateAccountBlocklistStatus({ ...baseOptions, accounts }) | ||
52 | ]) | ||
53 | |||
54 | return res.json(status) | ||
55 | } | ||
56 | |||
57 | async function populateServerBlocklistStatus (options: { | ||
58 | byAccountIds: number[] | ||
59 | user?: MUserAccountId | ||
60 | serverActor: MActorAccountId | ||
61 | hosts: string[] | ||
62 | status: BlockStatus | ||
63 | }) { | ||
64 | const { byAccountIds, user, serverActor, hosts, status } = options | ||
65 | |||
66 | if (!hosts || hosts.length === 0) return | ||
67 | |||
68 | const serverBlocklistStatus = await ServerBlocklistModel.getBlockStatus(byAccountIds, hosts) | ||
69 | |||
70 | logger.debug('Got server blocklist status.', { serverBlocklistStatus, byAccountIds, hosts }) | ||
71 | |||
72 | for (const host of hosts) { | ||
73 | const block = serverBlocklistStatus.find(b => b.host === host) | ||
74 | |||
75 | status.hosts[host] = getStatus(block, serverActor, user) | ||
76 | } | ||
77 | } | ||
78 | |||
79 | async function populateAccountBlocklistStatus (options: { | ||
80 | byAccountIds: number[] | ||
81 | user?: MUserAccountId | ||
82 | serverActor: MActorAccountId | ||
83 | accounts: string[] | ||
84 | status: BlockStatus | ||
85 | }) { | ||
86 | const { byAccountIds, user, serverActor, accounts, status } = options | ||
87 | |||
88 | if (!accounts || accounts.length === 0) return | ||
89 | |||
90 | const accountBlocklistStatus = await AccountBlocklistModel.getBlockStatus(byAccountIds, accounts) | ||
91 | |||
92 | logger.debug('Got account blocklist status.', { accountBlocklistStatus, byAccountIds, accounts }) | ||
93 | |||
94 | for (const account of accounts) { | ||
95 | const sanitizedHandle = handleToNameAndHost(account) | ||
96 | |||
97 | const block = accountBlocklistStatus.find(b => b.name === sanitizedHandle.name && b.host === sanitizedHandle.host) | ||
98 | |||
99 | status.accounts[sanitizedHandle.handle] = getStatus(block, serverActor, user) | ||
100 | } | ||
101 | } | ||
102 | |||
103 | function getStatus (block: { accountId: number }, serverActor: MActorAccountId, user?: MUserAccountId) { | ||
104 | return { | ||
105 | blockedByServer: !!(block && block.accountId === serverActor.Account.id), | ||
106 | blockedByUser: !!(block && user && block.accountId === user.Account.id) | ||
107 | } | ||
108 | } | ||
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts index 805ad99c7..b253db397 100644 --- a/server/controllers/api/config.ts +++ b/server/controllers/api/config.ts | |||
@@ -169,6 +169,18 @@ function customConfig (): CustomConfig { | |||
169 | whitelisted: CONFIG.SERVICES.TWITTER.WHITELISTED | 169 | whitelisted: CONFIG.SERVICES.TWITTER.WHITELISTED |
170 | } | 170 | } |
171 | }, | 171 | }, |
172 | client: { | ||
173 | videos: { | ||
174 | miniature: { | ||
175 | preferAuthorDisplayName: CONFIG.CLIENT.VIDEOS.MINIATURE.PREFER_AUTHOR_DISPLAY_NAME | ||
176 | } | ||
177 | }, | ||
178 | menu: { | ||
179 | login: { | ||
180 | redirectOnSingleExternalAuth: CONFIG.CLIENT.MENU.LOGIN.REDIRECT_ON_SINGLE_EXTERNAL_AUTH | ||
181 | } | ||
182 | } | ||
183 | }, | ||
172 | cache: { | 184 | cache: { |
173 | previews: { | 185 | previews: { |
174 | size: CONFIG.CACHE.PREVIEWS.SIZE | 186 | size: CONFIG.CACHE.PREVIEWS.SIZE |
diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts index 9949b378a..5f49336b1 100644 --- a/server/controllers/api/index.ts +++ b/server/controllers/api/index.ts | |||
@@ -6,6 +6,7 @@ import { badRequest } from '../../helpers/express-utils' | |||
6 | import { CONFIG } from '../../initializers/config' | 6 | import { CONFIG } from '../../initializers/config' |
7 | import { abuseRouter } from './abuse' | 7 | import { abuseRouter } from './abuse' |
8 | import { accountsRouter } from './accounts' | 8 | import { accountsRouter } from './accounts' |
9 | import { blocklistRouter } from './blocklist' | ||
9 | import { bulkRouter } from './bulk' | 10 | import { bulkRouter } from './bulk' |
10 | import { configRouter } from './config' | 11 | import { configRouter } from './config' |
11 | import { customPageRouter } from './custom-page' | 12 | import { customPageRouter } from './custom-page' |
@@ -49,6 +50,7 @@ apiRouter.use('/search', searchRouter) | |||
49 | apiRouter.use('/overviews', overviewsRouter) | 50 | apiRouter.use('/overviews', overviewsRouter) |
50 | apiRouter.use('/plugins', pluginRouter) | 51 | apiRouter.use('/plugins', pluginRouter) |
51 | apiRouter.use('/custom-pages', customPageRouter) | 52 | apiRouter.use('/custom-pages', customPageRouter) |
53 | apiRouter.use('/blocklist', blocklistRouter) | ||
52 | apiRouter.use('/ping', pong) | 54 | apiRouter.use('/ping', pong) |
53 | apiRouter.use('/*', badRequest) | 55 | apiRouter.use('/*', badRequest) |
54 | 56 | ||
diff --git a/server/controllers/api/plugins.ts b/server/controllers/api/plugins.ts index 2de7fe41f..de9e055dc 100644 --- a/server/controllers/api/plugins.ts +++ b/server/controllers/api/plugins.ts | |||
@@ -144,8 +144,13 @@ async function installPlugin (req: express.Request, res: express.Response) { | |||
144 | 144 | ||
145 | const fromDisk = !!body.path | 145 | const fromDisk = !!body.path |
146 | const toInstall = body.npmName || body.path | 146 | const toInstall = body.npmName || body.path |
147 | |||
148 | const pluginVersion = body.pluginVersion && body.npmName | ||
149 | ? body.pluginVersion | ||
150 | : undefined | ||
151 | |||
147 | try { | 152 | try { |
148 | const plugin = await PluginManager.Instance.install(toInstall, undefined, fromDisk) | 153 | const plugin = await PluginManager.Instance.install(toInstall, pluginVersion, fromDisk) |
149 | 154 | ||
150 | return res.json(plugin.toFormattedJSON()) | 155 | return res.json(plugin.toFormattedJSON()) |
151 | } catch (err) { | 156 | } catch (err) { |
diff --git a/server/controllers/api/server/stats.ts b/server/controllers/api/server/stats.ts index d661144ca..2ab398f4d 100644 --- a/server/controllers/api/server/stats.ts +++ b/server/controllers/api/server/stats.ts | |||
@@ -3,6 +3,7 @@ import { StatsManager } from '@server/lib/stat-manager' | |||
3 | import { ROUTE_CACHE_LIFETIME } from '../../../initializers/constants' | 3 | import { ROUTE_CACHE_LIFETIME } from '../../../initializers/constants' |
4 | import { asyncMiddleware } from '../../../middlewares' | 4 | import { asyncMiddleware } from '../../../middlewares' |
5 | import { cacheRoute } from '../../../middlewares/cache/cache' | 5 | import { cacheRoute } from '../../../middlewares/cache/cache' |
6 | import { Hooks } from '@server/lib/plugins/hooks' | ||
6 | 7 | ||
7 | const statsRouter = express.Router() | 8 | const statsRouter = express.Router() |
8 | 9 | ||
@@ -12,7 +13,8 @@ statsRouter.get('/stats', | |||
12 | ) | 13 | ) |
13 | 14 | ||
14 | async function getStats (_req: express.Request, res: express.Response) { | 15 | async function getStats (_req: express.Request, res: express.Response) { |
15 | const data = await StatsManager.Instance.getStats() | 16 | let data = await StatsManager.Instance.getStats() |
17 | data = await Hooks.wrapObject(data, 'filter:api.server.stats.get.result') | ||
16 | 18 | ||
17 | return res.json(data) | 19 | return res.json(data) |
18 | } | 20 | } |
diff --git a/server/controllers/api/users/my-subscriptions.ts b/server/controllers/api/users/my-subscriptions.ts index 6799ca8c5..fb1f68635 100644 --- a/server/controllers/api/users/my-subscriptions.ts +++ b/server/controllers/api/users/my-subscriptions.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import 'multer' | 1 | import 'multer' |
2 | import express from 'express' | 2 | import express from 'express' |
3 | import { handlesToNameAndHost } from '@server/helpers/actors' | ||
3 | import { pickCommonVideoQuery } from '@server/helpers/query' | 4 | import { pickCommonVideoQuery } from '@server/helpers/query' |
4 | import { sendUndoFollow } from '@server/lib/activitypub/send' | 5 | import { sendUndoFollow } from '@server/lib/activitypub/send' |
5 | import { guessAdditionalAttributesFromQuery } from '@server/models/video/formatter/video-format-utils' | 6 | import { guessAdditionalAttributesFromQuery } from '@server/models/video/formatter/video-format-utils' |
@@ -7,7 +8,6 @@ import { VideoChannelModel } from '@server/models/video/video-channel' | |||
7 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' | 8 | import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' |
8 | import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils' | 9 | import { buildNSFWFilter, getCountVideos } from '../../../helpers/express-utils' |
9 | import { getFormattedObjects } from '../../../helpers/utils' | 10 | import { getFormattedObjects } from '../../../helpers/utils' |
10 | import { WEBSERVER } from '../../../initializers/constants' | ||
11 | import { sequelizeTypescript } from '../../../initializers/database' | 11 | import { sequelizeTypescript } from '../../../initializers/database' |
12 | import { JobQueue } from '../../../lib/job-queue' | 12 | import { JobQueue } from '../../../lib/job-queue' |
13 | import { | 13 | import { |
@@ -89,28 +89,23 @@ async function areSubscriptionsExist (req: express.Request, res: express.Respons | |||
89 | const uris = req.query.uris as string[] | 89 | const uris = req.query.uris as string[] |
90 | const user = res.locals.oauth.token.User | 90 | const user = res.locals.oauth.token.User |
91 | 91 | ||
92 | const handles = uris.map(u => { | 92 | const sanitizedHandles = handlesToNameAndHost(uris) |
93 | let [ name, host ] = u.split('@') | ||
94 | if (host === WEBSERVER.HOST) host = null | ||
95 | 93 | ||
96 | return { name, host, uri: u } | 94 | const results = await ActorFollowModel.listSubscriptionsOf(user.Account.Actor.id, sanitizedHandles) |
97 | }) | ||
98 | |||
99 | const results = await ActorFollowModel.listSubscriptionsOf(user.Account.Actor.id, handles) | ||
100 | 95 | ||
101 | const existObject: { [id: string ]: boolean } = {} | 96 | const existObject: { [id: string ]: boolean } = {} |
102 | for (const handle of handles) { | 97 | for (const sanitizedHandle of sanitizedHandles) { |
103 | const obj = results.find(r => { | 98 | const obj = results.find(r => { |
104 | const server = r.ActorFollowing.Server | 99 | const server = r.ActorFollowing.Server |
105 | 100 | ||
106 | return r.ActorFollowing.preferredUsername === handle.name && | 101 | return r.ActorFollowing.preferredUsername === sanitizedHandle.name && |
107 | ( | 102 | ( |
108 | (!server && !handle.host) || | 103 | (!server && !sanitizedHandle.host) || |
109 | (server.host === handle.host) | 104 | (server.host === sanitizedHandle.host) |
110 | ) | 105 | ) |
111 | }) | 106 | }) |
112 | 107 | ||
113 | existObject[handle.uri] = obj !== undefined | 108 | existObject[sanitizedHandle.handle] = obj !== undefined |
114 | } | 109 | } |
115 | 110 | ||
116 | return res.json(existObject) | 111 | return res.json(existObject) |
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index eddb9b32d..52864bdfd 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts | |||
@@ -38,6 +38,7 @@ import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoIm | |||
38 | import { VideoModel } from '../../../models/video/video' | 38 | import { VideoModel } from '../../../models/video/video' |
39 | import { VideoCaptionModel } from '../../../models/video/video-caption' | 39 | import { VideoCaptionModel } from '../../../models/video/video-caption' |
40 | import { VideoImportModel } from '../../../models/video/video-import' | 40 | import { VideoImportModel } from '../../../models/video/video-import' |
41 | import { Hooks } from '@server/lib/plugins/hooks' | ||
41 | 42 | ||
42 | const auditLogger = auditLoggerFactory('video-imports') | 43 | const auditLogger = auditLoggerFactory('video-imports') |
43 | const videoImportsRouter = express.Router() | 44 | const videoImportsRouter = express.Router() |
@@ -94,7 +95,7 @@ async function addTorrentImport (req: express.Request, res: express.Response, to | |||
94 | videoName = result.name | 95 | videoName = result.name |
95 | } | 96 | } |
96 | 97 | ||
97 | const video = buildVideo(res.locals.videoChannel.id, body, { name: videoName }) | 98 | const video = await buildVideo(res.locals.videoChannel.id, body, { name: videoName }) |
98 | 99 | ||
99 | const thumbnailModel = await processThumbnail(req, video) | 100 | const thumbnailModel = await processThumbnail(req, video) |
100 | const previewModel = await processPreview(req, video) | 101 | const previewModel = await processPreview(req, video) |
@@ -151,7 +152,7 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response) | |||
151 | }) | 152 | }) |
152 | } | 153 | } |
153 | 154 | ||
154 | const video = buildVideo(res.locals.videoChannel.id, body, youtubeDLInfo) | 155 | const video = await buildVideo(res.locals.videoChannel.id, body, youtubeDLInfo) |
155 | 156 | ||
156 | // Process video thumbnail from request.files | 157 | // Process video thumbnail from request.files |
157 | let thumbnailModel = await processThumbnail(req, video) | 158 | let thumbnailModel = await processThumbnail(req, video) |
@@ -210,8 +211,8 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response) | |||
210 | return res.json(videoImport.toFormattedJSON()).end() | 211 | return res.json(videoImport.toFormattedJSON()).end() |
211 | } | 212 | } |
212 | 213 | ||
213 | function buildVideo (channelId: number, body: VideoImportCreate, importData: YoutubeDLInfo): MVideoThumbnail { | 214 | async function buildVideo (channelId: number, body: VideoImportCreate, importData: YoutubeDLInfo): Promise<MVideoThumbnail> { |
214 | const videoData = { | 215 | let videoData = { |
215 | name: body.name || importData.name || 'Unknown name', | 216 | name: body.name || importData.name || 'Unknown name', |
216 | remote: false, | 217 | remote: false, |
217 | category: body.category || importData.category, | 218 | category: body.category || importData.category, |
@@ -231,6 +232,14 @@ function buildVideo (channelId: number, body: VideoImportCreate, importData: You | |||
231 | ? new Date(body.originallyPublishedAt) | 232 | ? new Date(body.originallyPublishedAt) |
232 | : importData.originallyPublishedAt | 233 | : importData.originallyPublishedAt |
233 | } | 234 | } |
235 | |||
236 | videoData = await Hooks.wrapObject( | ||
237 | videoData, | ||
238 | body.targetUrl | ||
239 | ? 'filter:api.video.import-url.video-attribute.result' | ||
240 | : 'filter:api.video.import-torrent.video-attribute.result' | ||
241 | ) | ||
242 | |||
234 | const video = new VideoModel(videoData) | 243 | const video = new VideoModel(videoData) |
235 | video.url = getLocalVideoActivityPubUrl(video) | 244 | video.url = getLocalVideoActivityPubUrl(video) |
236 | 245 | ||
diff --git a/server/controllers/api/videos/live.ts b/server/controllers/api/videos/live.ts index e29615ff5..3e1480cf2 100644 --- a/server/controllers/api/videos/live.ts +++ b/server/controllers/api/videos/live.ts | |||
@@ -83,7 +83,9 @@ async function addLiveVideo (req: express.Request, res: express.Response) { | |||
83 | const videoInfo: LiveVideoCreate = req.body | 83 | const videoInfo: LiveVideoCreate = req.body |
84 | 84 | ||
85 | // Prepare data so we don't block the transaction | 85 | // Prepare data so we don't block the transaction |
86 | const videoData = buildLocalVideoFromReq(videoInfo, res.locals.videoChannel.id) | 86 | let videoData = buildLocalVideoFromReq(videoInfo, res.locals.videoChannel.id) |
87 | videoData = await Hooks.wrapObject(videoData, 'filter:api.video.live.video-attribute.result') | ||
88 | |||
87 | videoData.isLive = true | 89 | videoData.isLive = true |
88 | videoData.state = VideoState.WAITING_FOR_LIVE | 90 | videoData.state = VideoState.WAITING_FOR_LIVE |
89 | videoData.duration = 0 | 91 | videoData.duration = 0 |
diff --git a/server/controllers/api/videos/update.ts b/server/controllers/api/videos/update.ts index 3fcff3e86..589556f47 100644 --- a/server/controllers/api/videos/update.ts +++ b/server/controllers/api/videos/update.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { Transaction } from 'sequelize/types' | 2 | import { Transaction } from 'sequelize/types' |
3 | import { updateTorrentMetadata } from '@server/helpers/webtorrent' | ||
3 | import { changeVideoChannelShare } from '@server/lib/activitypub/share' | 4 | import { changeVideoChannelShare } from '@server/lib/activitypub/share' |
4 | import { buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video' | 5 | import { buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video' |
5 | import { openapiOperationDoc } from '@server/middlewares/doc' | 6 | import { openapiOperationDoc } from '@server/middlewares/doc' |
@@ -68,7 +69,7 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
68 | }) | 69 | }) |
69 | 70 | ||
70 | try { | 71 | try { |
71 | const videoInstanceUpdated = await sequelizeTypescript.transaction(async t => { | 72 | const { videoInstanceUpdated, isNewVideo } = await sequelizeTypescript.transaction(async t => { |
72 | // Refresh video since thumbnails to prevent concurrent updates | 73 | // Refresh video since thumbnails to prevent concurrent updates |
73 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoFromReq.id, t) | 74 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoFromReq.id, t) |
74 | 75 | ||
@@ -137,8 +138,6 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
137 | transaction: t | 138 | transaction: t |
138 | }) | 139 | }) |
139 | 140 | ||
140 | await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) | ||
141 | |||
142 | auditLogger.update( | 141 | auditLogger.update( |
143 | getAuditIdFromRes(res), | 142 | getAuditIdFromRes(res), |
144 | new VideoAuditView(videoInstanceUpdated.toFormattedDetailsJSON()), | 143 | new VideoAuditView(videoInstanceUpdated.toFormattedDetailsJSON()), |
@@ -146,12 +145,14 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
146 | ) | 145 | ) |
147 | logger.info('Video with name %s and uuid %s updated.', video.name, video.uuid, lTags(video.uuid)) | 146 | logger.info('Video with name %s and uuid %s updated.', video.name, video.uuid, lTags(video.uuid)) |
148 | 147 | ||
149 | return videoInstanceUpdated | 148 | return { videoInstanceUpdated, isNewVideo } |
150 | }) | 149 | }) |
151 | 150 | ||
152 | if (wasConfidentialVideo) { | 151 | if (videoInfoToUpdate.name) await updateTorrentsMetadata(videoInstanceUpdated) |
153 | Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated) | 152 | |
154 | } | 153 | await sequelizeTypescript.transaction(t => federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)) |
154 | |||
155 | if (wasConfidentialVideo) Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated) | ||
155 | 156 | ||
156 | Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated, body: req.body, req, res }) | 157 | Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated, body: req.body, req, res }) |
157 | } catch (err) { | 158 | } catch (err) { |
@@ -199,3 +200,20 @@ function updateSchedule (videoInstance: MVideoFullLight, videoInfoToUpdate: Vide | |||
199 | return ScheduleVideoUpdateModel.deleteByVideoId(videoInstance.id, transaction) | 200 | return ScheduleVideoUpdateModel.deleteByVideoId(videoInstance.id, transaction) |
200 | } | 201 | } |
201 | } | 202 | } |
203 | |||
204 | async function updateTorrentsMetadata (video: MVideoFullLight) { | ||
205 | for (const file of (video.VideoFiles || [])) { | ||
206 | await updateTorrentMetadata(video, file) | ||
207 | |||
208 | await file.save() | ||
209 | } | ||
210 | |||
211 | const hls = video.getHLSPlaylist() | ||
212 | if (!hls) return | ||
213 | |||
214 | for (const file of (hls.VideoFiles || [])) { | ||
215 | await updateTorrentMetadata(hls, file) | ||
216 | |||
217 | await file.save() | ||
218 | } | ||
219 | } | ||
diff --git a/server/controllers/api/videos/upload.ts b/server/controllers/api/videos/upload.ts index 6773b500f..1be87f746 100644 --- a/server/controllers/api/videos/upload.ts +++ b/server/controllers/api/videos/upload.ts | |||
@@ -8,6 +8,7 @@ import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' | |||
8 | import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' | 8 | import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' |
9 | import { generateWebTorrentVideoFilename } from '@server/lib/paths' | 9 | import { generateWebTorrentVideoFilename } from '@server/lib/paths' |
10 | import { Redis } from '@server/lib/redis' | 10 | import { Redis } from '@server/lib/redis' |
11 | import { uploadx } from '@server/lib/uploadx' | ||
11 | import { | 12 | import { |
12 | addMoveToObjectStorageJob, | 13 | addMoveToObjectStorageJob, |
13 | addOptimizeOrMergeAudioJob, | 14 | addOptimizeOrMergeAudioJob, |
@@ -19,7 +20,6 @@ import { VideoPathManager } from '@server/lib/video-path-manager' | |||
19 | import { buildNextVideoState } from '@server/lib/video-state' | 20 | import { buildNextVideoState } from '@server/lib/video-state' |
20 | import { openapiOperationDoc } from '@server/middlewares/doc' | 21 | import { openapiOperationDoc } from '@server/middlewares/doc' |
21 | import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models' | 22 | import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models' |
22 | import { Uploadx } from '@uploadx/core' | ||
23 | import { VideoCreate, VideoState } from '../../../../shared' | 23 | import { VideoCreate, VideoState } from '../../../../shared' |
24 | import { HttpStatusCode } from '../../../../shared/models' | 24 | import { HttpStatusCode } from '../../../../shared/models' |
25 | import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' | 25 | import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' |
@@ -41,8 +41,8 @@ import { | |||
41 | authenticate, | 41 | authenticate, |
42 | videosAddLegacyValidator, | 42 | videosAddLegacyValidator, |
43 | videosAddResumableInitValidator, | 43 | videosAddResumableInitValidator, |
44 | videosResumableUploadIdValidator, | 44 | videosAddResumableValidator, |
45 | videosAddResumableValidator | 45 | videosResumableUploadIdValidator |
46 | } from '../../../middlewares' | 46 | } from '../../../middlewares' |
47 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' | 47 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' |
48 | import { VideoModel } from '../../../models/video/video' | 48 | import { VideoModel } from '../../../models/video/video' |
@@ -52,9 +52,6 @@ const lTags = loggerTagsFactory('api', 'video') | |||
52 | const auditLogger = auditLoggerFactory('videos') | 52 | const auditLogger = auditLoggerFactory('videos') |
53 | const uploadRouter = express.Router() | 53 | const uploadRouter = express.Router() |
54 | 54 | ||
55 | const uploadx = new Uploadx({ directory: getResumableUploadPath() }) | ||
56 | uploadx.getUserId = (_, res: express.Response) => res.locals.oauth?.token.user.id | ||
57 | |||
58 | const reqVideoFileAdd = createReqFiles( | 55 | const reqVideoFileAdd = createReqFiles( |
59 | [ 'videofile', 'thumbnailfile', 'previewfile' ], | 56 | [ 'videofile', 'thumbnailfile', 'previewfile' ], |
60 | Object.assign({}, MIMETYPES.VIDEO.MIMETYPE_EXT, MIMETYPES.IMAGE.MIMETYPE_EXT), | 57 | Object.assign({}, MIMETYPES.VIDEO.MIMETYPE_EXT, MIMETYPES.IMAGE.MIMETYPE_EXT), |
@@ -156,7 +153,8 @@ async function addVideo (options: { | |||
156 | const videoChannel = res.locals.videoChannel | 153 | const videoChannel = res.locals.videoChannel |
157 | const user = res.locals.oauth.token.User | 154 | const user = res.locals.oauth.token.User |
158 | 155 | ||
159 | const videoData = buildLocalVideoFromReq(videoInfo, videoChannel.id) | 156 | let videoData = buildLocalVideoFromReq(videoInfo, videoChannel.id) |
157 | videoData = await Hooks.wrapObject(videoData, 'filter:api.video.upload.video-attribute.result') | ||
160 | 158 | ||
161 | videoData.state = buildNextVideoState() | 159 | videoData.state = buildNextVideoState() |
162 | videoData.duration = videoPhysicalFile.duration // duration was added by a previous middleware | 160 | videoData.duration = videoPhysicalFile.duration // duration was added by a previous middleware |
diff --git a/server/helpers/actors.ts b/server/helpers/actors.ts new file mode 100644 index 000000000..c31fe6f8e --- /dev/null +++ b/server/helpers/actors.ts | |||
@@ -0,0 +1,17 @@ | |||
1 | import { WEBSERVER } from '@server/initializers/constants' | ||
2 | |||
3 | function handleToNameAndHost (handle: string) { | ||
4 | let [ name, host ] = handle.split('@') | ||
5 | if (host === WEBSERVER.HOST) host = null | ||
6 | |||
7 | return { name, host, handle } | ||
8 | } | ||
9 | |||
10 | function handlesToNameAndHost (handles: string[]) { | ||
11 | return handles.map(h => handleToNameAndHost(h)) | ||
12 | } | ||
13 | |||
14 | export { | ||
15 | handleToNameAndHost, | ||
16 | handlesToNameAndHost | ||
17 | } | ||
diff --git a/server/helpers/decache.ts b/server/helpers/decache.ts new file mode 100644 index 000000000..e31973b7a --- /dev/null +++ b/server/helpers/decache.ts | |||
@@ -0,0 +1,78 @@ | |||
1 | // Thanks: https://github.com/dwyl/decache | ||
2 | // We reuse this file to also uncache plugin base path | ||
3 | |||
4 | import { extname } from 'path' | ||
5 | |||
6 | function decachePlugin (pluginPath: string, libraryPath: string) { | ||
7 | const moduleName = find(libraryPath) | ||
8 | |||
9 | if (!moduleName) return | ||
10 | |||
11 | searchCache(moduleName, function (mod) { | ||
12 | delete require.cache[mod.id] | ||
13 | }) | ||
14 | |||
15 | removeCachedPath(pluginPath) | ||
16 | } | ||
17 | |||
18 | function decacheModule (name: string) { | ||
19 | const moduleName = find(name) | ||
20 | |||
21 | if (!moduleName) return | ||
22 | |||
23 | searchCache(moduleName, function (mod) { | ||
24 | delete require.cache[mod.id] | ||
25 | }) | ||
26 | |||
27 | removeCachedPath(moduleName) | ||
28 | } | ||
29 | |||
30 | // --------------------------------------------------------------------------- | ||
31 | |||
32 | export { | ||
33 | decacheModule, | ||
34 | decachePlugin | ||
35 | } | ||
36 | |||
37 | // --------------------------------------------------------------------------- | ||
38 | |||
39 | function find (moduleName: string) { | ||
40 | try { | ||
41 | return require.resolve(moduleName) | ||
42 | } catch { | ||
43 | return '' | ||
44 | } | ||
45 | } | ||
46 | |||
47 | function searchCache (moduleName: string, callback: (current: NodeModule) => void) { | ||
48 | const resolvedModule = require.resolve(moduleName) | ||
49 | let mod: NodeModule | ||
50 | const visited = {} | ||
51 | |||
52 | if (resolvedModule && ((mod = require.cache[resolvedModule]) !== undefined)) { | ||
53 | // Recursively go over the results | ||
54 | (function run (current) { | ||
55 | visited[current.id] = true | ||
56 | |||
57 | current.children.forEach(function (child) { | ||
58 | if (extname(child.filename) !== '.node' && !visited[child.id]) { | ||
59 | run(child) | ||
60 | } | ||
61 | }) | ||
62 | |||
63 | // Call the specified callback providing the | ||
64 | // found module | ||
65 | callback(current) | ||
66 | })(mod) | ||
67 | } | ||
68 | }; | ||
69 | |||
70 | function removeCachedPath (pluginPath: string) { | ||
71 | const pathCache = (module.constructor as any)._pathCache | ||
72 | |||
73 | Object.keys(pathCache).forEach(function (cacheKey) { | ||
74 | if (cacheKey.includes(pluginPath)) { | ||
75 | delete pathCache[cacheKey] | ||
76 | } | ||
77 | }) | ||
78 | } | ||
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts index c75c058e4..ecc703646 100644 --- a/server/helpers/webtorrent.ts +++ b/server/helpers/webtorrent.ts | |||
@@ -14,7 +14,7 @@ import { MVideo } from '@server/types/models/video/video' | |||
14 | import { MVideoFile, MVideoFileRedundanciesOpt } from '@server/types/models/video/video-file' | 14 | import { MVideoFile, MVideoFileRedundanciesOpt } from '@server/types/models/video/video-file' |
15 | import { MStreamingPlaylistVideo } from '@server/types/models/video/video-streaming-playlist' | 15 | import { MStreamingPlaylistVideo } from '@server/types/models/video/video-streaming-playlist' |
16 | import { CONFIG } from '../initializers/config' | 16 | import { CONFIG } from '../initializers/config' |
17 | import { promisify2 } from './core-utils' | 17 | import { promisify2, sha1 } from './core-utils' |
18 | import { logger } from './logger' | 18 | import { logger } from './logger' |
19 | import { generateVideoImportTmpPath } from './utils' | 19 | import { generateVideoImportTmpPath } from './utils' |
20 | import { extractVideo } from './video' | 20 | import { extractVideo } from './video' |
@@ -94,7 +94,7 @@ function createTorrentAndSetInfoHash (videoOrPlaylist: MVideo | MStreamingPlayli | |||
94 | 94 | ||
95 | const options = { | 95 | const options = { |
96 | // Keep the extname, it's used by the client to stream the file inside a web browser | 96 | // Keep the extname, it's used by the client to stream the file inside a web browser |
97 | name: `${video.name} ${videoFile.resolution}p${videoFile.extname}`, | 97 | name: buildInfoName(video, videoFile), |
98 | createdBy: 'PeerTube', | 98 | createdBy: 'PeerTube', |
99 | announceList: buildAnnounceList(), | 99 | announceList: buildAnnounceList(), |
100 | urlList: buildUrlList(video, videoFile) | 100 | urlList: buildUrlList(video, videoFile) |
@@ -120,7 +120,7 @@ function createTorrentAndSetInfoHash (videoOrPlaylist: MVideo | MStreamingPlayli | |||
120 | }) | 120 | }) |
121 | } | 121 | } |
122 | 122 | ||
123 | async function updateTorrentUrls (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { | 123 | async function updateTorrentMetadata (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, videoFile: MVideoFile) { |
124 | const video = extractVideo(videoOrPlaylist) | 124 | const video = extractVideo(videoOrPlaylist) |
125 | 125 | ||
126 | const oldTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename) | 126 | const oldTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename) |
@@ -133,15 +133,19 @@ async function updateTorrentUrls (videoOrPlaylist: MVideo | MStreamingPlaylistVi | |||
133 | 133 | ||
134 | decoded['url-list'] = buildUrlList(video, videoFile) | 134 | decoded['url-list'] = buildUrlList(video, videoFile) |
135 | 135 | ||
136 | decoded.info.name = buildInfoName(video, videoFile) | ||
137 | decoded['creation date'] = Math.ceil(Date.now() / 1000) | ||
138 | |||
136 | const newTorrentFilename = generateTorrentFileName(videoOrPlaylist, videoFile.resolution) | 139 | const newTorrentFilename = generateTorrentFileName(videoOrPlaylist, videoFile.resolution) |
137 | const newTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, newTorrentFilename) | 140 | const newTorrentPath = join(CONFIG.STORAGE.TORRENTS_DIR, newTorrentFilename) |
138 | 141 | ||
139 | logger.info('Updating torrent URLs %s -> %s.', oldTorrentPath, newTorrentPath) | 142 | logger.info('Updating torrent metadata %s -> %s.', oldTorrentPath, newTorrentPath) |
140 | 143 | ||
141 | await writeFile(newTorrentPath, encode(decoded)) | 144 | await writeFile(newTorrentPath, encode(decoded)) |
142 | await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)) | 145 | await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)) |
143 | 146 | ||
144 | videoFile.torrentFilename = newTorrentFilename | 147 | videoFile.torrentFilename = newTorrentFilename |
148 | videoFile.infoHash = sha1(encode(decoded.info)) | ||
145 | } | 149 | } |
146 | 150 | ||
147 | function generateMagnetUri ( | 151 | function generateMagnetUri ( |
@@ -171,7 +175,7 @@ function generateMagnetUri ( | |||
171 | 175 | ||
172 | export { | 176 | export { |
173 | createTorrentPromise, | 177 | createTorrentPromise, |
174 | updateTorrentUrls, | 178 | updateTorrentMetadata, |
175 | createTorrentAndSetInfoHash, | 179 | createTorrentAndSetInfoHash, |
176 | generateMagnetUri, | 180 | generateMagnetUri, |
177 | downloadWebTorrentVideo | 181 | downloadWebTorrentVideo |
@@ -226,3 +230,7 @@ function buildAnnounceList () { | |||
226 | function buildUrlList (video: MVideo, videoFile: MVideoFile) { | 230 | function buildUrlList (video: MVideo, videoFile: MVideoFile) { |
227 | return [ videoFile.getFileUrl(video) ] | 231 | return [ videoFile.getFileUrl(video) ] |
228 | } | 232 | } |
233 | |||
234 | function buildInfoName (video: MVideo, videoFile: MVideoFile) { | ||
235 | return `${video.name} ${videoFile.resolution}p${videoFile.extname}` | ||
236 | } | ||
diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts index 51c396548..c85c389cd 100644 --- a/server/initializers/checker-before-init.ts +++ b/server/initializers/checker-before-init.ts | |||
@@ -33,6 +33,7 @@ function checkMissedConfig () { | |||
33 | 'transcoding.resolutions.2160p', | 33 | 'transcoding.resolutions.2160p', |
34 | 'import.videos.http.enabled', 'import.videos.torrent.enabled', 'import.videos.concurrency', 'auto_blacklist.videos.of_users.enabled', | 34 | 'import.videos.http.enabled', 'import.videos.torrent.enabled', 'import.videos.concurrency', 'auto_blacklist.videos.of_users.enabled', |
35 | 'trending.videos.interval_days', | 35 | 'trending.videos.interval_days', |
36 | 'client.videos.miniature.prefer_author_display_name', 'client.menu.login.redirect_on_single_external_auth', | ||
36 | 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route', | 37 | 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route', |
37 | 'instance.is_nsfw', 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt', | 38 | 'instance.is_nsfw', 'instance.default_nsfw_policy', 'instance.robots', 'instance.securitytxt', |
38 | 'services.twitter.username', 'services.twitter.whitelisted', | 39 | 'services.twitter.username', 'services.twitter.whitelisted', |
diff --git a/server/initializers/config.ts b/server/initializers/config.ts index dadda2a77..eb848be6b 100644 --- a/server/initializers/config.ts +++ b/server/initializers/config.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import bytes from 'bytes' | 1 | import bytes from 'bytes' |
2 | import { IConfig } from 'config' | 2 | import { IConfig } from 'config' |
3 | import decache from 'decache' | ||
4 | import { dirname, join } from 'path' | 3 | import { dirname, join } from 'path' |
4 | import { decacheModule } from '@server/helpers/decache' | ||
5 | import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' | 5 | import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' |
6 | import { BroadcastMessageLevel } from '@shared/models/server' | 6 | import { BroadcastMessageLevel } from '@shared/models/server' |
7 | import { VideosRedundancyStrategy } from '../../shared/models' | 7 | import { VideosRedundancyStrategy } from '../../shared/models' |
@@ -63,6 +63,11 @@ const CONFIG = { | |||
63 | MINIATURE: { | 63 | MINIATURE: { |
64 | get PREFER_AUTHOR_DISPLAY_NAME () { return config.get<boolean>('client.videos.miniature.prefer_author_display_name') } | 64 | get PREFER_AUTHOR_DISPLAY_NAME () { return config.get<boolean>('client.videos.miniature.prefer_author_display_name') } |
65 | } | 65 | } |
66 | }, | ||
67 | MENU: { | ||
68 | LOGIN: { | ||
69 | get REDIRECT_ON_SINGLE_EXTERNAL_AUTH () { return config.get<boolean>('client.menu.login.redirect_on_single_external_auth') } | ||
70 | } | ||
66 | } | 71 | } |
67 | }, | 72 | }, |
68 | 73 | ||
@@ -497,7 +502,7 @@ export function reloadConfig () { | |||
497 | delete require.cache[fileName] | 502 | delete require.cache[fileName] |
498 | } | 503 | } |
499 | 504 | ||
500 | decache('config') | 505 | decacheModule('config') |
501 | } | 506 | } |
502 | 507 | ||
503 | purge() | 508 | purge() |
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index b8633e83e..c61c01d62 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -223,7 +223,7 @@ const SCHEDULER_INTERVALS_MS = { | |||
223 | REMOVE_OLD_VIEWS: 60000 * 60 * 24, // 1 day | 223 | REMOVE_OLD_VIEWS: 60000 * 60 * 24, // 1 day |
224 | REMOVE_OLD_HISTORY: 60000 * 60 * 24, // 1 day | 224 | REMOVE_OLD_HISTORY: 60000 * 60 * 24, // 1 day |
225 | UPDATE_INBOX_STATS: 1000 * 60, // 1 minute | 225 | UPDATE_INBOX_STATS: 1000 * 60, // 1 minute |
226 | REMOVE_DANGLING_RESUMABLE_UPLOADS: 60000 * 60 * 16 // 16 hours | 226 | REMOVE_DANGLING_RESUMABLE_UPLOADS: 60000 * 60 // 1 hour |
227 | } | 227 | } |
228 | 228 | ||
229 | // --------------------------------------------------------------------------- | 229 | // --------------------------------------------------------------------------- |
diff --git a/server/lib/activitypub/process/process-flag.ts b/server/lib/activitypub/process/process-flag.ts index 7ed409d0e..fd3e46e2b 100644 --- a/server/lib/activitypub/process/process-flag.ts +++ b/server/lib/activitypub/process/process-flag.ts | |||
@@ -75,7 +75,8 @@ async function processCreateAbuse (activity: ActivityCreate | ActivityFlag, byAc | |||
75 | endAt, | 75 | endAt, |
76 | reporterAccount, | 76 | reporterAccount, |
77 | transaction: t, | 77 | transaction: t, |
78 | videoInstance: video | 78 | videoInstance: video, |
79 | skipNotification: false | ||
79 | }) | 80 | }) |
80 | } | 81 | } |
81 | 82 | ||
@@ -84,7 +85,8 @@ async function processCreateAbuse (activity: ActivityCreate | ActivityFlag, byAc | |||
84 | baseAbuse, | 85 | baseAbuse, |
85 | reporterAccount, | 86 | reporterAccount, |
86 | transaction: t, | 87 | transaction: t, |
87 | commentInstance: videoComment | 88 | commentInstance: videoComment, |
89 | skipNotification: false | ||
88 | }) | 90 | }) |
89 | } | 91 | } |
90 | 92 | ||
@@ -92,7 +94,8 @@ async function processCreateAbuse (activity: ActivityCreate | ActivityFlag, byAc | |||
92 | baseAbuse, | 94 | baseAbuse, |
93 | reporterAccount, | 95 | reporterAccount, |
94 | transaction: t, | 96 | transaction: t, |
95 | accountInstance: flaggedAccount | 97 | accountInstance: flaggedAccount, |
98 | skipNotification: false | ||
96 | }) | 99 | }) |
97 | }) | 100 | }) |
98 | } catch (err) { | 101 | } catch (err) { |
diff --git a/server/lib/blocklist.ts b/server/lib/blocklist.ts index d6b684015..98273a6ea 100644 --- a/server/lib/blocklist.ts +++ b/server/lib/blocklist.ts | |||
@@ -40,12 +40,12 @@ async function isBlockedByServerOrAccount (targetAccount: MAccountServer, userAc | |||
40 | 40 | ||
41 | if (userAccount) sourceAccounts.push(userAccount.id) | 41 | if (userAccount) sourceAccounts.push(userAccount.id) |
42 | 42 | ||
43 | const accountMutedHash = await AccountBlocklistModel.isAccountMutedByMulti(sourceAccounts, targetAccount.id) | 43 | const accountMutedHash = await AccountBlocklistModel.isAccountMutedByAccounts(sourceAccounts, targetAccount.id) |
44 | if (accountMutedHash[serverAccountId] || (userAccount && accountMutedHash[userAccount.id])) { | 44 | if (accountMutedHash[serverAccountId] || (userAccount && accountMutedHash[userAccount.id])) { |
45 | return true | 45 | return true |
46 | } | 46 | } |
47 | 47 | ||
48 | const instanceMutedHash = await ServerBlocklistModel.isServerMutedByMulti(sourceAccounts, targetAccount.Actor.serverId) | 48 | const instanceMutedHash = await ServerBlocklistModel.isServerMutedByAccounts(sourceAccounts, targetAccount.Actor.serverId) |
49 | if (instanceMutedHash[serverAccountId] || (userAccount && instanceMutedHash[userAccount.id])) { | 49 | if (instanceMutedHash[serverAccountId] || (userAccount && instanceMutedHash[userAccount.id])) { |
50 | return true | 50 | return true |
51 | } | 51 | } |
diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index 360b4667f..adc3d712e 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts | |||
@@ -350,10 +350,6 @@ class ClientHtml { | |||
350 | return join(__dirname, '../../../client/dist/standalone/videos/embed.html') | 350 | return join(__dirname, '../../../client/dist/standalone/videos/embed.html') |
351 | } | 351 | } |
352 | 352 | ||
353 | private static addHtmlLang (htmlStringPage: string, paramLang: string) { | ||
354 | return htmlStringPage.replace('<html>', `<html lang="${paramLang}">`) | ||
355 | } | ||
356 | |||
357 | private static addManifestContentHash (htmlStringPage: string) { | 353 | private static addManifestContentHash (htmlStringPage: string) { |
358 | return htmlStringPage.replace('[manifestContentHash]', FILES_CONTENT_HASH.MANIFEST) | 354 | return htmlStringPage.replace('[manifestContentHash]', FILES_CONTENT_HASH.MANIFEST) |
359 | } | 355 | } |
diff --git a/server/lib/job-queue/handlers/move-to-object-storage.ts b/server/lib/job-queue/handlers/move-to-object-storage.ts index 54a7c566b..b5eea0184 100644 --- a/server/lib/job-queue/handlers/move-to-object-storage.ts +++ b/server/lib/job-queue/handlers/move-to-object-storage.ts | |||
@@ -2,7 +2,7 @@ import { Job } from 'bull' | |||
2 | import { remove } from 'fs-extra' | 2 | import { remove } from 'fs-extra' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { logger } from '@server/helpers/logger' | 4 | import { logger } from '@server/helpers/logger' |
5 | import { updateTorrentUrls } from '@server/helpers/webtorrent' | 5 | import { updateTorrentMetadata } from '@server/helpers/webtorrent' |
6 | import { CONFIG } from '@server/initializers/config' | 6 | import { CONFIG } from '@server/initializers/config' |
7 | import { P2P_MEDIA_LOADER_PEER_VERSION } from '@server/initializers/constants' | 7 | import { P2P_MEDIA_LOADER_PEER_VERSION } from '@server/initializers/constants' |
8 | import { storeHLSFile, storeWebTorrentFile } from '@server/lib/object-storage' | 8 | import { storeHLSFile, storeWebTorrentFile } from '@server/lib/object-storage' |
@@ -113,7 +113,7 @@ async function onFileMoved (options: { | |||
113 | file.fileUrl = fileUrl | 113 | file.fileUrl = fileUrl |
114 | file.storage = VideoStorage.OBJECT_STORAGE | 114 | file.storage = VideoStorage.OBJECT_STORAGE |
115 | 115 | ||
116 | await updateTorrentUrls(videoOrPlaylist, file) | 116 | await updateTorrentMetadata(videoOrPlaylist, file) |
117 | await file.save() | 117 | await file.save() |
118 | 118 | ||
119 | logger.debug('Removing %s because it\'s now on object storage', oldPath) | 119 | logger.debug('Removing %s because it\'s now on object storage', oldPath) |
diff --git a/server/lib/moderation.ts b/server/lib/moderation.ts index 456b615b2..c2565f867 100644 --- a/server/lib/moderation.ts +++ b/server/lib/moderation.ts | |||
@@ -107,8 +107,9 @@ async function createVideoAbuse (options: { | |||
107 | endAt: number | 107 | endAt: number |
108 | transaction: Transaction | 108 | transaction: Transaction |
109 | reporterAccount: MAccountDefault | 109 | reporterAccount: MAccountDefault |
110 | skipNotification: boolean | ||
110 | }) { | 111 | }) { |
111 | const { baseAbuse, videoInstance, startAt, endAt, transaction, reporterAccount } = options | 112 | const { baseAbuse, videoInstance, startAt, endAt, transaction, reporterAccount, skipNotification } = options |
112 | 113 | ||
113 | const associateFun = async (abuseInstance: MAbuseFull) => { | 114 | const associateFun = async (abuseInstance: MAbuseFull) => { |
114 | const videoAbuseInstance: MVideoAbuseVideoFull = await VideoAbuseModel.create({ | 115 | const videoAbuseInstance: MVideoAbuseVideoFull = await VideoAbuseModel.create({ |
@@ -129,6 +130,7 @@ async function createVideoAbuse (options: { | |||
129 | reporterAccount, | 130 | reporterAccount, |
130 | flaggedAccount: videoInstance.VideoChannel.Account, | 131 | flaggedAccount: videoInstance.VideoChannel.Account, |
131 | transaction, | 132 | transaction, |
133 | skipNotification, | ||
132 | associateFun | 134 | associateFun |
133 | }) | 135 | }) |
134 | } | 136 | } |
@@ -138,8 +140,9 @@ function createVideoCommentAbuse (options: { | |||
138 | commentInstance: MCommentOwnerVideo | 140 | commentInstance: MCommentOwnerVideo |
139 | transaction: Transaction | 141 | transaction: Transaction |
140 | reporterAccount: MAccountDefault | 142 | reporterAccount: MAccountDefault |
143 | skipNotification: boolean | ||
141 | }) { | 144 | }) { |
142 | const { baseAbuse, commentInstance, transaction, reporterAccount } = options | 145 | const { baseAbuse, commentInstance, transaction, reporterAccount, skipNotification } = options |
143 | 146 | ||
144 | const associateFun = async (abuseInstance: MAbuseFull) => { | 147 | const associateFun = async (abuseInstance: MAbuseFull) => { |
145 | const commentAbuseInstance: MCommentAbuseAccountVideo = await VideoCommentAbuseModel.create({ | 148 | const commentAbuseInstance: MCommentAbuseAccountVideo = await VideoCommentAbuseModel.create({ |
@@ -158,6 +161,7 @@ function createVideoCommentAbuse (options: { | |||
158 | reporterAccount, | 161 | reporterAccount, |
159 | flaggedAccount: commentInstance.Account, | 162 | flaggedAccount: commentInstance.Account, |
160 | transaction, | 163 | transaction, |
164 | skipNotification, | ||
161 | associateFun | 165 | associateFun |
162 | }) | 166 | }) |
163 | } | 167 | } |
@@ -167,8 +171,9 @@ function createAccountAbuse (options: { | |||
167 | accountInstance: MAccountDefault | 171 | accountInstance: MAccountDefault |
168 | transaction: Transaction | 172 | transaction: Transaction |
169 | reporterAccount: MAccountDefault | 173 | reporterAccount: MAccountDefault |
174 | skipNotification: boolean | ||
170 | }) { | 175 | }) { |
171 | const { baseAbuse, accountInstance, transaction, reporterAccount } = options | 176 | const { baseAbuse, accountInstance, transaction, reporterAccount, skipNotification } = options |
172 | 177 | ||
173 | const associateFun = () => { | 178 | const associateFun = () => { |
174 | return Promise.resolve({ isOwned: accountInstance.isOwned() }) | 179 | return Promise.resolve({ isOwned: accountInstance.isOwned() }) |
@@ -179,6 +184,7 @@ function createAccountAbuse (options: { | |||
179 | reporterAccount, | 184 | reporterAccount, |
180 | flaggedAccount: accountInstance, | 185 | flaggedAccount: accountInstance, |
181 | transaction, | 186 | transaction, |
187 | skipNotification, | ||
182 | associateFun | 188 | associateFun |
183 | }) | 189 | }) |
184 | } | 190 | } |
@@ -207,9 +213,10 @@ async function createAbuse (options: { | |||
207 | reporterAccount: MAccountDefault | 213 | reporterAccount: MAccountDefault |
208 | flaggedAccount: MAccountLight | 214 | flaggedAccount: MAccountLight |
209 | associateFun: (abuseInstance: MAbuseFull) => Promise<{ isOwned: boolean} > | 215 | associateFun: (abuseInstance: MAbuseFull) => Promise<{ isOwned: boolean} > |
216 | skipNotification: boolean | ||
210 | transaction: Transaction | 217 | transaction: Transaction |
211 | }) { | 218 | }) { |
212 | const { base, reporterAccount, flaggedAccount, associateFun, transaction } = options | 219 | const { base, reporterAccount, flaggedAccount, associateFun, transaction, skipNotification } = options |
213 | const auditLogger = auditLoggerFactory('abuse') | 220 | const auditLogger = auditLoggerFactory('abuse') |
214 | 221 | ||
215 | const abuseAttributes = Object.assign({}, base, { flaggedAccountId: flaggedAccount.id }) | 222 | const abuseAttributes = Object.assign({}, base, { flaggedAccountId: flaggedAccount.id }) |
@@ -227,13 +234,15 @@ async function createAbuse (options: { | |||
227 | const abuseJSON = abuseInstance.toFormattedAdminJSON() | 234 | const abuseJSON = abuseInstance.toFormattedAdminJSON() |
228 | auditLogger.create(reporterAccount.Actor.getIdentifier(), new AbuseAuditView(abuseJSON)) | 235 | auditLogger.create(reporterAccount.Actor.getIdentifier(), new AbuseAuditView(abuseJSON)) |
229 | 236 | ||
230 | afterCommitIfTransaction(transaction, () => { | 237 | if (!skipNotification) { |
231 | Notifier.Instance.notifyOnNewAbuse({ | 238 | afterCommitIfTransaction(transaction, () => { |
232 | abuse: abuseJSON, | 239 | Notifier.Instance.notifyOnNewAbuse({ |
233 | abuseInstance, | 240 | abuse: abuseJSON, |
234 | reporter: reporterAccount.Actor.getIdentifier() | 241 | abuseInstance, |
242 | reporter: reporterAccount.Actor.getIdentifier() | ||
243 | }) | ||
235 | }) | 244 | }) |
236 | }) | 245 | } |
237 | 246 | ||
238 | logger.info('Abuse report %d created.', abuseInstance.id) | 247 | logger.info('Abuse report %d created.', abuseInstance.id) |
239 | 248 | ||
diff --git a/server/lib/notifier/shared/comment/comment-mention.ts b/server/lib/notifier/shared/comment/comment-mention.ts index 4f84d8dea..765cbaad9 100644 --- a/server/lib/notifier/shared/comment/comment-mention.ts +++ b/server/lib/notifier/shared/comment/comment-mention.ts | |||
@@ -47,8 +47,8 @@ export class CommentMention extends AbstractNotification <MCommentOwnerVideo, MU | |||
47 | 47 | ||
48 | const sourceAccounts = this.users.map(u => u.Account.id).concat([ this.serverAccountId ]) | 48 | const sourceAccounts = this.users.map(u => u.Account.id).concat([ this.serverAccountId ]) |
49 | 49 | ||
50 | this.accountMutedHash = await AccountBlocklistModel.isAccountMutedByMulti(sourceAccounts, this.payload.accountId) | 50 | this.accountMutedHash = await AccountBlocklistModel.isAccountMutedByAccounts(sourceAccounts, this.payload.accountId) |
51 | this.instanceMutedHash = await ServerBlocklistModel.isServerMutedByMulti(sourceAccounts, this.payload.Account.Actor.serverId) | 51 | this.instanceMutedHash = await ServerBlocklistModel.isServerMutedByAccounts(sourceAccounts, this.payload.Account.Actor.serverId) |
52 | } | 52 | } |
53 | 53 | ||
54 | log () { | 54 | log () { |
diff --git a/server/lib/plugins/plugin-manager.ts b/server/lib/plugins/plugin-manager.ts index d4d2a7edc..6c2f4764e 100644 --- a/server/lib/plugins/plugin-manager.ts +++ b/server/lib/plugins/plugin-manager.ts | |||
@@ -1,8 +1,8 @@ | |||
1 | import decache from 'decache' | ||
2 | import express from 'express' | 1 | import express from 'express' |
3 | import { createReadStream, createWriteStream } from 'fs' | 2 | import { createReadStream, createWriteStream } from 'fs' |
4 | import { ensureDir, outputFile, readJSON } from 'fs-extra' | 3 | import { ensureDir, outputFile, readJSON } from 'fs-extra' |
5 | import { basename, join } from 'path' | 4 | import { basename, join } from 'path' |
5 | import { decachePlugin } from '@server/helpers/decache' | ||
6 | import { MOAuthTokenUser, MUser } from '@server/types/models' | 6 | import { MOAuthTokenUser, MUser } from '@server/types/models' |
7 | import { getCompleteLocale } from '@shared/core-utils' | 7 | import { getCompleteLocale } from '@shared/core-utils' |
8 | import { ClientScript, PluginPackageJson, PluginTranslation, PluginTranslationPaths, RegisterServerHookOptions } from '@shared/models' | 8 | import { ClientScript, PluginPackageJson, PluginTranslation, PluginTranslationPaths, RegisterServerHookOptions } from '@shared/models' |
@@ -420,7 +420,7 @@ export class PluginManager implements ServerHook { | |||
420 | 420 | ||
421 | // Delete cache if needed | 421 | // Delete cache if needed |
422 | const modulePath = join(pluginPath, packageJSON.library) | 422 | const modulePath = join(pluginPath, packageJSON.library) |
423 | decache(modulePath) | 423 | decachePlugin(pluginPath, modulePath) |
424 | const library: PluginLibrary = require(modulePath) | 424 | const library: PluginLibrary = require(modulePath) |
425 | 425 | ||
426 | if (!isLibraryCodeValid(library)) { | 426 | if (!isLibraryCodeValid(library)) { |
diff --git a/server/lib/schedulers/remove-dangling-resumable-uploads-scheduler.ts b/server/lib/schedulers/remove-dangling-resumable-uploads-scheduler.ts index d6e561cad..61e93eafa 100644 --- a/server/lib/schedulers/remove-dangling-resumable-uploads-scheduler.ts +++ b/server/lib/schedulers/remove-dangling-resumable-uploads-scheduler.ts | |||
@@ -1,9 +1,7 @@ | |||
1 | import { map } from 'bluebird' | 1 | |
2 | import { readdir, remove, stat } from 'fs-extra' | ||
3 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | 2 | import { logger, loggerTagsFactory } from '@server/helpers/logger' |
4 | import { getResumableUploadPath } from '@server/helpers/upload' | ||
5 | import { SCHEDULER_INTERVALS_MS } from '@server/initializers/constants' | 3 | import { SCHEDULER_INTERVALS_MS } from '@server/initializers/constants' |
6 | import { METAFILE_EXTNAME } from '@uploadx/core' | 4 | import { uploadx } from '../uploadx' |
7 | import { AbstractScheduler } from './abstract-scheduler' | 5 | import { AbstractScheduler } from './abstract-scheduler' |
8 | 6 | ||
9 | const lTags = loggerTagsFactory('scheduler', 'resumable-upload', 'cleaner') | 7 | const lTags = loggerTagsFactory('scheduler', 'resumable-upload', 'cleaner') |
@@ -22,36 +20,17 @@ export class RemoveDanglingResumableUploadsScheduler extends AbstractScheduler { | |||
22 | } | 20 | } |
23 | 21 | ||
24 | protected async internalExecute () { | 22 | protected async internalExecute () { |
25 | const path = getResumableUploadPath() | 23 | logger.debug('Removing dangling resumable uploads', lTags()) |
26 | const files = await readdir(path) | ||
27 | |||
28 | const metafiles = files.filter(f => f.endsWith(METAFILE_EXTNAME)) | ||
29 | 24 | ||
30 | if (metafiles.length === 0) return | 25 | const now = new Date().getTime() |
31 | |||
32 | logger.debug('Reading resumable video upload folder %s with %d files', path, metafiles.length, lTags()) | ||
33 | 26 | ||
34 | try { | 27 | try { |
35 | await map(metafiles, metafile => { | 28 | // Remove files that were not updated since the last execution |
36 | return this.deleteIfOlderThan(metafile, this.lastExecutionTimeMs) | 29 | await uploadx.storage.purge(now - this.lastExecutionTimeMs) |
37 | }, { concurrency: 5 }) | ||
38 | } catch (error) { | 30 | } catch (error) { |
39 | logger.error('Failed to handle file during resumable video upload folder cleanup', { error, ...lTags() }) | 31 | logger.error('Failed to handle file during resumable video upload folder cleanup', { error, ...lTags() }) |
40 | } finally { | 32 | } finally { |
41 | this.lastExecutionTimeMs = new Date().getTime() | 33 | this.lastExecutionTimeMs = now |
42 | } | ||
43 | } | ||
44 | |||
45 | private async deleteIfOlderThan (metafile: string, olderThan: number) { | ||
46 | const metafilePath = getResumableUploadPath(metafile) | ||
47 | const statResult = await stat(metafilePath) | ||
48 | |||
49 | // Delete uploads that started since a long time | ||
50 | if (statResult.ctimeMs < olderThan) { | ||
51 | await remove(metafilePath) | ||
52 | |||
53 | const datafile = metafilePath.replace(new RegExp(`${METAFILE_EXTNAME}$`), '') | ||
54 | await remove(datafile) | ||
55 | } | 34 | } |
56 | } | 35 | } |
57 | 36 | ||
diff --git a/server/lib/server-config-manager.ts b/server/lib/server-config-manager.ts index bdf6492f9..6aa459f82 100644 --- a/server/lib/server-config-manager.ts +++ b/server/lib/server-config-manager.ts | |||
@@ -47,6 +47,11 @@ class ServerConfigManager { | |||
47 | miniature: { | 47 | miniature: { |
48 | preferAuthorDisplayName: CONFIG.CLIENT.VIDEOS.MINIATURE.PREFER_AUTHOR_DISPLAY_NAME | 48 | preferAuthorDisplayName: CONFIG.CLIENT.VIDEOS.MINIATURE.PREFER_AUTHOR_DISPLAY_NAME |
49 | } | 49 | } |
50 | }, | ||
51 | menu: { | ||
52 | login: { | ||
53 | redirectOnSingleExternalAuth: CONFIG.CLIENT.MENU.LOGIN.REDIRECT_ON_SINGLE_EXTERNAL_AUTH | ||
54 | } | ||
50 | } | 55 | } |
51 | }, | 56 | }, |
52 | 57 | ||
diff --git a/server/lib/uploadx.ts b/server/lib/uploadx.ts new file mode 100644 index 000000000..11b1044db --- /dev/null +++ b/server/lib/uploadx.ts | |||
@@ -0,0 +1,10 @@ | |||
1 | import express from 'express' | ||
2 | import { getResumableUploadPath } from '@server/helpers/upload' | ||
3 | import { Uploadx } from '@uploadx/core' | ||
4 | |||
5 | const uploadx = new Uploadx({ directory: getResumableUploadPath() }) | ||
6 | uploadx.getUserId = (_, res: express.Response) => res.locals.oauth?.token.user.id | ||
7 | |||
8 | export { | ||
9 | uploadx | ||
10 | } | ||
diff --git a/server/middlewares/error.ts b/server/middlewares/error.ts index 6c52ce7bd..34c87a26d 100644 --- a/server/middlewares/error.ts +++ b/server/middlewares/error.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { ProblemDocument, ProblemDocumentExtension } from 'http-problem-details' | 2 | import { ProblemDocument, ProblemDocumentExtension } from 'http-problem-details' |
3 | import { logger } from '@server/helpers/logger' | ||
3 | import { HttpStatusCode } from '@shared/models' | 4 | import { HttpStatusCode } from '@shared/models' |
4 | 5 | ||
5 | function apiFailMiddleware (req: express.Request, res: express.Response, next: express.NextFunction) { | 6 | function apiFailMiddleware (req: express.Request, res: express.Response, next: express.NextFunction) { |
@@ -18,7 +19,8 @@ function apiFailMiddleware (req: express.Request, res: express.Response, next: e | |||
18 | 19 | ||
19 | res.status(status) | 20 | res.status(status) |
20 | res.setHeader('Content-Type', 'application/problem+json') | 21 | res.setHeader('Content-Type', 'application/problem+json') |
21 | res.json(new ProblemDocument({ | 22 | |
23 | const json = new ProblemDocument({ | ||
22 | status, | 24 | status, |
23 | title, | 25 | title, |
24 | instance, | 26 | instance, |
@@ -28,7 +30,11 @@ function apiFailMiddleware (req: express.Request, res: express.Response, next: e | |||
28 | type: type | 30 | type: type |
29 | ? `https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/${type}` | 31 | ? `https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/${type}` |
30 | : undefined | 32 | : undefined |
31 | }, extension)) | 33 | }, extension) |
34 | |||
35 | logger.debug('Bad HTTP request.', { json }) | ||
36 | |||
37 | res.json(json) | ||
32 | } | 38 | } |
33 | 39 | ||
34 | if (next) next() | 40 | if (next) next() |
diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.ts index b7749e204..12980ced4 100644 --- a/server/middlewares/validators/blocklist.ts +++ b/server/middlewares/validators/blocklist.ts | |||
@@ -1,8 +1,10 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { body, param } from 'express-validator' | 2 | import { body, param, query } from 'express-validator' |
3 | import { areValidActorHandles } from '@server/helpers/custom-validators/activitypub/actor' | ||
4 | import { toArray } from '@server/helpers/custom-validators/misc' | ||
3 | import { getServerActor } from '@server/models/application/application' | 5 | import { getServerActor } from '@server/models/application/application' |
4 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' | 6 | import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' |
5 | import { isHostValid } from '../../helpers/custom-validators/servers' | 7 | import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' |
6 | import { logger } from '../../helpers/logger' | 8 | import { logger } from '../../helpers/logger' |
7 | import { WEBSERVER } from '../../initializers/constants' | 9 | import { WEBSERVER } from '../../initializers/constants' |
8 | import { AccountBlocklistModel } from '../../models/account/account-blocklist' | 10 | import { AccountBlocklistModel } from '../../models/account/account-blocklist' |
@@ -123,6 +125,26 @@ const unblockServerByServerValidator = [ | |||
123 | } | 125 | } |
124 | ] | 126 | ] |
125 | 127 | ||
128 | const blocklistStatusValidator = [ | ||
129 | query('hosts') | ||
130 | .optional() | ||
131 | .customSanitizer(toArray) | ||
132 | .custom(isEachUniqueHostValid).withMessage('Should have a valid hosts array'), | ||
133 | |||
134 | query('accounts') | ||
135 | .optional() | ||
136 | .customSanitizer(toArray) | ||
137 | .custom(areValidActorHandles).withMessage('Should have a valid accounts array'), | ||
138 | |||
139 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
140 | logger.debug('Checking blocklistStatusValidator parameters', { query: req.query }) | ||
141 | |||
142 | if (areValidationErrors(req, res)) return | ||
143 | |||
144 | return next() | ||
145 | } | ||
146 | ] | ||
147 | |||
126 | // --------------------------------------------------------------------------- | 148 | // --------------------------------------------------------------------------- |
127 | 149 | ||
128 | export { | 150 | export { |
@@ -131,7 +153,8 @@ export { | |||
131 | unblockAccountByAccountValidator, | 153 | unblockAccountByAccountValidator, |
132 | unblockServerByAccountValidator, | 154 | unblockServerByAccountValidator, |
133 | unblockAccountByServerValidator, | 155 | unblockAccountByServerValidator, |
134 | unblockServerByServerValidator | 156 | unblockServerByServerValidator, |
157 | blocklistStatusValidator | ||
135 | } | 158 | } |
136 | 159 | ||
137 | // --------------------------------------------------------------------------- | 160 | // --------------------------------------------------------------------------- |
diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.ts index 21171af23..c1e9ebefb 100644 --- a/server/middlewares/validators/plugins.ts +++ b/server/middlewares/validators/plugins.ts | |||
@@ -116,6 +116,9 @@ const installOrUpdatePluginValidator = [ | |||
116 | body('npmName') | 116 | body('npmName') |
117 | .optional() | 117 | .optional() |
118 | .custom(isNpmPluginNameValid).withMessage('Should have a valid npm name'), | 118 | .custom(isNpmPluginNameValid).withMessage('Should have a valid npm name'), |
119 | body('pluginVersion') | ||
120 | .optional() | ||
121 | .custom(isPluginVersionValid).withMessage('Should have a valid plugin version'), | ||
119 | body('path') | 122 | body('path') |
120 | .optional() | 123 | .optional() |
121 | .custom(isSafePath).withMessage('Should have a valid safe path'), | 124 | .custom(isSafePath).withMessage('Should have a valid safe path'), |
@@ -129,6 +132,9 @@ const installOrUpdatePluginValidator = [ | |||
129 | if (!body.path && !body.npmName) { | 132 | if (!body.path && !body.npmName) { |
130 | return res.fail({ message: 'Should have either a npmName or a path' }) | 133 | return res.fail({ message: 'Should have either a npmName or a path' }) |
131 | } | 134 | } |
135 | if (body.pluginVersion && !body.npmName) { | ||
136 | return res.fail({ message: 'Should have a npmName when specifying a pluginVersion' }) | ||
137 | } | ||
132 | 138 | ||
133 | return next() | 139 | return next() |
134 | } | 140 | } |
diff --git a/server/models/account/account-blocklist.ts b/server/models/account/account-blocklist.ts index b2375b006..21983428a 100644 --- a/server/models/account/account-blocklist.ts +++ b/server/models/account/account-blocklist.ts | |||
@@ -1,11 +1,12 @@ | |||
1 | import { Op } from 'sequelize' | 1 | import { Op, QueryTypes } from 'sequelize' |
2 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { handlesToNameAndHost } from '@server/helpers/actors' | ||
3 | import { MAccountBlocklist, MAccountBlocklistAccounts, MAccountBlocklistFormattable } from '@server/types/models' | 4 | import { MAccountBlocklist, MAccountBlocklistAccounts, MAccountBlocklistFormattable } from '@server/types/models' |
4 | import { AttributesOnly } from '@shared/core-utils' | 5 | import { AttributesOnly } from '@shared/core-utils' |
5 | import { AccountBlock } from '../../../shared/models' | 6 | import { AccountBlock } from '../../../shared/models' |
6 | import { ActorModel } from '../actor/actor' | 7 | import { ActorModel } from '../actor/actor' |
7 | import { ServerModel } from '../server/server' | 8 | import { ServerModel } from '../server/server' |
8 | import { getSort, searchAttribute } from '../utils' | 9 | import { createSafeIn, getSort, searchAttribute } from '../utils' |
9 | import { AccountModel } from './account' | 10 | import { AccountModel } from './account' |
10 | 11 | ||
11 | enum ScopeNames { | 12 | enum ScopeNames { |
@@ -77,7 +78,7 @@ export class AccountBlocklistModel extends Model<Partial<AttributesOnly<AccountB | |||
77 | }) | 78 | }) |
78 | BlockedAccount: AccountModel | 79 | BlockedAccount: AccountModel |
79 | 80 | ||
80 | static isAccountMutedByMulti (accountIds: number[], targetAccountId: number) { | 81 | static isAccountMutedByAccounts (accountIds: number[], targetAccountId: number) { |
81 | const query = { | 82 | const query = { |
82 | attributes: [ 'accountId', 'id' ], | 83 | attributes: [ 'accountId', 'id' ], |
83 | where: { | 84 | where: { |
@@ -187,6 +188,39 @@ export class AccountBlocklistModel extends Model<Partial<AttributesOnly<AccountB | |||
187 | .then(entries => entries.map(e => `${e.BlockedAccount.Actor.preferredUsername}@${e.BlockedAccount.Actor.Server.host}`)) | 188 | .then(entries => entries.map(e => `${e.BlockedAccount.Actor.preferredUsername}@${e.BlockedAccount.Actor.Server.host}`)) |
188 | } | 189 | } |
189 | 190 | ||
191 | static getBlockStatus (byAccountIds: number[], handles: string[]): Promise<{ name: string, host: string, accountId: number }[]> { | ||
192 | const sanitizedHandles = handlesToNameAndHost(handles) | ||
193 | |||
194 | const localHandles = sanitizedHandles.filter(h => !h.host) | ||
195 | .map(h => h.name) | ||
196 | |||
197 | const remoteHandles = sanitizedHandles.filter(h => !!h.host) | ||
198 | .map(h => ([ h.name, h.host ])) | ||
199 | |||
200 | const handlesWhere: string[] = [] | ||
201 | |||
202 | if (localHandles.length !== 0) { | ||
203 | handlesWhere.push(`("actor"."preferredUsername" IN (:localHandles) AND "server"."id" IS NULL)`) | ||
204 | } | ||
205 | |||
206 | if (remoteHandles.length !== 0) { | ||
207 | handlesWhere.push(`(("actor"."preferredUsername", "server"."host") IN (:remoteHandles))`) | ||
208 | } | ||
209 | |||
210 | const rawQuery = `SELECT "accountBlocklist"."accountId", "actor"."preferredUsername" AS "name", "server"."host" ` + | ||
211 | `FROM "accountBlocklist" ` + | ||
212 | `INNER JOIN "account" ON "account"."id" = "accountBlocklist"."targetAccountId" ` + | ||
213 | `INNER JOIN "actor" ON "actor"."id" = "account"."actorId" ` + | ||
214 | `LEFT JOIN "server" ON "server"."id" = "actor"."serverId" ` + | ||
215 | `WHERE "accountBlocklist"."accountId" IN (${createSafeIn(AccountBlocklistModel.sequelize, byAccountIds)}) ` + | ||
216 | `AND (${handlesWhere.join(' OR ')})` | ||
217 | |||
218 | return AccountBlocklistModel.sequelize.query(rawQuery, { | ||
219 | type: QueryTypes.SELECT as QueryTypes.SELECT, | ||
220 | replacements: { byAccountIds, localHandles, remoteHandles } | ||
221 | }) | ||
222 | } | ||
223 | |||
190 | toFormattedJSON (this: MAccountBlocklistFormattable): AccountBlock { | 224 | toFormattedJSON (this: MAccountBlocklistFormattable): AccountBlock { |
191 | return { | 225 | return { |
192 | byAccount: this.ByAccount.toFormattedJSON(), | 226 | byAccount: this.ByAccount.toFormattedJSON(), |
diff --git a/server/models/server/server-blocklist.ts b/server/models/server/server-blocklist.ts index b3579d589..092998db3 100644 --- a/server/models/server/server-blocklist.ts +++ b/server/models/server/server-blocklist.ts | |||
@@ -1,10 +1,10 @@ | |||
1 | import { Op } from 'sequelize' | 1 | import { Op, QueryTypes } from 'sequelize' |
2 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { MServerBlocklist, MServerBlocklistAccountServer, MServerBlocklistFormattable } from '@server/types/models' | 3 | import { MServerBlocklist, MServerBlocklistAccountServer, MServerBlocklistFormattable } from '@server/types/models' |
4 | import { AttributesOnly } from '@shared/core-utils' | 4 | import { AttributesOnly } from '@shared/core-utils' |
5 | import { ServerBlock } from '@shared/models' | 5 | import { ServerBlock } from '@shared/models' |
6 | import { AccountModel } from '../account/account' | 6 | import { AccountModel } from '../account/account' |
7 | import { getSort, searchAttribute } from '../utils' | 7 | import { createSafeIn, getSort, searchAttribute } from '../utils' |
8 | import { ServerModel } from './server' | 8 | import { ServerModel } from './server' |
9 | 9 | ||
10 | enum ScopeNames { | 10 | enum ScopeNames { |
@@ -76,7 +76,7 @@ export class ServerBlocklistModel extends Model<Partial<AttributesOnly<ServerBlo | |||
76 | }) | 76 | }) |
77 | BlockedServer: ServerModel | 77 | BlockedServer: ServerModel |
78 | 78 | ||
79 | static isServerMutedByMulti (accountIds: number[], targetServerId: number) { | 79 | static isServerMutedByAccounts (accountIds: number[], targetServerId: number) { |
80 | const query = { | 80 | const query = { |
81 | attributes: [ 'accountId', 'id' ], | 81 | attributes: [ 'accountId', 'id' ], |
82 | where: { | 82 | where: { |
@@ -141,6 +141,19 @@ export class ServerBlocklistModel extends Model<Partial<AttributesOnly<ServerBlo | |||
141 | .then(entries => entries.map(e => e.BlockedServer.host)) | 141 | .then(entries => entries.map(e => e.BlockedServer.host)) |
142 | } | 142 | } |
143 | 143 | ||
144 | static getBlockStatus (byAccountIds: number[], hosts: string[]): Promise<{ host: string, accountId: number }[]> { | ||
145 | const rawQuery = `SELECT "server"."host", "serverBlocklist"."accountId" ` + | ||
146 | `FROM "serverBlocklist" ` + | ||
147 | `INNER JOIN "server" ON "server"."id" = "serverBlocklist"."targetServerId" ` + | ||
148 | `WHERE "server"."host" IN (:hosts) ` + | ||
149 | `AND "serverBlocklist"."accountId" IN (${createSafeIn(ServerBlocklistModel.sequelize, byAccountIds)})` | ||
150 | |||
151 | return ServerBlocklistModel.sequelize.query(rawQuery, { | ||
152 | type: QueryTypes.SELECT as QueryTypes.SELECT, | ||
153 | replacements: { hosts } | ||
154 | }) | ||
155 | } | ||
156 | |||
144 | static listForApi (parameters: { | 157 | static listForApi (parameters: { |
145 | start: number | 158 | start: number |
146 | count: number | 159 | count: number |
diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts index 82c832188..a87b2bcae 100644 --- a/server/models/video/video-playlist-element.ts +++ b/server/models/video/video-playlist-element.ts | |||
@@ -276,7 +276,7 @@ export class VideoPlaylistElementModel extends Model<Partial<AttributesOnly<Vide | |||
276 | } | 276 | } |
277 | 277 | ||
278 | const positionQuery = Sequelize.literal(`${newPosition} + "position" - ${firstPosition}`) | 278 | const positionQuery = Sequelize.literal(`${newPosition} + "position" - ${firstPosition}`) |
279 | return VideoPlaylistElementModel.update({ position: positionQuery as any }, query) | 279 | return VideoPlaylistElementModel.update({ position: positionQuery }, query) |
280 | } | 280 | } |
281 | 281 | ||
282 | static increasePositionOf ( | 282 | static increasePositionOf ( |
diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts index 4643c5452..e36852cad 100644 --- a/server/models/video/video-streaming-playlist.ts +++ b/server/models/video/video-streaming-playlist.ts | |||
@@ -198,6 +198,15 @@ export class VideoStreamingPlaylistModel extends Model<Partial<AttributesOnly<Vi | |||
198 | return Object.assign(playlist, { videoId: video.id, Video: video }) | 198 | return Object.assign(playlist, { videoId: video.id, Video: video }) |
199 | } | 199 | } |
200 | 200 | ||
201 | static doesOwnedHLSPlaylistExist (videoUUID: string) { | ||
202 | const query = `SELECT 1 FROM "videoStreamingPlaylist" ` + | ||
203 | `INNER JOIN "video" ON "video"."id" = "videoStreamingPlaylist"."videoId" ` + | ||
204 | `AND "video"."remote" IS FALSE AND "video"."uuid" = $videoUUID ` + | ||
205 | `AND "storage" = ${VideoStorage.FILE_SYSTEM} LIMIT 1` | ||
206 | |||
207 | return doesExist(query, { videoUUID }) | ||
208 | } | ||
209 | |||
201 | assignP2PMediaLoaderInfoHashes (video: MVideo, files: unknown[]) { | 210 | assignP2PMediaLoaderInfoHashes (video: MVideo, files: unknown[]) { |
202 | const masterPlaylistUrl = this.getMasterPlaylistUrl(video) | 211 | const masterPlaylistUrl = this.getMasterPlaylistUrl(video) |
203 | 212 | ||
diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts index 7d5fae5cf..f72a892e2 100644 --- a/server/tests/api/check-params/blocklist.ts +++ b/server/tests/api/check-params/blocklist.ts | |||
@@ -481,6 +481,78 @@ describe('Test blocklist API validators', function () { | |||
481 | }) | 481 | }) |
482 | }) | 482 | }) |
483 | 483 | ||
484 | describe('When getting blocklist status', function () { | ||
485 | const path = '/api/v1/blocklist/status' | ||
486 | |||
487 | it('Should fail with a bad token', async function () { | ||
488 | await makeGetRequest({ | ||
489 | url: server.url, | ||
490 | path, | ||
491 | token: 'false', | ||
492 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | ||
493 | }) | ||
494 | }) | ||
495 | |||
496 | it('Should fail with a bad accounts field', async function () { | ||
497 | await makeGetRequest({ | ||
498 | url: server.url, | ||
499 | path, | ||
500 | query: { | ||
501 | accounts: 1 | ||
502 | }, | ||
503 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
504 | }) | ||
505 | |||
506 | await makeGetRequest({ | ||
507 | url: server.url, | ||
508 | path, | ||
509 | query: { | ||
510 | accounts: [ 1 ] | ||
511 | }, | ||
512 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
513 | }) | ||
514 | }) | ||
515 | |||
516 | it('Should fail with a bad hosts field', async function () { | ||
517 | await makeGetRequest({ | ||
518 | url: server.url, | ||
519 | path, | ||
520 | query: { | ||
521 | hosts: 1 | ||
522 | }, | ||
523 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
524 | }) | ||
525 | |||
526 | await makeGetRequest({ | ||
527 | url: server.url, | ||
528 | path, | ||
529 | query: { | ||
530 | hosts: [ 1 ] | ||
531 | }, | ||
532 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
533 | }) | ||
534 | }) | ||
535 | |||
536 | it('Should succeed with the correct parameters', async function () { | ||
537 | await makeGetRequest({ | ||
538 | url: server.url, | ||
539 | path, | ||
540 | query: {}, | ||
541 | expectedStatus: HttpStatusCode.OK_200 | ||
542 | }) | ||
543 | |||
544 | await makeGetRequest({ | ||
545 | url: server.url, | ||
546 | path, | ||
547 | query: { | ||
548 | hosts: [ 'example.com' ], | ||
549 | accounts: [ 'john@example.com' ] | ||
550 | }, | ||
551 | expectedStatus: HttpStatusCode.OK_200 | ||
552 | }) | ||
553 | }) | ||
554 | }) | ||
555 | |||
484 | after(async function () { | 556 | after(async function () { |
485 | await cleanupTests(servers) | 557 | await cleanupTests(servers) |
486 | }) | 558 | }) |
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index d0cd7722b..a6e87730a 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts | |||
@@ -54,6 +54,18 @@ describe('Test config API validators', function () { | |||
54 | whitelisted: true | 54 | whitelisted: true |
55 | } | 55 | } |
56 | }, | 56 | }, |
57 | client: { | ||
58 | videos: { | ||
59 | miniature: { | ||
60 | preferAuthorDisplayName: false | ||
61 | } | ||
62 | }, | ||
63 | menu: { | ||
64 | login: { | ||
65 | redirectOnSingleExternalAuth: false | ||
66 | } | ||
67 | } | ||
68 | }, | ||
57 | cache: { | 69 | cache: { |
58 | previews: { | 70 | previews: { |
59 | size: 2 | 71 | size: 2 |
diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts index 33f84ecbc..2c436376c 100644 --- a/server/tests/api/check-params/plugins.ts +++ b/server/tests/api/check-params/plugins.ts | |||
@@ -30,7 +30,7 @@ describe('Test server plugins API validators', function () { | |||
30 | // --------------------------------------------------------------- | 30 | // --------------------------------------------------------------- |
31 | 31 | ||
32 | before(async function () { | 32 | before(async function () { |
33 | this.timeout(30000) | 33 | this.timeout(60000) |
34 | 34 | ||
35 | server = await createSingleServer(1) | 35 | server = await createSingleServer(1) |
36 | 36 | ||
diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts index 089af8b15..b3fd8ecac 100644 --- a/server/tests/api/moderation/blocklist.ts +++ b/server/tests/api/moderation/blocklist.ts | |||
@@ -254,6 +254,45 @@ describe('Test blocklist', function () { | |||
254 | } | 254 | } |
255 | }) | 255 | }) |
256 | 256 | ||
257 | it('Should get blocked status', async function () { | ||
258 | const remoteHandle = 'user2@' + servers[1].host | ||
259 | const localHandle = 'user1@' + servers[0].host | ||
260 | const unknownHandle = 'user5@' + servers[0].host | ||
261 | |||
262 | { | ||
263 | const status = await command.getStatus({ accounts: [ remoteHandle ] }) | ||
264 | expect(Object.keys(status.accounts)).to.have.lengthOf(1) | ||
265 | expect(status.accounts[remoteHandle].blockedByUser).to.be.false | ||
266 | expect(status.accounts[remoteHandle].blockedByServer).to.be.false | ||
267 | |||
268 | expect(Object.keys(status.hosts)).to.have.lengthOf(0) | ||
269 | } | ||
270 | |||
271 | { | ||
272 | const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ remoteHandle ] }) | ||
273 | expect(Object.keys(status.accounts)).to.have.lengthOf(1) | ||
274 | expect(status.accounts[remoteHandle].blockedByUser).to.be.true | ||
275 | expect(status.accounts[remoteHandle].blockedByServer).to.be.false | ||
276 | |||
277 | expect(Object.keys(status.hosts)).to.have.lengthOf(0) | ||
278 | } | ||
279 | |||
280 | { | ||
281 | const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ localHandle, remoteHandle, unknownHandle ] }) | ||
282 | expect(Object.keys(status.accounts)).to.have.lengthOf(3) | ||
283 | |||
284 | for (const handle of [ localHandle, remoteHandle ]) { | ||
285 | expect(status.accounts[handle].blockedByUser).to.be.true | ||
286 | expect(status.accounts[handle].blockedByServer).to.be.false | ||
287 | } | ||
288 | |||
289 | expect(status.accounts[unknownHandle].blockedByUser).to.be.false | ||
290 | expect(status.accounts[unknownHandle].blockedByServer).to.be.false | ||
291 | |||
292 | expect(Object.keys(status.hosts)).to.have.lengthOf(0) | ||
293 | } | ||
294 | }) | ||
295 | |||
257 | it('Should not allow a remote blocked user to comment my videos', async function () { | 296 | it('Should not allow a remote blocked user to comment my videos', async function () { |
258 | this.timeout(60000) | 297 | this.timeout(60000) |
259 | 298 | ||
@@ -434,6 +473,35 @@ describe('Test blocklist', function () { | |||
434 | expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) | 473 | expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) |
435 | }) | 474 | }) |
436 | 475 | ||
476 | it('Should get blocklist status', async function () { | ||
477 | const blockedServer = servers[1].host | ||
478 | const notBlockedServer = 'example.com' | ||
479 | |||
480 | { | ||
481 | const status = await command.getStatus({ hosts: [ blockedServer, notBlockedServer ] }) | ||
482 | expect(Object.keys(status.accounts)).to.have.lengthOf(0) | ||
483 | |||
484 | expect(Object.keys(status.hosts)).to.have.lengthOf(2) | ||
485 | expect(status.hosts[blockedServer].blockedByUser).to.be.false | ||
486 | expect(status.hosts[blockedServer].blockedByServer).to.be.false | ||
487 | |||
488 | expect(status.hosts[notBlockedServer].blockedByUser).to.be.false | ||
489 | expect(status.hosts[notBlockedServer].blockedByServer).to.be.false | ||
490 | } | ||
491 | |||
492 | { | ||
493 | const status = await command.getStatus({ token: servers[0].accessToken, hosts: [ blockedServer, notBlockedServer ] }) | ||
494 | expect(Object.keys(status.accounts)).to.have.lengthOf(0) | ||
495 | |||
496 | expect(Object.keys(status.hosts)).to.have.lengthOf(2) | ||
497 | expect(status.hosts[blockedServer].blockedByUser).to.be.true | ||
498 | expect(status.hosts[blockedServer].blockedByServer).to.be.false | ||
499 | |||
500 | expect(status.hosts[notBlockedServer].blockedByUser).to.be.false | ||
501 | expect(status.hosts[notBlockedServer].blockedByServer).to.be.false | ||
502 | } | ||
503 | }) | ||
504 | |||
437 | it('Should unblock the remote server', async function () { | 505 | it('Should unblock the remote server', async function () { |
438 | await command.removeFromMyBlocklist({ server: 'localhost:' + servers[1].port }) | 506 | await command.removeFromMyBlocklist({ server: 'localhost:' + servers[1].port }) |
439 | }) | 507 | }) |
@@ -575,6 +643,27 @@ describe('Test blocklist', function () { | |||
575 | } | 643 | } |
576 | }) | 644 | }) |
577 | 645 | ||
646 | it('Should get blocked status', async function () { | ||
647 | const remoteHandle = 'user2@' + servers[1].host | ||
648 | const localHandle = 'user1@' + servers[0].host | ||
649 | const unknownHandle = 'user5@' + servers[0].host | ||
650 | |||
651 | for (const token of [ undefined, servers[0].accessToken ]) { | ||
652 | const status = await command.getStatus({ token, accounts: [ localHandle, remoteHandle, unknownHandle ] }) | ||
653 | expect(Object.keys(status.accounts)).to.have.lengthOf(3) | ||
654 | |||
655 | for (const handle of [ localHandle, remoteHandle ]) { | ||
656 | expect(status.accounts[handle].blockedByUser).to.be.false | ||
657 | expect(status.accounts[handle].blockedByServer).to.be.true | ||
658 | } | ||
659 | |||
660 | expect(status.accounts[unknownHandle].blockedByUser).to.be.false | ||
661 | expect(status.accounts[unknownHandle].blockedByServer).to.be.false | ||
662 | |||
663 | expect(Object.keys(status.hosts)).to.have.lengthOf(0) | ||
664 | } | ||
665 | }) | ||
666 | |||
578 | it('Should unblock the remote account', async function () { | 667 | it('Should unblock the remote account', async function () { |
579 | await command.removeFromServerBlocklist({ account: 'user2@localhost:' + servers[1].port }) | 668 | await command.removeFromServerBlocklist({ account: 'user2@localhost:' + servers[1].port }) |
580 | }) | 669 | }) |
@@ -620,6 +709,7 @@ describe('Test blocklist', function () { | |||
620 | }) | 709 | }) |
621 | 710 | ||
622 | describe('When managing server blocklist', function () { | 711 | describe('When managing server blocklist', function () { |
712 | |||
623 | it('Should list all videos', async function () { | 713 | it('Should list all videos', async function () { |
624 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | 714 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { |
625 | await checkAllVideos(servers[0], token) | 715 | await checkAllVideos(servers[0], token) |
@@ -713,6 +803,23 @@ describe('Test blocklist', function () { | |||
713 | expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) | 803 | expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) |
714 | }) | 804 | }) |
715 | 805 | ||
806 | it('Should get blocklist status', async function () { | ||
807 | const blockedServer = servers[1].host | ||
808 | const notBlockedServer = 'example.com' | ||
809 | |||
810 | for (const token of [ undefined, servers[0].accessToken ]) { | ||
811 | const status = await command.getStatus({ token, hosts: [ blockedServer, notBlockedServer ] }) | ||
812 | expect(Object.keys(status.accounts)).to.have.lengthOf(0) | ||
813 | |||
814 | expect(Object.keys(status.hosts)).to.have.lengthOf(2) | ||
815 | expect(status.hosts[blockedServer].blockedByUser).to.be.false | ||
816 | expect(status.hosts[blockedServer].blockedByServer).to.be.true | ||
817 | |||
818 | expect(status.hosts[notBlockedServer].blockedByUser).to.be.false | ||
819 | expect(status.hosts[notBlockedServer].blockedByServer).to.be.false | ||
820 | } | ||
821 | }) | ||
822 | |||
716 | it('Should unblock the remote server', async function () { | 823 | it('Should unblock the remote server', async function () { |
717 | await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port }) | 824 | await command.removeFromServerBlocklist({ server: 'localhost:' + servers[1].port }) |
718 | }) | 825 | }) |
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index f806fed31..81ce8061b 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts | |||
@@ -24,11 +24,13 @@ import { | |||
24 | wait, | 24 | wait, |
25 | waitJobs | 25 | waitJobs |
26 | } from '@shared/extra-utils' | 26 | } from '@shared/extra-utils' |
27 | import { AbuseState, CustomConfig, UserNotification, VideoPrivacy } from '@shared/models' | 27 | import { AbuseState, CustomConfig, UserNotification, UserRole, VideoPrivacy } from '@shared/models' |
28 | 28 | ||
29 | describe('Test moderation notifications', function () { | 29 | describe('Test moderation notifications', function () { |
30 | let servers: PeerTubeServer[] = [] | 30 | let servers: PeerTubeServer[] = [] |
31 | let userAccessToken: string | 31 | let userToken1: string |
32 | let userToken2: string | ||
33 | |||
32 | let userNotifications: UserNotification[] = [] | 34 | let userNotifications: UserNotification[] = [] |
33 | let adminNotifications: UserNotification[] = [] | 35 | let adminNotifications: UserNotification[] = [] |
34 | let adminNotificationsServer2: UserNotification[] = [] | 36 | let adminNotificationsServer2: UserNotification[] = [] |
@@ -39,11 +41,13 @@ describe('Test moderation notifications', function () { | |||
39 | 41 | ||
40 | const res = await prepareNotificationsTest(3) | 42 | const res = await prepareNotificationsTest(3) |
41 | emails = res.emails | 43 | emails = res.emails |
42 | userAccessToken = res.userAccessToken | 44 | userToken1 = res.userAccessToken |
43 | servers = res.servers | 45 | servers = res.servers |
44 | userNotifications = res.userNotifications | 46 | userNotifications = res.userNotifications |
45 | adminNotifications = res.adminNotifications | 47 | adminNotifications = res.adminNotifications |
46 | adminNotificationsServer2 = res.adminNotificationsServer2 | 48 | adminNotificationsServer2 = res.adminNotificationsServer2 |
49 | |||
50 | userToken2 = await servers[1].users.generateUserAndToken('user2', UserRole.USER) | ||
47 | }) | 51 | }) |
48 | 52 | ||
49 | describe('Abuse for moderators notification', function () { | 53 | describe('Abuse for moderators notification', function () { |
@@ -58,15 +62,27 @@ describe('Test moderation notifications', function () { | |||
58 | } | 62 | } |
59 | }) | 63 | }) |
60 | 64 | ||
61 | it('Should send a notification to moderators on local video abuse', async function () { | 65 | it('Should not send a notification to moderators on local abuse reported by an admin', async function () { |
62 | this.timeout(20000) | 66 | this.timeout(20000) |
63 | 67 | ||
64 | const name = 'video for abuse ' + buildUUID() | 68 | const name = 'video for abuse ' + buildUUID() |
65 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) | 69 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
66 | 70 | ||
67 | await servers[0].abuses.report({ videoId: video.id, reason: 'super reason' }) | 71 | await servers[0].abuses.report({ videoId: video.id, reason: 'super reason' }) |
68 | 72 | ||
69 | await waitJobs(servers) | 73 | await waitJobs(servers) |
74 | await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'absence' }) | ||
75 | }) | ||
76 | |||
77 | it('Should send a notification to moderators on local video abuse', async function () { | ||
78 | this.timeout(20000) | ||
79 | |||
80 | const name = 'video for abuse ' + buildUUID() | ||
81 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) | ||
82 | |||
83 | await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason' }) | ||
84 | |||
85 | await waitJobs(servers) | ||
70 | await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) | 86 | await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
71 | }) | 87 | }) |
72 | 88 | ||
@@ -74,12 +90,12 @@ describe('Test moderation notifications', function () { | |||
74 | this.timeout(20000) | 90 | this.timeout(20000) |
75 | 91 | ||
76 | const name = 'video for abuse ' + buildUUID() | 92 | const name = 'video for abuse ' + buildUUID() |
77 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) | 93 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
78 | 94 | ||
79 | await waitJobs(servers) | 95 | await waitJobs(servers) |
80 | 96 | ||
81 | const videoId = await servers[1].videos.getId({ uuid: video.uuid }) | 97 | const videoId = await servers[1].videos.getId({ uuid: video.uuid }) |
82 | await servers[1].abuses.report({ videoId, reason: 'super reason' }) | 98 | await servers[1].abuses.report({ token: userToken2, videoId, reason: 'super reason' }) |
83 | 99 | ||
84 | await waitJobs(servers) | 100 | await waitJobs(servers) |
85 | await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) | 101 | await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
@@ -89,16 +105,16 @@ describe('Test moderation notifications', function () { | |||
89 | this.timeout(20000) | 105 | this.timeout(20000) |
90 | 106 | ||
91 | const name = 'video for abuse ' + buildUUID() | 107 | const name = 'video for abuse ' + buildUUID() |
92 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) | 108 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
93 | const comment = await servers[0].comments.createThread({ | 109 | const comment = await servers[0].comments.createThread({ |
94 | token: userAccessToken, | 110 | token: userToken1, |
95 | videoId: video.id, | 111 | videoId: video.id, |
96 | text: 'comment abuse ' + buildUUID() | 112 | text: 'comment abuse ' + buildUUID() |
97 | }) | 113 | }) |
98 | 114 | ||
99 | await waitJobs(servers) | 115 | await waitJobs(servers) |
100 | 116 | ||
101 | await servers[0].abuses.report({ commentId: comment.id, reason: 'super reason' }) | 117 | await servers[0].abuses.report({ token: userToken1, commentId: comment.id, reason: 'super reason' }) |
102 | 118 | ||
103 | await waitJobs(servers) | 119 | await waitJobs(servers) |
104 | await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) | 120 | await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
@@ -108,10 +124,10 @@ describe('Test moderation notifications', function () { | |||
108 | this.timeout(20000) | 124 | this.timeout(20000) |
109 | 125 | ||
110 | const name = 'video for abuse ' + buildUUID() | 126 | const name = 'video for abuse ' + buildUUID() |
111 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) | 127 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
112 | 128 | ||
113 | await servers[0].comments.createThread({ | 129 | await servers[0].comments.createThread({ |
114 | token: userAccessToken, | 130 | token: userToken1, |
115 | videoId: video.id, | 131 | videoId: video.id, |
116 | text: 'comment abuse ' + buildUUID() | 132 | text: 'comment abuse ' + buildUUID() |
117 | }) | 133 | }) |
@@ -120,7 +136,7 @@ describe('Test moderation notifications', function () { | |||
120 | 136 | ||
121 | const { data } = await servers[1].comments.listThreads({ videoId: video.uuid }) | 137 | const { data } = await servers[1].comments.listThreads({ videoId: video.uuid }) |
122 | const commentId = data[0].id | 138 | const commentId = data[0].id |
123 | await servers[1].abuses.report({ commentId, reason: 'super reason' }) | 139 | await servers[1].abuses.report({ token: userToken2, commentId, reason: 'super reason' }) |
124 | 140 | ||
125 | await waitJobs(servers) | 141 | await waitJobs(servers) |
126 | await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) | 142 | await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) |
@@ -133,7 +149,7 @@ describe('Test moderation notifications', function () { | |||
133 | const { account } = await servers[0].users.create({ username, password: 'donald' }) | 149 | const { account } = await servers[0].users.create({ username, password: 'donald' }) |
134 | const accountId = account.id | 150 | const accountId = account.id |
135 | 151 | ||
136 | await servers[0].abuses.report({ accountId, reason: 'super reason' }) | 152 | await servers[0].abuses.report({ token: userToken1, accountId, reason: 'super reason' }) |
137 | 153 | ||
138 | await waitJobs(servers) | 154 | await waitJobs(servers) |
139 | await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) | 155 | await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) |
@@ -149,7 +165,7 @@ describe('Test moderation notifications', function () { | |||
149 | await waitJobs(servers) | 165 | await waitJobs(servers) |
150 | 166 | ||
151 | const account = await servers[1].accounts.get({ accountName: username + '@' + servers[0].host }) | 167 | const account = await servers[1].accounts.get({ accountName: username + '@' + servers[0].host }) |
152 | await servers[1].abuses.report({ accountId: account.id, reason: 'super reason' }) | 168 | await servers[1].abuses.report({ token: userToken2, accountId: account.id, reason: 'super reason' }) |
153 | 169 | ||
154 | await waitJobs(servers) | 170 | await waitJobs(servers) |
155 | await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) | 171 | await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) |
@@ -165,13 +181,13 @@ describe('Test moderation notifications', function () { | |||
165 | server: servers[0], | 181 | server: servers[0], |
166 | emails, | 182 | emails, |
167 | socketNotifications: userNotifications, | 183 | socketNotifications: userNotifications, |
168 | token: userAccessToken | 184 | token: userToken1 |
169 | } | 185 | } |
170 | 186 | ||
171 | const name = 'abuse ' + buildUUID() | 187 | const name = 'abuse ' + buildUUID() |
172 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) | 188 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
173 | 189 | ||
174 | const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) | 190 | const body = await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason' }) |
175 | abuseId = body.abuse.id | 191 | abuseId = body.abuse.id |
176 | }) | 192 | }) |
177 | 193 | ||
@@ -205,7 +221,7 @@ describe('Test moderation notifications', function () { | |||
205 | server: servers[0], | 221 | server: servers[0], |
206 | emails, | 222 | emails, |
207 | socketNotifications: userNotifications, | 223 | socketNotifications: userNotifications, |
208 | token: userAccessToken | 224 | token: userToken1 |
209 | } | 225 | } |
210 | 226 | ||
211 | baseParamsAdmin = { | 227 | baseParamsAdmin = { |
@@ -216,15 +232,15 @@ describe('Test moderation notifications', function () { | |||
216 | } | 232 | } |
217 | 233 | ||
218 | const name = 'abuse ' + buildUUID() | 234 | const name = 'abuse ' + buildUUID() |
219 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) | 235 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
220 | 236 | ||
221 | { | 237 | { |
222 | const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) | 238 | const body = await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason' }) |
223 | abuseId = body.abuse.id | 239 | abuseId = body.abuse.id |
224 | } | 240 | } |
225 | 241 | ||
226 | { | 242 | { |
227 | const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason 2' }) | 243 | const body = await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason 2' }) |
228 | abuseId2 = body.abuse.id | 244 | abuseId2 = body.abuse.id |
229 | } | 245 | } |
230 | }) | 246 | }) |
@@ -254,7 +270,7 @@ describe('Test moderation notifications', function () { | |||
254 | this.timeout(10000) | 270 | this.timeout(10000) |
255 | 271 | ||
256 | const message = 'my super message to moderators' | 272 | const message = 'my super message to moderators' |
257 | await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) | 273 | await servers[0].abuses.addMessage({ token: userToken1, abuseId: abuseId2, message }) |
258 | await waitJobs(servers) | 274 | await waitJobs(servers) |
259 | 275 | ||
260 | const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com' | 276 | const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com' |
@@ -265,7 +281,7 @@ describe('Test moderation notifications', function () { | |||
265 | this.timeout(10000) | 281 | this.timeout(10000) |
266 | 282 | ||
267 | const message = 'my super message that should not be sent to reporter' | 283 | const message = 'my super message that should not be sent to reporter' |
268 | await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) | 284 | await servers[0].abuses.addMessage({ token: userToken1, abuseId: abuseId2, message }) |
269 | await waitJobs(servers) | 285 | await waitJobs(servers) |
270 | 286 | ||
271 | const toEmail = 'user_1@example.com' | 287 | const toEmail = 'user_1@example.com' |
@@ -281,7 +297,7 @@ describe('Test moderation notifications', function () { | |||
281 | server: servers[0], | 297 | server: servers[0], |
282 | emails, | 298 | emails, |
283 | socketNotifications: userNotifications, | 299 | socketNotifications: userNotifications, |
284 | token: userAccessToken | 300 | token: userToken1 |
285 | } | 301 | } |
286 | }) | 302 | }) |
287 | 303 | ||
@@ -289,7 +305,7 @@ describe('Test moderation notifications', function () { | |||
289 | this.timeout(10000) | 305 | this.timeout(10000) |
290 | 306 | ||
291 | const name = 'video for abuse ' + buildUUID() | 307 | const name = 'video for abuse ' + buildUUID() |
292 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) | 308 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
293 | 309 | ||
294 | await servers[0].blacklist.add({ videoId: uuid }) | 310 | await servers[0].blacklist.add({ videoId: uuid }) |
295 | 311 | ||
@@ -301,7 +317,7 @@ describe('Test moderation notifications', function () { | |||
301 | this.timeout(10000) | 317 | this.timeout(10000) |
302 | 318 | ||
303 | const name = 'video for abuse ' + buildUUID() | 319 | const name = 'video for abuse ' + buildUUID() |
304 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) | 320 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken1, attributes: { name } }) |
305 | 321 | ||
306 | await servers[0].blacklist.add({ videoId: uuid }) | 322 | await servers[0].blacklist.add({ videoId: uuid }) |
307 | 323 | ||
@@ -335,7 +351,7 @@ describe('Test moderation notifications', function () { | |||
335 | 351 | ||
336 | await checkUserRegistered({ ...baseParams, username: 'user_45', checkType: 'presence' }) | 352 | await checkUserRegistered({ ...baseParams, username: 'user_45', checkType: 'presence' }) |
337 | 353 | ||
338 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | 354 | const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } } |
339 | await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_45', checkType: 'absence' }) | 355 | await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_45', checkType: 'absence' }) |
340 | }) | 356 | }) |
341 | }) | 357 | }) |
@@ -377,7 +393,7 @@ describe('Test moderation notifications', function () { | |||
377 | 393 | ||
378 | await checkNewInstanceFollower({ ...baseParams, followerHost: 'localhost:' + servers[2].port, checkType: 'presence' }) | 394 | await checkNewInstanceFollower({ ...baseParams, followerHost: 'localhost:' + servers[2].port, checkType: 'presence' }) |
379 | 395 | ||
380 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | 396 | const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } } |
381 | await checkNewInstanceFollower({ ...baseParams, ...userOverride, followerHost: 'localhost:' + servers[2].port, checkType: 'absence' }) | 397 | await checkNewInstanceFollower({ ...baseParams, ...userOverride, followerHost: 'localhost:' + servers[2].port, checkType: 'absence' }) |
382 | }) | 398 | }) |
383 | 399 | ||
@@ -404,7 +420,7 @@ describe('Test moderation notifications', function () { | |||
404 | const followingHost = servers[2].host | 420 | const followingHost = servers[2].host |
405 | await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' }) | 421 | await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' }) |
406 | 422 | ||
407 | const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } | 423 | const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } } |
408 | await checkAutoInstanceFollowing({ ...baseParams, ...userOverride, followerHost, followingHost, checkType: 'absence' }) | 424 | await checkAutoInstanceFollowing({ ...baseParams, ...userOverride, followerHost, followingHost, checkType: 'absence' }) |
409 | 425 | ||
410 | config.followings.instance.autoFollowBack.enabled = false | 426 | config.followings.instance.autoFollowBack.enabled = false |
@@ -461,7 +477,7 @@ describe('Test moderation notifications', function () { | |||
461 | server: servers[0], | 477 | server: servers[0], |
462 | emails, | 478 | emails, |
463 | socketNotifications: userNotifications, | 479 | socketNotifications: userNotifications, |
464 | token: userAccessToken | 480 | token: userToken1 |
465 | } | 481 | } |
466 | 482 | ||
467 | currentCustomConfig = await servers[0].config.getCustomConfig() | 483 | currentCustomConfig = await servers[0].config.getCustomConfig() |
@@ -490,7 +506,7 @@ describe('Test moderation notifications', function () { | |||
490 | this.timeout(120000) | 506 | this.timeout(120000) |
491 | 507 | ||
492 | videoName = 'video with auto-blacklist ' + buildUUID() | 508 | videoName = 'video with auto-blacklist ' + buildUUID() |
493 | const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: videoName } }) | 509 | const video = await servers[0].videos.upload({ token: userToken1, attributes: { name: videoName } }) |
494 | shortUUID = video.shortUUID | 510 | shortUUID = video.shortUUID |
495 | uuid = video.uuid | 511 | uuid = video.uuid |
496 | 512 | ||
@@ -547,7 +563,7 @@ describe('Test moderation notifications', function () { | |||
547 | } | 563 | } |
548 | } | 564 | } |
549 | 565 | ||
550 | const { shortUUID, uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes }) | 566 | const { shortUUID, uuid } = await servers[0].videos.upload({ token: userToken1, attributes }) |
551 | 567 | ||
552 | await servers[0].blacklist.remove({ videoId: uuid }) | 568 | await servers[0].blacklist.remove({ videoId: uuid }) |
553 | 569 | ||
@@ -579,7 +595,7 @@ describe('Test moderation notifications', function () { | |||
579 | } | 595 | } |
580 | } | 596 | } |
581 | 597 | ||
582 | const { shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes }) | 598 | const { shortUUID } = await servers[0].videos.upload({ token: userToken1, attributes }) |
583 | 599 | ||
584 | await wait(6000) | 600 | await wait(6000) |
585 | await checkVideoIsPublished({ ...userBaseParams, videoName: name, shortUUID, checkType: 'absence' }) | 601 | await checkVideoIsPublished({ ...userBaseParams, videoName: name, shortUUID, checkType: 'absence' }) |
diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index 468efdf35..9af20843e 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts | |||
@@ -267,7 +267,7 @@ describe('Test user notifications', function () { | |||
267 | }) | 267 | }) |
268 | 268 | ||
269 | it('Should send a notification when an imported video is transcoded', async function () { | 269 | it('Should send a notification when an imported video is transcoded', async function () { |
270 | this.timeout(50000) | 270 | this.timeout(120000) |
271 | 271 | ||
272 | const name = 'video import ' + buildUUID() | 272 | const name = 'video import ' + buildUUID() |
273 | 273 | ||
diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 86b40cfe6..b5929129a 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts | |||
@@ -307,7 +307,7 @@ describe('Test videos redundancy', function () { | |||
307 | const strategy = 'most-views' | 307 | const strategy = 'most-views' |
308 | 308 | ||
309 | before(function () { | 309 | before(function () { |
310 | this.timeout(120000) | 310 | this.timeout(240000) |
311 | 311 | ||
312 | return createServers(strategy) | 312 | return createServers(strategy) |
313 | }) | 313 | }) |
@@ -357,7 +357,7 @@ describe('Test videos redundancy', function () { | |||
357 | const strategy = 'trending' | 357 | const strategy = 'trending' |
358 | 358 | ||
359 | before(function () { | 359 | before(function () { |
360 | this.timeout(120000) | 360 | this.timeout(240000) |
361 | 361 | ||
362 | return createServers(strategy) | 362 | return createServers(strategy) |
363 | }) | 363 | }) |
@@ -420,7 +420,7 @@ describe('Test videos redundancy', function () { | |||
420 | const strategy = 'recently-added' | 420 | const strategy = 'recently-added' |
421 | 421 | ||
422 | before(function () { | 422 | before(function () { |
423 | this.timeout(120000) | 423 | this.timeout(240000) |
424 | 424 | ||
425 | return createServers(strategy, { min_views: 3 }) | 425 | return createServers(strategy, { min_views: 3 }) |
426 | }) | 426 | }) |
@@ -491,7 +491,7 @@ describe('Test videos redundancy', function () { | |||
491 | const strategy = 'recently-added' | 491 | const strategy = 'recently-added' |
492 | 492 | ||
493 | before(async function () { | 493 | before(async function () { |
494 | this.timeout(120000) | 494 | this.timeout(240000) |
495 | 495 | ||
496 | await createServers(strategy, { min_views: 3 }, false) | 496 | await createServers(strategy, { min_views: 3 }, false) |
497 | }) | 497 | }) |
@@ -553,7 +553,7 @@ describe('Test videos redundancy', function () { | |||
553 | 553 | ||
554 | describe('With manual strategy', function () { | 554 | describe('With manual strategy', function () { |
555 | before(function () { | 555 | before(function () { |
556 | this.timeout(120000) | 556 | this.timeout(240000) |
557 | 557 | ||
558 | return createServers(null) | 558 | return createServers(null) |
559 | }) | 559 | }) |
@@ -632,7 +632,7 @@ describe('Test videos redundancy', function () { | |||
632 | } | 632 | } |
633 | 633 | ||
634 | before(async function () { | 634 | before(async function () { |
635 | this.timeout(120000) | 635 | this.timeout(240000) |
636 | 636 | ||
637 | await createServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) | 637 | await createServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) |
638 | 638 | ||
@@ -674,7 +674,7 @@ describe('Test videos redundancy', function () { | |||
674 | const strategy = 'recently-added' | 674 | const strategy = 'recently-added' |
675 | 675 | ||
676 | before(async function () { | 676 | before(async function () { |
677 | this.timeout(120000) | 677 | this.timeout(240000) |
678 | 678 | ||
679 | await createServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) | 679 | await createServers(strategy, { min_lifetime: '7 seconds', min_views: 0 }) |
680 | 680 | ||
@@ -698,7 +698,7 @@ describe('Test videos redundancy', function () { | |||
698 | }) | 698 | }) |
699 | 699 | ||
700 | it('Should cache video 2 webseeds on the first video', async function () { | 700 | it('Should cache video 2 webseeds on the first video', async function () { |
701 | this.timeout(120000) | 701 | this.timeout(240000) |
702 | 702 | ||
703 | await waitJobs(servers) | 703 | await waitJobs(servers) |
704 | 704 | ||
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index ea524723c..96ec17b0f 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts | |||
@@ -43,6 +43,9 @@ function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) { | |||
43 | expect(data.services.twitter.username).to.equal('@Chocobozzz') | 43 | expect(data.services.twitter.username).to.equal('@Chocobozzz') |
44 | expect(data.services.twitter.whitelisted).to.be.false | 44 | expect(data.services.twitter.whitelisted).to.be.false |
45 | 45 | ||
46 | expect(data.client.videos.miniature.preferAuthorDisplayName).to.be.false | ||
47 | expect(data.client.menu.login.redirectOnSingleExternalAuth).to.be.false | ||
48 | |||
46 | expect(data.cache.previews.size).to.equal(1) | 49 | expect(data.cache.previews.size).to.equal(1) |
47 | expect(data.cache.captions.size).to.equal(1) | 50 | expect(data.cache.captions.size).to.equal(1) |
48 | expect(data.cache.torrents.size).to.equal(1) | 51 | expect(data.cache.torrents.size).to.equal(1) |
@@ -138,6 +141,9 @@ function checkUpdatedConfig (data: CustomConfig) { | |||
138 | expect(data.services.twitter.username).to.equal('@Kuja') | 141 | expect(data.services.twitter.username).to.equal('@Kuja') |
139 | expect(data.services.twitter.whitelisted).to.be.true | 142 | expect(data.services.twitter.whitelisted).to.be.true |
140 | 143 | ||
144 | expect(data.client.videos.miniature.preferAuthorDisplayName).to.be.true | ||
145 | expect(data.client.menu.login.redirectOnSingleExternalAuth).to.be.true | ||
146 | |||
141 | expect(data.cache.previews.size).to.equal(2) | 147 | expect(data.cache.previews.size).to.equal(2) |
142 | expect(data.cache.captions.size).to.equal(3) | 148 | expect(data.cache.captions.size).to.equal(3) |
143 | expect(data.cache.torrents.size).to.equal(4) | 149 | expect(data.cache.torrents.size).to.equal(4) |
@@ -246,6 +252,18 @@ const newCustomConfig: CustomConfig = { | |||
246 | whitelisted: true | 252 | whitelisted: true |
247 | } | 253 | } |
248 | }, | 254 | }, |
255 | client: { | ||
256 | videos: { | ||
257 | miniature: { | ||
258 | preferAuthorDisplayName: true | ||
259 | } | ||
260 | }, | ||
261 | menu: { | ||
262 | login: { | ||
263 | redirectOnSingleExternalAuth: true | ||
264 | } | ||
265 | } | ||
266 | }, | ||
249 | cache: { | 267 | cache: { |
250 | previews: { | 268 | previews: { |
251 | size: 2 | 269 | size: 2 |
diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index 5f97edbc2..cd8d70341 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts | |||
@@ -185,7 +185,7 @@ describe('Test emails', function () { | |||
185 | this.timeout(10000) | 185 | this.timeout(10000) |
186 | 186 | ||
187 | const reason = 'my super bad reason' | 187 | const reason = 'my super bad reason' |
188 | await server.abuses.report({ videoId, reason }) | 188 | await server.abuses.report({ token: userAccessToken, videoId, reason }) |
189 | 189 | ||
190 | await waitJobs(server) | 190 | await waitJobs(server) |
191 | expect(emails).to.have.lengthOf(3) | 191 | expect(emails).to.have.lengthOf(3) |
diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index b51b3bcdd..08b624ff3 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts | |||
@@ -2,7 +2,15 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { cleanupTests, createSingleServer, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' | 5 | import { |
6 | cleanupTests, | ||
7 | createSingleServer, | ||
8 | doubleFollow, | ||
9 | PeerTubeServer, | ||
10 | setAccessTokensToServers, | ||
11 | wait, | ||
12 | waitJobs | ||
13 | } from '@shared/extra-utils' | ||
6 | import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models' | 14 | import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models' |
7 | 15 | ||
8 | const expect = chai.expect | 16 | const expect = chai.expect |
@@ -209,7 +217,7 @@ describe('Test video privacy', function () { | |||
209 | describe('Privacy update', function () { | 217 | describe('Privacy update', function () { |
210 | 218 | ||
211 | it('Should update the private and internal videos to public on server 1', async function () { | 219 | it('Should update the private and internal videos to public on server 1', async function () { |
212 | this.timeout(10000) | 220 | this.timeout(100000) |
213 | 221 | ||
214 | now = Date.now() | 222 | now = Date.now() |
215 | 223 | ||
@@ -230,6 +238,7 @@ describe('Test video privacy', function () { | |||
230 | await servers[0].videos.update({ id: internalVideoId, attributes }) | 238 | await servers[0].videos.update({ id: internalVideoId, attributes }) |
231 | } | 239 | } |
232 | 240 | ||
241 | await wait(10000) | ||
233 | await waitJobs(servers) | 242 | await waitJobs(servers) |
234 | }) | 243 | }) |
235 | 244 | ||
diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts index f2a984962..3ac440f84 100644 --- a/server/tests/cli/peertube.ts +++ b/server/tests/cli/peertube.ts | |||
@@ -207,6 +207,25 @@ describe('Test CLI wrapper', function () { | |||
207 | 207 | ||
208 | expect(res).to.not.contain('peertube-plugin-hello-world') | 208 | expect(res).to.not.contain('peertube-plugin-hello-world') |
209 | }) | 209 | }) |
210 | |||
211 | it('Should install a plugin in requested version', async function () { | ||
212 | this.timeout(60000) | ||
213 | |||
214 | await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world --plugin-version 0.0.17`) | ||
215 | }) | ||
216 | |||
217 | it('Should list installed plugins, in correct version', async function () { | ||
218 | const res = await cliCommand.execWithEnv(`${cmd} plugins list`) | ||
219 | |||
220 | expect(res).to.contain('peertube-plugin-hello-world') | ||
221 | expect(res).to.contain('0.0.17') | ||
222 | }) | ||
223 | |||
224 | it('Should uninstall the plugin again', async function () { | ||
225 | const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`) | ||
226 | |||
227 | expect(res).to.not.contain('peertube-plugin-hello-world') | ||
228 | }) | ||
210 | }) | 229 | }) |
211 | 230 | ||
212 | describe('Manage video redundancies', function () { | 231 | describe('Manage video redundancies', function () { |
diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts index 2d4c02da7..1c0282da9 100644 --- a/server/tests/cli/prune-storage.ts +++ b/server/tests/cli/prune-storage.ts | |||
@@ -36,7 +36,7 @@ async function assertNotExists (server: PeerTubeServer, directory: string, subst | |||
36 | } | 36 | } |
37 | } | 37 | } |
38 | 38 | ||
39 | async function assertCountAreOkay (servers: PeerTubeServer[], videoServer2UUID: string) { | 39 | async function assertCountAreOkay (servers: PeerTubeServer[]) { |
40 | for (const server of servers) { | 40 | for (const server of servers) { |
41 | const videosCount = await countFiles(server, 'videos') | 41 | const videosCount = await countFiles(server, 'videos') |
42 | expect(videosCount).to.equal(8) | 42 | expect(videosCount).to.equal(8) |
@@ -52,22 +52,16 @@ async function assertCountAreOkay (servers: PeerTubeServer[], videoServer2UUID: | |||
52 | 52 | ||
53 | const avatarsCount = await countFiles(server, 'avatars') | 53 | const avatarsCount = await countFiles(server, 'avatars') |
54 | expect(avatarsCount).to.equal(2) | 54 | expect(avatarsCount).to.equal(2) |
55 | } | ||
56 | |||
57 | // When we'll prune HLS directories too | ||
58 | // const hlsRootCount = await countFiles(servers[1], 'streaming-playlists/hls/') | ||
59 | // expect(hlsRootCount).to.equal(2) | ||
60 | 55 | ||
61 | // const hlsCount = await countFiles(servers[1], 'streaming-playlists/hls/' + videoServer2UUID) | 56 | const hlsRootCount = await countFiles(server, 'streaming-playlists/hls') |
62 | // expect(hlsCount).to.equal(10) | 57 | expect(hlsRootCount).to.equal(2) |
58 | } | ||
63 | } | 59 | } |
64 | 60 | ||
65 | describe('Test prune storage scripts', function () { | 61 | describe('Test prune storage scripts', function () { |
66 | let servers: PeerTubeServer[] | 62 | let servers: PeerTubeServer[] |
67 | const badNames: { [directory: string]: string[] } = {} | 63 | const badNames: { [directory: string]: string[] } = {} |
68 | 64 | ||
69 | let videoServer2UUID: string | ||
70 | |||
71 | before(async function () { | 65 | before(async function () { |
72 | this.timeout(120000) | 66 | this.timeout(120000) |
73 | 67 | ||
@@ -77,9 +71,7 @@ describe('Test prune storage scripts', function () { | |||
77 | 71 | ||
78 | for (const server of servers) { | 72 | for (const server of servers) { |
79 | await server.videos.upload({ attributes: { name: 'video 1' } }) | 73 | await server.videos.upload({ attributes: { name: 'video 1' } }) |
80 | 74 | await server.videos.upload({ attributes: { name: 'video 2' } }) | |
81 | const { uuid } = await server.videos.upload({ attributes: { name: 'video 2' } }) | ||
82 | if (server.serverNumber === 2) videoServer2UUID = uuid | ||
83 | 75 | ||
84 | await server.users.updateMyAvatar({ fixture: 'avatar.png' }) | 76 | await server.users.updateMyAvatar({ fixture: 'avatar.png' }) |
85 | 77 | ||
@@ -123,7 +115,7 @@ describe('Test prune storage scripts', function () { | |||
123 | }) | 115 | }) |
124 | 116 | ||
125 | it('Should have the files on the disk', async function () { | 117 | it('Should have the files on the disk', async function () { |
126 | await assertCountAreOkay(servers, videoServer2UUID) | 118 | await assertCountAreOkay(servers) |
127 | }) | 119 | }) |
128 | 120 | ||
129 | it('Should create some dirty files', async function () { | 121 | it('Should create some dirty files', async function () { |
@@ -188,27 +180,14 @@ describe('Test prune storage scripts', function () { | |||
188 | badNames['avatars'] = [ n1, n2 ] | 180 | badNames['avatars'] = [ n1, n2 ] |
189 | } | 181 | } |
190 | 182 | ||
191 | // When we'll prune HLS directories too | 183 | { |
192 | // { | 184 | const directory = join('streaming-playlists', 'hls') |
193 | // const directory = join('streaming-playlists', 'hls') | 185 | const base = servers[0].servers.buildDirectory(directory) |
194 | // const base = servers[1].servers.buildDirectory(directory) | ||
195 | |||
196 | // const n1 = buildUUID() | ||
197 | // await createFile(join(base, n1)) | ||
198 | // badNames[directory] = [ n1 ] | ||
199 | // } | ||
200 | |||
201 | // { | ||
202 | // const directory = join('streaming-playlists', 'hls', videoServer2UUID) | ||
203 | // const base = servers[1].servers.buildDirectory(directory) | ||
204 | // const n1 = buildUUID() + '-240-fragmented-.mp4' | ||
205 | // const n2 = buildUUID() + '-master.m3u8' | ||
206 | |||
207 | // await createFile(join(base, n1)) | ||
208 | // await createFile(join(base, n2)) | ||
209 | 186 | ||
210 | // badNames[directory] = [ n1, n2 ] | 187 | const n1 = buildUUID() |
211 | // } | 188 | await createFile(join(base, n1)) |
189 | badNames[directory] = [ n1 ] | ||
190 | } | ||
212 | } | 191 | } |
213 | }) | 192 | }) |
214 | 193 | ||
@@ -220,7 +199,7 @@ describe('Test prune storage scripts', function () { | |||
220 | }) | 199 | }) |
221 | 200 | ||
222 | it('Should have removed files', async function () { | 201 | it('Should have removed files', async function () { |
223 | await assertCountAreOkay(servers, videoServer2UUID) | 202 | await assertCountAreOkay(servers) |
224 | 203 | ||
225 | for (const directory of Object.keys(badNames)) { | 204 | for (const directory of Object.keys(badNames)) { |
226 | for (const name of badNames[directory]) { | 205 | for (const name of badNames[directory]) { |
diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js index db405ff31..04e059848 100644 --- a/server/tests/fixtures/peertube-plugin-test/main.js +++ b/server/tests/fixtures/peertube-plugin-test/main.js | |||
@@ -233,6 +233,28 @@ async function register ({ registerHook, registerSetting, settingsManager, stora | |||
233 | } | 233 | } |
234 | }) | 234 | }) |
235 | 235 | ||
236 | registerHook({ | ||
237 | target: 'filter:api.server.stats.get.result', | ||
238 | handler: (result) => { | ||
239 | return { ...result, customStats: 14 } | ||
240 | } | ||
241 | }) | ||
242 | |||
243 | // Upload/import/live attributes | ||
244 | for (const target of [ | ||
245 | 'filter:api.video.upload.video-attribute.result', | ||
246 | 'filter:api.video.import-url.video-attribute.result', | ||
247 | 'filter:api.video.import-torrent.video-attribute.result', | ||
248 | 'filter:api.video.live.video-attribute.result' | ||
249 | ]) { | ||
250 | registerHook({ | ||
251 | target, | ||
252 | handler: (result) => { | ||
253 | return { ...result, description: result.description + ' - ' + target } | ||
254 | } | ||
255 | }) | ||
256 | } | ||
257 | |||
236 | { | 258 | { |
237 | const filterHooks = [ | 259 | const filterHooks = [ |
238 | 'filter:api.search.videos.local.list.params', | 260 | 'filter:api.search.videos.local.list.params', |
diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts index f3e018d43..25b25bfee 100644 --- a/server/tests/plugins/external-auth.ts +++ b/server/tests/plugins/external-auth.ts | |||
@@ -125,7 +125,7 @@ describe('Test external auth plugins', function () { | |||
125 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | 125 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
126 | }) | 126 | }) |
127 | 127 | ||
128 | await server.servers.waitUntilLog('expired external auth token', 2) | 128 | await server.servers.waitUntilLog('expired external auth token', 4) |
129 | }) | 129 | }) |
130 | 130 | ||
131 | it('Should auto login Cyan, create the user and use the token', async function () { | 131 | it('Should auto login Cyan, create the user and use the token', async function () { |
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index 02915f08c..ff2afc56b 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts | |||
@@ -537,6 +537,75 @@ describe('Test plugin filter hooks', function () { | |||
537 | }) | 537 | }) |
538 | }) | 538 | }) |
539 | 539 | ||
540 | describe('Upload/import/live attributes filters', function () { | ||
541 | |||
542 | before(async function () { | ||
543 | await servers[0].config.enableLive({ transcoding: false, allowReplay: false }) | ||
544 | await servers[0].config.enableImports() | ||
545 | await servers[0].config.disableTranscoding() | ||
546 | }) | ||
547 | |||
548 | it('Should run filter:api.video.upload.video-attribute.result', async function () { | ||
549 | for (const mode of [ 'legacy' as 'legacy', 'resumable' as 'resumable' ]) { | ||
550 | const { id } = await servers[0].videos.upload({ attributes: { name: 'video', description: 'upload' }, mode }) | ||
551 | |||
552 | const video = await servers[0].videos.get({ id }) | ||
553 | expect(video.description).to.equal('upload - filter:api.video.upload.video-attribute.result') | ||
554 | } | ||
555 | }) | ||
556 | |||
557 | it('Should run filter:api.video.import-url.video-attribute.result', async function () { | ||
558 | const attributes = { | ||
559 | name: 'video', | ||
560 | description: 'import url', | ||
561 | channelId: servers[0].store.channel.id, | ||
562 | targetUrl: FIXTURE_URLS.goodVideo, | ||
563 | privacy: VideoPrivacy.PUBLIC | ||
564 | } | ||
565 | const { video: { id } } = await servers[0].imports.importVideo({ attributes }) | ||
566 | |||
567 | const video = await servers[0].videos.get({ id }) | ||
568 | expect(video.description).to.equal('import url - filter:api.video.import-url.video-attribute.result') | ||
569 | }) | ||
570 | |||
571 | it('Should run filter:api.video.import-torrent.video-attribute.result', async function () { | ||
572 | const attributes = { | ||
573 | name: 'video', | ||
574 | description: 'import torrent', | ||
575 | channelId: servers[0].store.channel.id, | ||
576 | magnetUri: FIXTURE_URLS.magnet, | ||
577 | privacy: VideoPrivacy.PUBLIC | ||
578 | } | ||
579 | const { video: { id } } = await servers[0].imports.importVideo({ attributes }) | ||
580 | |||
581 | const video = await servers[0].videos.get({ id }) | ||
582 | expect(video.description).to.equal('import torrent - filter:api.video.import-torrent.video-attribute.result') | ||
583 | }) | ||
584 | |||
585 | it('Should run filter:api.video.live.video-attribute.result', async function () { | ||
586 | const fields = { | ||
587 | name: 'live', | ||
588 | description: 'live', | ||
589 | channelId: servers[0].store.channel.id, | ||
590 | privacy: VideoPrivacy.PUBLIC | ||
591 | } | ||
592 | const { id } = await servers[0].live.create({ fields }) | ||
593 | |||
594 | const video = await servers[0].videos.get({ id }) | ||
595 | expect(video.description).to.equal('live - filter:api.video.live.video-attribute.result') | ||
596 | }) | ||
597 | }) | ||
598 | |||
599 | describe('Stats filters', function () { | ||
600 | |||
601 | it('Should run filter:api.server.stats.get.result', async function () { | ||
602 | const data = await servers[0].stats.get() | ||
603 | |||
604 | expect((data as any).customStats).to.equal(14) | ||
605 | }) | ||
606 | |||
607 | }) | ||
608 | |||
540 | after(async function () { | 609 | after(async function () { |
541 | await cleanupTests(servers) | 610 | await cleanupTests(servers) |
542 | }) | 611 | }) |
diff --git a/server/tools/peertube-plugins.ts b/server/tools/peertube-plugins.ts index ae625114d..9dd3f08c9 100644 --- a/server/tools/peertube-plugins.ts +++ b/server/tools/peertube-plugins.ts | |||
@@ -31,6 +31,7 @@ program | |||
31 | .option('-p, --password <token>', 'Password') | 31 | .option('-p, --password <token>', 'Password') |
32 | .option('-P --path <path>', 'Install from a path') | 32 | .option('-P --path <path>', 'Install from a path') |
33 | .option('-n, --npm-name <npmName>', 'Install from npm') | 33 | .option('-n, --npm-name <npmName>', 'Install from npm') |
34 | .option('--plugin-version <pluginVersion>', 'Specify the plugin version to install (only available when installing from npm)') | ||
34 | .action((options, command) => installPluginCLI(command, options)) | 35 | .action((options, command) => installPluginCLI(command, options)) |
35 | 36 | ||
36 | program | 37 | program |
@@ -109,7 +110,7 @@ async function installPluginCLI (command: Command, options: OptionValues) { | |||
109 | await assignToken(server, username, password) | 110 | await assignToken(server, username, password) |
110 | 111 | ||
111 | try { | 112 | try { |
112 | await server.plugins.install({ npmName: options.npmName, path: options.path }) | 113 | await server.plugins.install({ npmName: options.npmName, path: options.path, pluginVersion: options.pluginVersion }) |
113 | } catch (err) { | 114 | } catch (err) { |
114 | console.error('Cannot install plugin.', err) | 115 | console.error('Cannot install plugin.', err) |
115 | process.exit(-1) | 116 | process.exit(-1) |