mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 10:19:35 +02:00
Add ability to search video channels
This commit is contained in:
parent
240085d005
commit
f37dc0dd14
35 changed files with 670 additions and 145 deletions
|
@ -20,7 +20,8 @@ import {
|
|||
deleteMeValidator,
|
||||
userSubscriptionsSortValidator,
|
||||
videoImportsSortValidator,
|
||||
videosSortValidator
|
||||
videosSortValidator,
|
||||
areSubscriptionsExistValidator
|
||||
} from '../../../middlewares/validators'
|
||||
import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
|
||||
import { UserModel } from '../../../models/account/user'
|
||||
|
@ -98,7 +99,6 @@ meRouter.post('/me/avatar/pick',
|
|||
// ##### Subscriptions part #####
|
||||
|
||||
meRouter.get('/me/subscriptions/videos',
|
||||
authenticate,
|
||||
authenticate,
|
||||
paginationValidator,
|
||||
videosSortValidator,
|
||||
|
@ -108,6 +108,12 @@ meRouter.get('/me/subscriptions/videos',
|
|||
asyncMiddleware(getUserSubscriptionVideos)
|
||||
)
|
||||
|
||||
meRouter.get('/me/subscriptions/exist',
|
||||
authenticate,
|
||||
areSubscriptionsExistValidator,
|
||||
asyncMiddleware(areSubscriptionsExist)
|
||||
)
|
||||
|
||||
meRouter.get('/me/subscriptions',
|
||||
authenticate,
|
||||
paginationValidator,
|
||||
|
@ -143,6 +149,37 @@ export {
|
|||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function areSubscriptionsExist (req: express.Request, res: express.Response) {
|
||||
const uris = req.query.uris as string[]
|
||||
const user = res.locals.oauth.token.User as UserModel
|
||||
|
||||
const handles = uris.map(u => {
|
||||
let [ name, host ] = u.split('@')
|
||||
if (host === CONFIG.WEBSERVER.HOST) host = null
|
||||
|
||||
return { name, host, uri: u }
|
||||
})
|
||||
|
||||
const results = await ActorFollowModel.listSubscribedIn(user.Account.Actor.id, handles)
|
||||
|
||||
const existObject: { [id: string ]: boolean } = {}
|
||||
for (const handle of handles) {
|
||||
const obj = results.find(r => {
|
||||
const server = r.ActorFollowing.Server
|
||||
|
||||
return r.ActorFollowing.preferredUsername === handle.name &&
|
||||
(
|
||||
(!server && !handle.host) ||
|
||||
(server.host === handle.host)
|
||||
)
|
||||
})
|
||||
|
||||
existObject[handle.uri] = obj !== undefined
|
||||
}
|
||||
|
||||
return res.json(existObject)
|
||||
}
|
||||
|
||||
async function addUserSubscription (req: express.Request, res: express.Response) {
|
||||
const user = res.locals.oauth.token.User as UserModel
|
||||
const [ name, host ] = req.body.uri.split('@')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue