import { Subscription } from 'rxjs/Subscription'
import { AuthService } from '../../core/auth'
import { ComponentPagination } from '../rest/component-pagination.model'
-import { SortField } from './sort-field.type'
+import { VideoSortField } from './sort-field.type'
import { Video } from './video.model'
export abstract class AbstractVideoList implements OnInit, OnDestroy {
itemsPerPage: 10,
totalItems: null
}
- sort: SortField = '-createdAt'
- defaultSort: SortField = '-createdAt'
+ sort: VideoSortField = '-createdAt'
+ defaultSort: VideoSortField = '-createdAt'
syndicationItems = []
loadOnInit = true
}
protected loadRouteParams (routeParams: { [ key: string ]: any }) {
- this.sort = routeParams['sort'] as SortField || this.defaultSort
+ this.sort = routeParams['sort'] as VideoSortField || this.defaultSort
if (routeParams['page'] !== undefined) {
this.pagination.currentPage = parseInt(routeParams['page'], 10)
-export type SortField = 'name' | '-name'
+export type VideoSortField = 'name' | '-name'
| 'duration' | '-duration'
| 'createdAt' | '-createdAt'
| 'views' | '-views'
import { RestExtractor } from '../rest/rest-extractor.service'
import { RestService } from '../rest/rest.service'
import { UserService } from '../users/user.service'
-import { SortField } from './sort-field.type'
+import { VideoSortField } from './sort-field.type'
import { VideoDetails } from './video-details.model'
import { VideoEdit } from './video-edit.model'
import { Video } from './video.model'
.catch(this.restExtractor.handleError)
}
- getMyVideos (videoPagination: ComponentPagination, sort: SortField): Observable<{ videos: Video[], totalVideos: number}> {
+ getMyVideos (videoPagination: ComponentPagination, sort: VideoSortField): Observable<{ videos: Video[], totalVideos: number}> {
const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
let params = new HttpParams()
getVideos (
videoPagination: ComponentPagination,
- sort: SortField,
+ sort: VideoSortField,
filter?: VideoFilter
): Observable<{ videos: Video[], totalVideos: number}> {
const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
.catch((res) => this.restExtractor.handleError(res))
}
- buildBaseFeedUrls () {
+ buildBaseFeedUrls (params: HttpParams) {
const feeds = [
{
label: 'rss 2.0',
}
]
+ if (params && params.keys().length !== 0) {
+ for (const feed of feeds) {
+ feed.url += '?' + params.toString()
+ }
+ }
+
return feeds
}
- getVideoFeedUrls (filter?: VideoFilter) {
- let params = this.restService.addRestGetParams(new HttpParams())
- const feeds = this.buildBaseFeedUrls()
+ getVideoFeedUrls (sort: VideoSortField, filter?: VideoFilter) {
+ let params = this.restService.addRestGetParams(new HttpParams(), undefined, sort)
if (filter) params = params.set('filter', filter)
- if (params.keys().length !== 0) {
- for (let item of feeds) {
- item.url += `?${params.toString()}`
- }
- }
-
- return feeds
+ return this.buildBaseFeedUrls(params)
}
getAccountFeedUrls (accountId: number) {
let params = this.restService.addRestGetParams(new HttpParams())
- const feeds = this.buildBaseFeedUrls()
-
params = params.set('accountId', accountId.toString())
- if (params.keys().length !== 0) {
- for (let item of feeds) {
- item.url += `?${params.toString()}`
- }
- }
-
- return feeds
+ return this.buildBaseFeedUrls(params)
}
searchVideos (
search: string,
videoPagination: ComponentPagination,
- sort: SortField
+ sort: VideoSortField
): Observable<{ videos: Video[], totalVideos: number}> {
const url = VideoService.BASE_VIDEO_URL + 'search'
import { environment } from '../../../../environments/environment'
import { RestExtractor, RestService } from '../../../shared/rest'
import { ComponentPagination } from '../../../shared/rest/component-pagination.model'
-import { SortField } from '../../../shared/video/sort-field.type'
+import { VideoSortField } from '../../../shared/video/sort-field.type'
import { VideoComment } from './video-comment.model'
@Injectable()
getVideoCommentThreads (
videoId: number | string,
componentPagination: ComponentPagination,
- sort: SortField
+ sort: VideoSortField
): Observable<{ comments: VideoComment[], totalComments: number}> {
const pagination = this.restService.componentPaginationToRestPagination(componentPagination)
import { AuthService } from '../../../core/auth'
import { ComponentPagination } from '../../../shared/rest/component-pagination.model'
import { User } from '../../../shared/users'
-import { SortField } from '../../../shared/video/sort-field.type'
+import { VideoSortField } from '../../../shared/video/sort-field.type'
import { VideoDetails } from '../../../shared/video/video-details.model'
import { VideoComment } from './video-comment.model'
import { VideoCommentService } from './video-comment.service'
comments: VideoComment[] = []
highlightedThread: VideoComment
- sort: SortField = '-createdAt'
+ sort: VideoSortField = '-createdAt'
componentPagination: ComponentPagination = {
currentPage: 1,
itemsPerPage: 10,
import { immutableAssign } from '@app/shared/misc/utils'
import { NotificationsService } from 'angular2-notifications'
import { AuthService } from '../../core/auth'
-import { PopoverModule } from 'ngx-bootstrap/popover'
import { AbstractVideoList } from '../../shared/video/abstract-video-list'
-import { SortField } from '../../shared/video/sort-field.type'
+import { VideoSortField } from '../../shared/video/sort-field.type'
import { VideoService } from '../../shared/video/video.service'
-import { FeedFormat } from '../../../../../shared/models/feeds/feed-format.enum'
-import * as url from 'url'
+import { VideoFilter } from '../../../../../shared/models/videos/video-query.type'
@Component({
selector: 'my-videos-local',
export class VideoLocalComponent extends AbstractVideoList implements OnInit, OnDestroy {
titlePage = 'Local videos'
currentRoute = '/videos/local'
- sort = '-createdAt' as SortField
+ sort = '-createdAt' as VideoSortField
+ filter: VideoFilter = 'local'
constructor (protected router: Router,
protected route: ActivatedRoute,
getVideosObservable (page: number) {
const newPagination = immutableAssign(this.pagination, { currentPage: page })
- return this.videoService.getVideos(newPagination, this.sort, 'local')
+ return this.videoService.getVideos(newPagination, this.sort, this.filter)
}
generateSyndicationList () {
- this.syndicationItems = this.videoService.getVideoFeedUrls('local')
+ this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, this.filter)
}
}
import { NotificationsService } from 'angular2-notifications'
import { AuthService } from '../../core/auth'
import { AbstractVideoList } from '../../shared/video/abstract-video-list'
-import { SortField } from '../../shared/video/sort-field.type'
+import { VideoSortField } from '../../shared/video/sort-field.type'
import { VideoService } from '../../shared/video/video.service'
-import { FeedFormat } from '../../../../../shared/models/feeds/feed-format.enum'
-import * as url from 'url'
@Component({
selector: 'my-videos-recently-added',
export class VideoRecentlyAddedComponent extends AbstractVideoList implements OnInit, OnDestroy {
titlePage = 'Recently added'
currentRoute = '/videos/recently-added'
- sort: SortField = '-createdAt'
+ sort: VideoSortField = '-createdAt'
constructor (protected router: Router,
protected route: ActivatedRoute,
}
generateSyndicationList () {
- this.syndicationItems = this.videoService.getVideoFeedUrls()
+ this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort)
}
}
import { NotificationsService } from 'angular2-notifications'
import { AuthService } from '../../core/auth'
import { AbstractVideoList } from '../../shared/video/abstract-video-list'
-import { SortField } from '../../shared/video/sort-field.type'
+import { VideoSortField } from '../../shared/video/sort-field.type'
import { VideoService } from '../../shared/video/video.service'
@Component({
export class VideoTrendingComponent extends AbstractVideoList implements OnInit, OnDestroy {
titlePage = 'Trending'
currentRoute = '/videos/trending'
- defaultSort: SortField = '-views'
+ defaultSort: VideoSortField = '-views'
constructor (protected router: Router,
protected route: ActivatedRoute,
}
generateSyndicationList () {
- this.syndicationItems = this.videoService.getVideoFeedUrls()
+ this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort)
}
}
async function getUserVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
const user = res.locals.oauth.token.User as UserModel
- const resultList = await VideoModel.listUserVideosForApi(user.id ,req.query.start, req.query.count, req.query.sort)
+ const resultList = await VideoModel.listAccountVideosForApi(user.Account.id ,req.query.start, req.query.count, req.query.sort)
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
import * as express from 'express'
import { CONFIG } from '../initializers'
-import { asyncMiddleware, feedsValidator } from '../middlewares'
+import {
+ asyncMiddleware,
+ feedsValidator,
+ setDefaultPagination,
+ setDefaultSort,
+ videosSortValidator
+} from '../middlewares'
import { VideoModel } from '../models/video/video'
import * as Feed from 'pfeed'
import { ResultList } from '../../shared/models'
const feedsRouter = express.Router()
feedsRouter.get('/feeds/videos.:format',
+ videosSortValidator,
+ setDefaultSort,
asyncMiddleware(feedsValidator),
asyncMiddleware(generateFeed)
)
async function generateFeed (req: express.Request, res: express.Response, next: express.NextFunction) {
let feed = initFeed()
- let feedStart = 0
- let feedCount = 10
- let feedSort = '-createdAt'
+ const paginationStart = 0
+ const paginationCount = 20
let resultList: ResultList<VideoModel>
const account: AccountModel = res.locals.account
if (account) {
- resultList = await VideoModel.listUserVideosForApi(
+ resultList = await VideoModel.listAccountVideosForApi(
account.id,
- feedStart,
- feedCount,
- feedSort,
+ paginationStart,
+ paginationCount,
+ req.query.sort,
true
)
} else {
resultList = await VideoModel.listForApi(
- feedStart,
- feedCount,
- feedSort,
+ paginationStart,
+ paginationCount,
+ req.query.sort,
req.query.filter,
true
)
rss: `${webserverUrl}/feeds/videos.xml`
},
author: {
- name: 'instance admin of ' + CONFIG.INSTANCE.NAME,
+ name: 'Instance admin of ' + CONFIG.INSTANCE.NAME,
email: CONFIG.ADMIN.EMAIL,
link: `${webserverUrl}/about`
}
})
}
- static listUserVideosForApi (userId: number, start: number, count: number, sort: string, withFiles = false) {
+ static listAccountVideosForApi (accountId: number, start: number, count: number, sort: string, withFiles = false) {
const query: IFindOptions<VideoModel> = {
offset: start,
limit: count,
{
model: AccountModel,
where: {
- userId
+ id: accountId
},
required: true
}