38a3ccc7f8
* feat: show contained playlists under My videos closes #4769 * refactor(server): remove unused types * fixes after code review * fix(client/video-miniature): add to playlist * fix(server/user/me): shortUUID response * Revert "fix(client/video-miniature): add to playlist" This reverts commitf1a0412391
. * fix(client/PlaylistService): caching * Revert "fix(server/user/me): shortUUID response" This reverts commite3f1ee4e33
. * Fix fetching playlists Co-authored-by: Chocobozzz <me@florianbigard.com>
50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
import { uuidToShort } from '@shared/extra-utils'
|
|
import express from 'express'
|
|
import { VideosExistInPlaylists } from '../../../../shared/models/videos/playlist/video-exist-in-playlist.model'
|
|
import { asyncMiddleware, authenticate } from '../../../middlewares'
|
|
import { doVideosInPlaylistExistValidator } from '../../../middlewares/validators/videos/video-playlists'
|
|
import { VideoPlaylistModel } from '../../../models/video/video-playlist'
|
|
|
|
const myVideoPlaylistsRouter = express.Router()
|
|
|
|
myVideoPlaylistsRouter.get('/me/video-playlists/videos-exist',
|
|
authenticate,
|
|
doVideosInPlaylistExistValidator,
|
|
asyncMiddleware(doVideosInPlaylistExist)
|
|
)
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export {
|
|
myVideoPlaylistsRouter
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
async function doVideosInPlaylistExist (req: express.Request, res: express.Response) {
|
|
const videoIds = req.query.videoIds.map(i => parseInt(i + '', 10))
|
|
const user = res.locals.oauth.token.User
|
|
|
|
const results = await VideoPlaylistModel.listPlaylistSummariesOf(user.Account.id, videoIds)
|
|
|
|
const existObject: VideosExistInPlaylists = {}
|
|
|
|
for (const videoId of videoIds) {
|
|
existObject[videoId] = []
|
|
}
|
|
|
|
for (const result of results) {
|
|
for (const element of result.VideoPlaylistElements) {
|
|
existObject[element.videoId].push({
|
|
playlistElementId: element.id,
|
|
playlistId: result.id,
|
|
playlistDisplayName: result.name,
|
|
playlistShortUUID: uuidToShort(result.uuid),
|
|
startTimestamp: element.startTimestamp,
|
|
stopTimestamp: element.stopTimestamp
|
|
})
|
|
}
|
|
}
|
|
|
|
return res.json(existObject)
|
|
}
|