aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/shared
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/videos/shared')
-rw-r--r--client/src/app/videos/shared/index.ts1
-rw-r--r--client/src/app/videos/shared/markdown.service.ts40
-rw-r--r--client/src/app/videos/shared/video-edit.model.ts15
-rw-r--r--client/src/app/videos/shared/video.service.ts2
4 files changed, 57 insertions, 1 deletions
diff --git a/client/src/app/videos/shared/index.ts b/client/src/app/videos/shared/index.ts
index dcaa4e090..09d961dd3 100644
--- a/client/src/app/videos/shared/index.ts
+++ b/client/src/app/videos/shared/index.ts
@@ -1,4 +1,5 @@
1export * from './sort-field.type' 1export * from './sort-field.type'
2export * from './markdown.service'
2export * from './video.model' 3export * from './video.model'
3export * from './video-details.model' 4export * from './video-details.model'
4export * from './video-edit.model' 5export * from './video-edit.model'
diff --git a/client/src/app/videos/shared/markdown.service.ts b/client/src/app/videos/shared/markdown.service.ts
new file mode 100644
index 000000000..d8b5b76b6
--- /dev/null
+++ b/client/src/app/videos/shared/markdown.service.ts
@@ -0,0 +1,40 @@
1import { Injectable } from '@angular/core'
2
3import * as MarkdownIt from 'markdown-it'
4
5@Injectable()
6export class MarkdownService {
7 private markdownIt: MarkdownIt.MarkdownIt
8
9 constructor () {
10 this.markdownIt = new MarkdownIt('zero', { linkify: true })
11 .enable('linkify')
12 .enable('autolink')
13 .enable('emphasis')
14 .enable('link')
15 .enable('newline')
16
17 // Snippet from markdown-it documentation: https://github.com/markdown-it/markdown-it/blob/master/docs/architecture.md#renderer
18 const defaultRender = this.markdownIt.renderer.rules.link_open || function (tokens, idx, options, env, self) {
19 return self.renderToken(tokens, idx, options)
20 }
21
22 this.markdownIt.renderer.rules.link_open = function (tokens, idx, options, env, self) {
23 // If you are sure other plugins can't add `target` - drop check below
24 const aIndex = tokens[idx].attrIndex('target')
25
26 if (aIndex < 0) {
27 tokens[idx].attrPush(['target', '_blank']) // add new attribute
28 } else {
29 tokens[idx].attrs[aIndex][1] = '_blank' // replace value of existing attr
30 }
31
32 // pass token to default renderer.
33 return defaultRender(tokens, idx, options, env, self)
34 }
35 }
36
37 markdownToHTML (markdown: string) {
38 return this.markdownIt.render(markdown)
39 }
40}
diff --git a/client/src/app/videos/shared/video-edit.model.ts b/client/src/app/videos/shared/video-edit.model.ts
index f30d8feba..e0b7bf130 100644
--- a/client/src/app/videos/shared/video-edit.model.ts
+++ b/client/src/app/videos/shared/video-edit.model.ts
@@ -1,3 +1,5 @@
1import { VideoDetails } from './video-details.model'
2
1export class VideoEdit { 3export class VideoEdit {
2 category: number 4 category: number
3 licence: number 5 licence: number
@@ -10,6 +12,19 @@ export class VideoEdit {
10 uuid?: string 12 uuid?: string
11 id?: number 13 id?: number
12 14
15 constructor (videoDetails: VideoDetails) {
16 this.id = videoDetails.id
17 this.uuid = videoDetails.uuid
18 this.category = videoDetails.category
19 this.licence = videoDetails.licence
20 this.language = videoDetails.language
21 this.description = videoDetails.description
22 this.name = videoDetails.name
23 this.tags = videoDetails.tags
24 this.nsfw = videoDetails.nsfw
25 this.channel = videoDetails.channel.id
26 }
27
13 patch (values: Object) { 28 patch (values: Object) {
14 Object.keys(values).forEach((key) => { 29 Object.keys(values).forEach((key) => {
15 this[key] = values[key] 30 this[key] = values[key]
diff --git a/client/src/app/videos/shared/video.service.ts b/client/src/app/videos/shared/video.service.ts
index 06fb3313e..8fdc1f213 100644
--- a/client/src/app/videos/shared/video.service.ts
+++ b/client/src/app/videos/shared/video.service.ts
@@ -36,7 +36,7 @@ export class VideoService {
36 private restService: RestService 36 private restService: RestService
37 ) {} 37 ) {}
38 38
39 getVideo (uuid: string) { 39 getVideo (uuid: string): Observable<VideoDetails> {
40 return this.authHttp.get<VideoDetailsServerModel>(VideoService.BASE_VIDEO_URL + uuid) 40 return this.authHttp.get<VideoDetailsServerModel>(VideoService.BASE_VIDEO_URL + uuid)
41 .map(videoHash => new VideoDetails(videoHash)) 41 .map(videoHash => new VideoDetails(videoHash))
42 .catch((res) => this.restExtractor.handleError(res)) 42 .catch((res) => this.restExtractor.handleError(res))