Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Prefer handle param name

Chocobozzze7753c1b629b
diff --git a/server/core/controllers/activitypub/client.ts b/server/core/controllers/activitypub/client.ts
index 1ff2342d4b..fe3657cb2c 100644
--- a/server/core/controllers/activitypub/client.ts
+++ b/server/core/controllers/activitypub/client.ts
@@ -92,7 +92,7 @@ activityPubClientRouter.get(
asyncMiddleware(accountPlaylistsController)
)
activityPubClientRouter.get(
- '/accounts?/:name/likes/:videoId',
+ '/accounts?/:accountName/likes/:videoId',
executeIfActivityPub,
activityPubRateLimiter,
cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS),
@@ -100,7 +100,7 @@ activityPubClientRouter.get(
asyncMiddleware(getAccountVideoRateFactory('like'))
)
activityPubClientRouter.get(
- '/accounts?/:name/dislikes/:videoId',
+ '/accounts?/:accountName/dislikes/:videoId',
executeIfActivityPub,
activityPubRateLimiter,
cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS),
diff --git a/server/core/controllers/api/server/follows.ts b/server/core/controllers/api/server/follows.ts
index 3a796229f7..f6fb43b8db 100644
--- a/server/core/controllers/api/server/follows.ts
+++ b/server/core/controllers/api/server/follows.ts
@@ -30,7 +30,8 @@ import {
import { ActorFollowModel } from '../../../models/actor/actor-follow.js'
const serverFollowsRouter = express.Router()
-serverFollowsRouter.get('/following',
+serverFollowsRouter.get(
+ '/following',
listFollowsValidator,
paginationValidator,
instanceFollowingSortValidator,
@@ -39,7 +40,8 @@ serverFollowsRouter.get('/following',
asyncMiddleware(listFollowing)
)
-serverFollowsRouter.post('/following',
+serverFollowsRouter.post(
+ '/following',
authenticate,
ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW),
followValidator,
@@ -47,14 +49,16 @@ serverFollowsRouter.post('/following',
asyncMiddleware(addFollow)
)
-serverFollowsRouter.delete('/following/:hostOrHandle',
+serverFollowsRouter.delete(
+ '/following/:hostOrHandle',
authenticate,
ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW),
asyncMiddleware(removeFollowingValidator),
asyncMiddleware(removeFollowing)
)
-serverFollowsRouter.get('/followers',
+serverFollowsRouter.get(
+ '/followers',
listFollowsValidator,
paginationValidator,
instanceFollowersSortValidator,
@@ -63,14 +67,16 @@ serverFollowsRouter.get('/followers',
asyncMiddleware(listFollowers)
)
-serverFollowsRouter.delete('/followers/:nameWithHost',
+serverFollowsRouter.delete(
+ '/followers/:handle',
authenticate,
ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW),
asyncMiddleware(getFollowerValidator),
asyncMiddleware(removeFollower)
)
-serverFollowsRouter.post('/followers/:nameWithHost/reject',
+serverFollowsRouter.post(
+ '/followers/:handle/reject',
authenticate,
ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW),
asyncMiddleware(getFollowerValidator),
@@ -78,7 +84,8 @@ serverFollowsRouter.post('/followers/:nameWithHost/reject',
asyncMiddleware(rejectFollower)
)
-serverFollowsRouter.post('/followers/:nameWithHost/accept',
+serverFollowsRouter.post(
+ '/followers/:handle/accept',
authenticate,
ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW),
asyncMiddleware(getFollowerValidator),
diff --git a/server/core/controllers/client.ts b/server/core/controllers/client.ts
index 403b8b141a..e23716bd93 100644
--- a/server/core/controllers/client.ts
+++ b/server/core/controllers/client.ts
@@ -24,30 +24,15 @@ const testEmbedPath = join(distPath, 'standalone', 'videos', 'test-embed.html')
// Special route that add OpenGraph and oEmbed tags
// Do not use a template engine for a so little thing
-clientsRouter.use([ '/w/p/:id', '/videos/watch/playlist/:id' ],
- clientsRateLimiter,
- asyncMiddleware(generateWatchPlaylistHtmlPage)
-)
+clientsRouter.use([ '/w/p/:id', '/videos/watch/playlist/:id' ], clientsRateLimiter, asyncMiddleware(generateWatchPlaylistHtmlPage))
-clientsRouter.use([ '/w/:id', '/videos/watch/:id' ],
- clientsRateLimiter,
- asyncMiddleware(generateWatchHtmlPage)
-)
+clientsRouter.use([ '/w/:id', '/videos/watch/:id' ], clientsRateLimiter, asyncMiddleware(generateWatchHtmlPage))
-clientsRouter.use([ '/accounts/:nameWithHost', '/a/:nameWithHost' ],
- clientsRateLimiter,
- asyncMiddleware(generateAccountHtmlPage)
-)
+clientsRouter.use([ '/accounts/:handle', '/a/:handle' ], clientsRateLimiter, asyncMiddleware(generateAccountHtmlPage))
-clientsRouter.use([ '/video-channels/:nameWithHost', '/c/:nameWithHost' ],
- clientsRateLimiter,
- asyncMiddleware(generateVideoChannelHtmlPage)
-)
+clientsRouter.use([ '/video-channels/:handle', '/c/:handle' ], clientsRateLimiter, asyncMiddleware(generateVideoChannelHtmlPage))
-clientsRouter.use('/@:nameWithHost',
- clientsRateLimiter,
- asyncMiddleware(generateActorHtmlPage)
-)
+clientsRouter.use('/@:handle', clientsRateLimiter, asyncMiddleware(generateActorHtmlPage))
// ---------------------------------------------------------------------------
@@ -118,10 +103,7 @@ clientsRouter.use('/client/*', (req: express.Request, res: express.Response) =>
// Always serve index client page (the client is a single page application, let it handle routing)
// Try to provide the right language index.html
-clientsRouter.use('/(:language)?',
- clientsRateLimiter,
- asyncMiddleware(serveIndexHTML)
-)
+clientsRouter.use('/(:language)?', clientsRateLimiter, asyncMiddleware(serveIndexHTML))
// ---------------------------------------------------------------------------
@@ -206,19 +188,19 @@ async function generateWatchPlaylistHtmlPage (req: express.Request, res: express
}
async function generateAccountHtmlPage (req: express.Request, res: express.Response) {
- const html = await ClientHtml.getAccountHTMLPage(req.params.nameWithHost, req, res)
+ const html = await ClientHtml.getAccountHTMLPage(req.params.handle, req, res)
return sendHTML(html, res, true)
}
async function generateVideoChannelHtmlPage (req: express.Request, res: express.Response) {
- const html = await ClientHtml.getVideoChannelHTMLPage(req.params.nameWithHost, req, res)
+ const html = await ClientHtml.getVideoChannelHTMLPage(req.params.handle, req, res)
return sendHTML(html, res, true)
}
async function generateActorHtmlPage (req: express.Request, res: express.Response) {
- const html = await ClientHtml.getActorHTMLPage(req.params.nameWithHost, req, res)
+ const html = await ClientHtml.getActorHTMLPage(req.params.handle, req, res)
return sendHTML(html, res, true)
}
diff --git a/server/core/lib/activitypub/actors/webfinger.ts b/server/core/lib/activitypub/actors/webfinger.ts
index 21d148a611..6fcc269dbb 100644
--- a/server/core/lib/activitypub/actors/webfinger.ts
+++ b/server/core/lib/activitypub/actors/webfinger.ts
@@ -56,9 +56,9 @@ function getLinkOrThrow (webfingerData: WebFingerData) {
return selfLink.href
}
-function webfingerLookup (nameWithHost: string) {
+function webfingerLookup (handle: string) {
return new Promise<WebFingerData>((res, rej) => {
- webfinger.lookup(nameWithHost, (err, p) => {
+ webfinger.lookup(handle, (err, p) => {
if (err) return rej(err)
return res(p.object)
diff --git a/server/core/lib/html/client-html.ts b/server/core/lib/html/client-html.ts
index c5e765ec8e..df5142ec23 100644
--- a/server/core/lib/html/client-html.ts
+++ b/server/core/lib/html/client-html.ts
@@ -8,7 +8,6 @@ import { ActorHtml } from './shared/actor-html.js'
import { PageHtml } from './shared/page-html.js'
class ClientHtml {
-
static invalidateCache () {
PageHtml.invalidateCache()
}
@@ -39,16 +38,16 @@ class ClientHtml {
// ---------------------------------------------------------------------------
- static getAccountHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
- return ActorHtml.getAccountHTMLPage(nameWithHost, req, res)
+ static getAccountHTMLPage (handle: string, req: express.Request, res: express.Response) {
+ return ActorHtml.getAccountHTMLPage(handle, req, res)
}
- static getVideoChannelHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
- return ActorHtml.getVideoChannelHTMLPage(nameWithHost, req, res)
+ static getVideoChannelHTMLPage (handle: string, req: express.Request, res: express.Response) {
+ return ActorHtml.getVideoChannelHTMLPage(handle, req, res)
}
- static getActorHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
- return ActorHtml.getActorHTMLPage(nameWithHost, req, res)
+ static getActorHTMLPage (handle: string, req: express.Request, res: express.Response) {
+ return ActorHtml.getActorHTMLPage(handle, req, res)
}
}
diff --git a/server/core/lib/html/shared/actor-html.ts b/server/core/lib/html/shared/actor-html.ts
index 7de5058dab..2dbd3bc2a9 100644
--- a/server/core/lib/html/shared/actor-html.ts
+++ b/server/core/lib/html/shared/actor-html.ts
@@ -11,8 +11,8 @@ import { PageHtml } from './page-html.js'
import { TagsHtml, TagsOptions } from './tags-html.js'
export class ActorHtml {
- static async getAccountHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
- const accountModelPromise = AccountModel.loadByNameWithHost(nameWithHost)
+ static async getAccountHTMLPage (handle: string, req: express.Request, res: express.Response) {
+ const accountModelPromise = AccountModel.loadByHandle(handle)
return this.getAccountOrChannelHTMLPage({
loader: () => accountModelPromise,
@@ -22,8 +22,8 @@ export class ActorHtml {
})
}
- static async getVideoChannelHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
- const videoChannel = await VideoChannelModel.loadByHandleAndPopulateAccount(nameWithHost)
+ static async getVideoChannelHTMLPage (handle: string, req: express.Request, res: express.Response) {
+ const videoChannel = await VideoChannelModel.loadByHandleAndPopulateAccount(handle)
return this.getAccountOrChannelHTMLPage({
loader: () => Promise.resolve(videoChannel),
@@ -33,10 +33,10 @@ export class ActorHtml {
})
}
- static async getActorHTMLPage (nameWithHost: string, req: express.Request, res: express.Response) {
+ static async getActorHTMLPage (handle: string, req: express.Request, res: express.Response) {
const [ account, channel ] = await Promise.all([
- AccountModel.loadByNameWithHost(nameWithHost),
- VideoChannelModel.loadByHandleAndPopulateAccount(nameWithHost)
+ AccountModel.loadByHandle(handle),
+ VideoChannelModel.loadByHandleAndPopulateAccount(handle)
])
return this.getAccountOrChannelHTMLPage({
diff --git a/server/core/lib/plugins/plugin-helpers-builder.ts b/server/core/lib/plugins/plugin-helpers-builder.ts
index 05b14362c6..e5fe98d72a 100644
--- a/server/core/lib/plugins/plugin-helpers-builder.ts
+++ b/server/core/lib/plugins/plugin-helpers-builder.ts
@@ -177,7 +177,7 @@ function buildModerationHelpers () {
},
blockAccount: async (options: { byAccountId: number, handleToBlock: string }) => {
- const accountToBlock = await AccountModel.loadByNameWithHost(options.handleToBlock)
+ const accountToBlock = await AccountModel.loadByHandle(options.handleToBlock)
if (!accountToBlock) return
const user = await UserModel.loadByAccountId(options.byAccountId)
@@ -190,7 +190,7 @@ function buildModerationHelpers () {
},
unblockAccount: async (options: { byAccountId: number, handleToUnblock: string }) => {
- const targetAccount = await AccountModel.loadByNameWithHost(options.handleToUnblock)
+ const targetAccount = await AccountModel.loadByHandle(options.handleToUnblock)
if (!targetAccount) return
const accountBlock = await AccountBlocklistModel.loadByAccountAndTarget(options.byAccountId, targetAccount.id)
diff --git a/server/core/lib/user-import-export/importers/account-blocklist-importer.ts b/server/core/lib/user-import-export/importers/account-blocklist-importer.ts
index 5a7534eefb..99458d4091 100644
--- a/server/core/lib/user-import-export/importers/account-blocklist-importer.ts
+++ b/server/core/lib/user-import-export/importers/account-blocklist-importer.ts
@@ -12,8 +12,7 @@ const lTags = loggerTagsFactory('user-import')
type ImportObject = { handle: string | null, host: string | null, archiveFiles?: never }
-export class BlocklistImporter extends AbstractUserImporter <BlocklistExportJSON, ImportObject, ImportObject> {
-
+export class BlocklistImporter extends AbstractUserImporter<BlocklistExportJSON, ImportObject, ImportObject> {
protected getImportObjects (json: BlocklistExportJSON) {
return [
...json.actors.map(o => ({ handle: o.handle, host: null })),
@@ -38,7 +37,7 @@ export class BlocklistImporter extends AbstractUserImporter <BlocklistExportJSON
}
private async importAccountBlock (handle: string) {
- const accountToBlock = await AccountModel.loadByNameWithHost(handle)
+ const accountToBlock = await AccountModel.loadByHandle(handle)
if (!accountToBlock) {
logger.info('Account %s was not blocked on user import because it cannot be found in the database.', handle, lTags())
return
diff --git a/server/core/middlewares/validators/account.ts b/server/core/middlewares/validators/account.ts
index a3ae023576..e31016414f 100644
--- a/server/core/middlewares/validators/account.ts
+++ b/server/core/middlewares/validators/account.ts
@@ -15,7 +15,7 @@ export const accountHandleGetValidatorFactory = (options: {
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
- if (!await doesAccountHandleExist({ handle: req.params.accountName, res, checkIsLocal, checkManage })) return
+ if (!await doesAccountHandleExist({ handle: req.params.handle, res, checkIsLocal, checkManage })) return
if (options.checkManage) {
const user = res.locals.oauth.token.User
diff --git a/server/core/middlewares/validators/follows.ts b/server/core/middlewares/validators/follows.ts
index a124dcf27c..76571e594a 100644
--- a/server/core/middlewares/validators/follows.ts
+++ b/server/core/middlewares/validators/follows.ts
@@ -53,7 +53,6 @@ const followValidator = [
const body: ServerFollowCreate = req.body
if (body.hosts.length === 0 && body.handles.length === 0) {
-
return res
.status(HttpStatusCode.BAD_REQUEST_400)
.json({
@@ -94,7 +93,7 @@ const removeFollowingValidator = [
]
const getFollowerValidator = [
- param('nameWithHost')
+ param('handle')
.custom(isValidActorHandle),
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
@@ -102,19 +101,19 @@ const getFollowerValidator = [
let follow: MActorFollowActorsDefault
try {
- const actorUrl = await loadActorUrlOrGetFromWebfinger(req.params.nameWithHost)
+ const actorUrl = await loadActorUrlOrGetFromWebfinger(req.params.handle)
const actor = await ActorModel.loadByUrl(actorUrl)
const serverActor = await getServerActor()
follow = await ActorFollowModel.loadByActorAndTarget(actor.id, serverActor.id)
} catch (err) {
- logger.warn('Cannot get actor from handle.', { handle: req.params.nameWithHost, err })
+ logger.warn('Cannot get actor from handle.', { handle: req.params.handle, err })
}
if (!follow) {
return res.fail({
status: HttpStatusCode.NOT_FOUND_404,
- message: `Follower ${req.params.nameWithHost} not found.`
+ message: `Follower ${req.params.handle} not found.`
})
}
diff --git a/server/core/middlewares/validators/shared/accounts.ts b/server/core/middlewares/validators/shared/accounts.ts
index 29fcecf7e2..17e5a8be64 100644
--- a/server/core/middlewares/validators/shared/accounts.ts
+++ b/server/core/middlewares/validators/shared/accounts.ts
@@ -26,7 +26,7 @@ export async function doesAccountHandleExist (options: {
}) {
const { handle, res, checkIsLocal, checkManage } = options
- const account = await AccountModel.loadByNameWithHost(handle)
+ const account = await AccountModel.loadByHandle(handle)
return doesAccountExist({ account, res, checkIsLocal, checkManage })
}
diff --git a/server/core/middlewares/validators/videos/video-channels.ts b/server/core/middlewares/validators/videos/video-channels.ts
index a39e9b1318..1c4c96abb0 100644
--- a/server/core/middlewares/validators/videos/video-channels.ts
+++ b/server/core/middlewares/validators/videos/video-channels.ts
@@ -51,9 +51,6 @@ export const videoChannelsAddValidator = [
]
export const videoChannelsUpdateValidator = [
- param('nameWithHost')
- .exists(),
-
body('displayName')
.optional()
.custom(isVideoChannelDisplayNameValid),
@@ -95,7 +92,7 @@ export const videoChannelsHandleValidatorFactory = (options: {
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
- if (!await doesChannelHandleExist({ handle: req.params.nameWithHost, checkManage, checkIsLocal, res })) return
+ if (!await doesChannelHandleExist({ handle: req.params.handle, checkManage, checkIsLocal, res })) return
return next()
}
diff --git a/server/core/middlewares/validators/videos/video-rates.ts b/server/core/middlewares/validators/videos/video-rates.ts
index 6adbf1a6e1..4f49dd206d 100644
--- a/server/core/middlewares/validators/videos/video-rates.ts
+++ b/server/core/middlewares/validators/videos/video-rates.ts
@@ -28,7 +28,7 @@ const videoUpdateRateValidator = [
const getAccountVideoRateValidatorFactory = function (rateType: VideoRateType) {
return [
- param('name')
+ param('accountName')
.custom(isAccountNameValid),
param('videoId')
.custom(isIdValid),
@@ -36,7 +36,7 @@ const getAccountVideoRateValidatorFactory = function (rateType: VideoRateType) {
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (areValidationErrors(req, res)) return
- const rate = await AccountVideoRateModel.loadLocalAndPopulateVideo(rateType, req.params.name, +req.params.videoId)
+ const rate = await AccountVideoRateModel.loadLocalAndPopulateVideo(rateType, req.params.accountName, +req.params.videoId)
if (!rate) {
return res.fail({
status: HttpStatusCode.NOT_FOUND_404,
diff --git a/server/core/middlewares/validators/webfinger.ts b/server/core/middlewares/validators/webfinger.ts
index 63855bbf38..b637d1db79 100644
--- a/server/core/middlewares/validators/webfinger.ts
+++ b/server/core/middlewares/validators/webfinger.ts
@@ -14,8 +14,8 @@ const webfingerValidator = [
if (areValidationErrors(req, res)) return
// Remove 'acct:' from the beginning of the string
- const nameWithHost = getHostWithPort(req.query.resource.substr(5))
- const [ name ] = nameWithHost.split('@')
+ const handle = getHostWithPort(req.query.resource.substr(5))
+ const [ name ] = handle.split('@')
const actor = await ActorModel.loadLocalUrlByName(name)
if (!actor) {
diff --git a/server/core/models/account/account.ts b/server/core/models/account/account.ts
index c5b82aca7d..c2598d57ad 100644
--- a/server/core/models/account/account.ts
+++ b/server/core/models/account/account.ts
@@ -302,8 +302,8 @@ export class AccountModel extends SequelizeModel<AccountModel> {
return AccountModel.findByPk(id, { transaction })
}
- static loadByNameWithHost (nameWithHost: string): Promise<MAccountDefault> {
- const [ accountName, host ] = nameWithHost.split('@')
+ static loadByHandle (handle: string): Promise<MAccountDefault> {
+ const [ accountName, host ] = handle.split('@')
if (!host || host === WEBSERVER.HOST) return AccountModel.loadLocalByName(accountName)
diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yaml
index f73c4b7813..0e4a3f2a42 100644
--- a/support/doc/api/openapi.yaml
+++ b/support/doc/api/openapi.yaml
@@ -1202,7 +1202,7 @@ paths:
items:
$ref: '#/components/schemas/Follow'
- '/api/v1/server/followers/{nameWithHost}':
+ '/api/v1/server/followers/{handle}':
delete:
summary: Remove or reject a follower to your server
security:
@@ -1211,7 +1211,7 @@ paths:
tags:
- Instance Follows
parameters:
- - name: nameWithHost
+ - name: handle
in: path
required: true
description: The remote actor handle to remove from your followers
@@ -1224,7 +1224,7 @@ paths:
'404':
description: follower not found
- '/api/v1/server/followers/{nameWithHost}/reject':
+ '/api/v1/server/followers/{handle}/reject':
post:
summary: Reject a pending follower to your server
security:
@@ -1233,7 +1233,7 @@ paths:
tags:
- Instance Follows
parameters:
- - name: nameWithHost
+ - name: handle
in: path
required: true
description: The remote actor handle to remove from your followers
@@ -1246,7 +1246,7 @@ paths:
'404':
description: follower not found
- '/api/v1/server/followers/{nameWithHost}/accept':
+ '/api/v1/server/followers/{handle}/accept':
post:
summary: Accept a pending follower to your server
security:
@@ -1255,7 +1255,7 @@ paths:
tags:
- Instance Follows
parameters:
- - name: nameWithHost
+ - name: handle
in: path
required: true
description: The remote actor handle to remove from your followers