Verified Commit 88b36255 authored by Chocobozzz's avatar Chocobozzz
Browse files

Support short uuid for GET video/playlist

parent 62ddc31a
......@@ -122,7 +122,7 @@ export class VideoBlockListComponent extends RestTable implements OnInit {
}
getVideoUrl (videoBlock: VideoBlacklist) {
return Video.buildClientUrl(videoBlock.video.uuid)
return Video.buildWatchUrl(videoBlock.video)
}
toHtml (text: string) {
......
import { SortMeta } from 'primeng/api'
import { Component, OnInit } from '@angular/core'
import { Notifier, RestPagination, RestTable } from '@app/core'
import { VideoImportService } from '@app/shared/shared-main'
import { Video, VideoImportService } from '@app/shared/shared-main'
import { VideoImport, VideoImportState } from '@shared/models'
@Component({
......@@ -55,11 +55,11 @@ export class MyVideoImportsComponent extends RestTable implements OnInit {
}
getVideoUrl (video: { uuid: string }) {
return '/w/' + video.uuid
return Video.buildWatchUrl(video)
}
getEditVideoUrl (video: { uuid: string }) {
return '/videos/update/' + video.uuid
return Video.buildUpdateUrl(video)
}
protected reloadData () {
......
import { forkJoin } from 'rxjs'
import { Component, OnInit } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
import { VideoChannel } from '@app/shared/shared-main'
import { Video, VideoChannel } from '@app/shared/shared-main'
import { SearchService } from '@app/shared/shared-search'
@Component({
......@@ -39,7 +39,7 @@ export class RemoteInteractionComponent implements OnInit {
if (videoResult.data.length !== 0) {
const video = videoResult.data[0]
redirectUrl = '/w/' + video.uuid
redirectUrl = Video.buildWatchUrl(video)
} else if (channelResult.data.length !== 0) {
const channel = new VideoChannel(channelResult.data[0])
......
import { Observable } from 'rxjs'
import { map } from 'rxjs/operators'
import { ActivatedRouteSnapshot, Resolve, Router } from '@angular/router'
import { ResultList } from '@shared/models/result-list.model'
import { ResultList } from '@shared/models'
export abstract class AbstractLazyLoadResolver <T> implements Resolve<any> {
protected router: Router
......
......@@ -19,6 +19,6 @@ export class PlaylistLazyLoadResolver extends AbstractLazyLoadResolver<VideoPlay
}
protected buildUrl (playlist: VideoPlaylist) {
return '/w/p/' + playlist.uuid
return VideoPlaylist.buildWatchUrl(playlist)
}
}
......@@ -19,6 +19,6 @@ export class VideoLazyLoadResolver extends AbstractLazyLoadResolver<Video> {
}
protected buildUrl (video: Video) {
return '/w/' + video.uuid
return Video.buildWatchUrl(video)
}
}
import { forkJoin } from 'rxjs'
import { AfterViewChecked, AfterViewInit, Component, EventEmitter, OnInit, Output } from '@angular/core'
import { AfterViewInit, Component, EventEmitter, OnInit, Output } from '@angular/core'
import { Router } from '@angular/router'
import { AuthService, CanComponentDeactivate, HooksService, Notifier, ServerService } from '@app/core'
import { scrollToTop } from '@app/helpers'
import { FormValidatorService } from '@app/shared/shared-forms'
import { VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
import { Video, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
import { LiveVideoService } from '@app/shared/shared-video-live'
import { LoadingBarService } from '@ngx-loading-bar/core'
import { LiveVideo, LiveVideoCreate, LiveVideoUpdate, PeerTubeProblemDocument, ServerErrorCode, VideoPrivacy } from '@shared/models'
......@@ -127,7 +127,7 @@ export class VideoGoLiveComponent extends VideoSend implements OnInit, AfterView
() => {
this.notifier.success($localize`Live published.`)
this.router.navigate(['/w', video.uuid])
this.router.navigateByUrl(Video.buildWatchUrl(video))
},
err => {
......
import { UploadState, UploadxOptions, UploadxService } from 'ngx-uploadx'
import { HttpErrorResponse, HttpEventType, HttpHeaders } from '@angular/common/http'
import { AfterViewInit, Component, ElementRef, EventEmitter, OnDestroy, OnInit, Output, ViewChild } from '@angular/core'
import { Router } from '@angular/router'
import { UploadxOptions, UploadState, UploadxService } from 'ngx-uploadx'
import { UploaderXFormData } from './uploaderx-form-data'
import { AuthService, CanComponentDeactivate, HooksService, Notifier, ServerService, UserService } from '@app/core'
import { scrollToTop, genericUploadErrorHandler } from '@app/helpers'
import { genericUploadErrorHandler, scrollToTop } from '@app/helpers'
import { FormValidatorService } from '@app/shared/shared-forms'
import { BytesPipe, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
import { BytesPipe, Video, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
import { LoadingBarService } from '@ngx-loading-bar/core'
import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
import { VideoPrivacy } from '@shared/models'
import { UploaderXFormData } from './uploaderx-form-data'
import { VideoSend } from './video-send'
import { HttpErrorResponse, HttpEventType, HttpHeaders } from '@angular/common/http'
@Component({
selector: 'my-video-upload',
......@@ -243,7 +243,7 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
this.isUploadingVideo = false
this.notifier.success($localize`Video published.`)
this.router.navigate([ '/w', video.uuid ])
this.router.navigateByUrl(Video.buildWatchUrl(video))
},
err => {
......
<div class="margin-content">
<div class="title-page title-page-single">
<span class="mr-1" i18n>Update</span>
<a [routerLink]="[ '/w', video.uuid ]">{{ video?.name }}</a>
<a [routerLink]="getVideoUrl()">{{ video?.name }}</a>
</div>
<form novalidate [formGroup]="form">
......
......@@ -5,7 +5,7 @@ import { Component, HostListener, OnInit } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
import { Notifier } from '@app/core'
import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
import { VideoCaptionEdit, VideoCaptionService, VideoDetails, VideoEdit, VideoService } from '@app/shared/shared-main'
import { Video, VideoCaptionEdit, VideoCaptionService, VideoDetails, VideoEdit, VideoService } from '@app/shared/shared-main'
import { LiveVideoService } from '@app/shared/shared-video-live'
import { LoadingBarService } from '@ngx-loading-bar/core'
import { LiveVideo, LiveVideoUpdate, VideoPrivacy } from '@shared/models'
......@@ -156,7 +156,7 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
this.isUpdatingVideo = false
this.loadingBar.useRef().complete()
this.notifier.success($localize`Video updated.`)
this.router.navigate([ '/w', this.video.uuid ])
this.router.navigateByUrl(Video.buildWatchUrl(this.video))
},
err => {
......@@ -175,4 +175,8 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
pluginData: this.video.pluginData
})
}
getVideoUrl () {
return Video.buildWatchUrl(this.videoDetails)
}
}
......@@ -20,7 +20,7 @@
</a>
</div>
<a [routerLink]="['/w', video.uuid, { 'threadId': comment.threadId }]" class="comment-date" [title]="comment.createdAt">
<a [routerLink]="['/w', video.shortUUID, { 'threadId': comment.threadId }]" class="comment-date" [title]="comment.createdAt">
{{ comment.createdAt | myFromNow }}
</a>
</div>
......@@ -45,7 +45,7 @@
<ng-container *ngIf="comment.isDeleted">
<div class="comment-account-date">
<span class="comment-account" i18n>Deleted</span>
<a [routerLink]="['/w', video.uuid, { 'threadId': comment.threadId }]"
<a [routerLink]="['/w', video.shortUUID, { 'threadId': comment.threadId }]"
class="comment-date">{{ comment.createdAt | myFromNow }}</a>
</div>
......
......@@ -247,7 +247,7 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
this.componentPagination.totalItems = null
this.totalNotDeletedComments = null
this.syndicationItems = this.videoCommentService.getVideoCommentsFeeds(this.video.uuid)
this.syndicationItems = this.videoCommentService.getVideoCommentsFeeds(this.video)
this.loadMoreThreads()
}
}
......
......@@ -312,7 +312,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
getVideoUrl () {
if (!this.video.url) {
return this.video.originInstanceUrl + VideoDetails.buildClientUrl(this.video.uuid)
return this.video.originInstanceUrl + VideoDetails.buildWatchUrl(this.video)
}
return this.video.url
}
......@@ -415,7 +415,10 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
private loadVideo (videoId: string) {
// Video did not change
if (this.video && this.video.uuid === videoId) return
if (
this.video &&
(this.video.uuid === videoId || this.video.shortUUID === videoId)
) return
if (this.player) this.player.pause()
......@@ -489,7 +492,10 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
private loadPlaylist (playlistId: string) {
// Playlist did not change
if (this.playlist && this.playlist.uuid === playlistId) return
if (
this.playlist &&
(this.playlist.uuid === playlistId || this.playlist.shortUUID === playlistId)
) return
this.playlistService.getVideoPlaylist(playlistId)
.pipe(
......@@ -772,13 +778,13 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
private flushPlayer () {
// Remove player if it exists
if (this.player) {
try {
this.player.dispose()
this.player = undefined
} catch (err) {
console.error('Cannot dispose player.', err)
}
if (!this.player) return
try {
this.player.dispose()
this.player = undefined
} catch (err) {
console.error('Cannot dispose player.', err)
}
}
......
......@@ -116,11 +116,11 @@ export class AbuseListTableComponent extends RestTable implements OnInit {
}
getVideoUrl (abuse: AdminAbuse) {
return Video.buildClientUrl(abuse.video.uuid)
return Video.buildWatchUrl(abuse.video)
}
getCommentUrl (abuse: AdminAbuse) {
return Video.buildClientUrl(abuse.comment.video.uuid) + ';threadId=' + abuse.comment.threadId
return Video.buildWatchUrl(abuse.comment.video) + ';threadId=' + abuse.comment.threadId
}
getAccountUrl (abuse: ProcessedAbuse) {
......
......@@ -6,7 +6,7 @@ import { Component, Input, ViewEncapsulation } from '@angular/core'
templateUrl: './link.component.html'
})
export class LinkComponent {
@Input() internalLink?: any[]
@Input() internalLink?: string | any[]
@Input() href?: string
@Input() target?: string
......
......@@ -12,6 +12,7 @@ import {
UserRight,
VideoInfo
} from '@shared/models'
import { Video } from '../video'
export class UserNotification implements UserNotificationServer {
id: number
......@@ -238,7 +239,7 @@ export class UserNotification implements UserNotificationServer {
}
private buildVideoUrl (video: { uuid: string }) {
return '/w/' + video.uuid
return Video.buildWatchUrl(video)
}
private buildAccountUrl (account: { name: string, host: string }) {
......
......@@ -26,12 +26,18 @@ export class Video implements VideoServerModel {
licence: VideoConstant<number>
language: VideoConstant<string>
privacy: VideoConstant<VideoPrivacy>
description: string
duration: number
durationLabel: string
id: number
uuid: string
shortUUID: string
isLocal: boolean
name: string
serverHost: string
thumbnailPath: string
......@@ -85,8 +91,12 @@ export class Video implements VideoServerModel {
pluginData?: any
static buildClientUrl (videoUUID: string) {
return '/w/' + videoUUID
static buildWatchUrl (video: Partial<Pick<Video, 'uuid' | 'shortUUID'>>) {
return '/w/' + (video.shortUUID || video.uuid)
}
static buildUpdateUrl (video: Pick<Video, 'uuid'>) {
return '/videos/update/' + video.uuid
}
constructor (hash: VideoServerModel, translations = {}) {
......@@ -109,6 +119,7 @@ export class Video implements VideoServerModel {
this.id = hash.id
this.uuid = hash.uuid
this.shortUUID = hash.shortUUID
this.isLocal = hash.isLocal
this.name = hash.name
......
import { Component, ElementRef, Input, ViewChild } from '@angular/core'
import { VideoDetails } from '@app/shared/shared-main'
import { Video, VideoDetails } from '@app/shared/shared-main'
import { VideoPlaylist } from '@app/shared/shared-video-playlist'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { VideoCaption } from '@shared/models'
......@@ -98,14 +98,15 @@ export class VideoShareComponent {
getVideoUrl () {
let baseUrl = this.customizations.originUrl ? this.video.originInstanceUrl : window.location.origin
baseUrl += '/w/' + this.video.uuid
baseUrl += Video.buildWatchUrl(this.video)
const options = this.getVideoOptions(baseUrl)
return buildVideoLink(options)
}
getPlaylistUrl () {
const base = window.location.origin + '/w/p/' + this.playlist.uuid
const base = window.location.origin + VideoPlaylist.buildWatchUrl(this.playlist)
if (!this.includeVideoInPlaylist) return base
......
......@@ -12,7 +12,7 @@ export class VideoThumbnailComponent {
@Input() video: Video
@Input() nsfw = false
@Input() videoRouterLink: any[]
@Input() videoRouterLink: string | any[]
@Input() queryParams: { [ p: string ]: any }
@Input() videoHref: string
@Input() videoTarget: string
......@@ -57,7 +57,7 @@ export class VideoThumbnailComponent {
getVideoRouterLink () {
if (this.videoRouterLink) return this.videoRouterLink
return [ '/w', this.video.uuid ]
return Video.buildWatchUrl(this.video)
}
onWatchLaterClick (event: Event) {
......
import { getAbsoluteAPIUrl } from '@app/helpers'
import { Account, Actor } from '@app/shared/shared-main'
import { Account, Actor, Video } from '@app/shared/shared-main'
import { Account as AccountInterface, VideoComment as VideoCommentServerModel, VideoCommentAdmin as VideoCommentAdminServerModel } from '@shared/models'
export class VideoComment implements VideoCommentServerModel {
......@@ -85,7 +85,7 @@ export class VideoCommentAdmin implements VideoCommentAdminServerModel {
id: hash.video.id,
uuid: hash.video.uuid,
name: hash.video.name,
localUrl: '/w/' + hash.video.uuid
localUrl: Video.buildWatchUrl(hash.video)
}
this.localUrl = this.video.localUrl + ';threadId=' + this.threadId
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment