diff options
author | Chocobozzz <me@florianbigard.com> | 2019-01-14 16:48:38 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-01-14 16:48:38 +0100 |
commit | 1506307f2f903ce0f80155072a33345c702b7c76 (patch) | |
tree | 2bd9620c9ac49c1fc167bb09114f6a5fab049704 /client/src/app/videos/+video-watch | |
parent | 9a39392a7e6b3f180104856a4ea893e5baf86a02 (diff) | |
download | PeerTube-1506307f2f903ce0f80155072a33345c702b7c76.tar.gz PeerTube-1506307f2f903ce0f80155072a33345c702b7c76.tar.zst PeerTube-1506307f2f903ce0f80155072a33345c702b7c76.zip |
Increase abuse length to 3000
And correctly handle new lines
Diffstat (limited to 'client/src/app/videos/+video-watch')
6 files changed, 8 insertions, 149 deletions
diff --git a/client/src/app/videos/+video-watch/comment/linkifier.service.ts b/client/src/app/videos/+video-watch/comment/linkifier.service.ts deleted file mode 100644 index 2529c9eaf..000000000 --- a/client/src/app/videos/+video-watch/comment/linkifier.service.ts +++ /dev/null | |||
@@ -1,115 +0,0 @@ | |||
1 | import { Injectable } from '@angular/core' | ||
2 | import { getAbsoluteAPIUrl } from '@app/shared/misc/utils' | ||
3 | // FIXME: use @types/linkify when https://github.com/DefinitelyTyped/DefinitelyTyped/pull/29682/files is merged? | ||
4 | const linkify = require('linkifyjs') | ||
5 | const linkifyHtml = require('linkifyjs/html') | ||
6 | |||
7 | @Injectable() | ||
8 | export class LinkifierService { | ||
9 | |||
10 | static CLASSNAME = 'linkified' | ||
11 | |||
12 | private linkifyOptions = { | ||
13 | className: { | ||
14 | mention: LinkifierService.CLASSNAME + '-mention', | ||
15 | url: LinkifierService.CLASSNAME + '-url' | ||
16 | } | ||
17 | } | ||
18 | |||
19 | constructor () { | ||
20 | // Apply plugin | ||
21 | this.mentionWithDomainPlugin(linkify) | ||
22 | } | ||
23 | |||
24 | linkify (text: string) { | ||
25 | return linkifyHtml(text, this.linkifyOptions) | ||
26 | } | ||
27 | |||
28 | private mentionWithDomainPlugin (linkify: any) { | ||
29 | const TT = linkify.scanner.TOKENS // Text tokens | ||
30 | const { TOKENS: MT, State } = linkify.parser // Multi tokens, state | ||
31 | const MultiToken = MT.Base | ||
32 | const S_START = linkify.parser.start | ||
33 | |||
34 | const TT_AT = TT.AT | ||
35 | const TT_DOMAIN = TT.DOMAIN | ||
36 | const TT_LOCALHOST = TT.LOCALHOST | ||
37 | const TT_NUM = TT.NUM | ||
38 | const TT_COLON = TT.COLON | ||
39 | const TT_SLASH = TT.SLASH | ||
40 | const TT_TLD = TT.TLD | ||
41 | const TT_UNDERSCORE = TT.UNDERSCORE | ||
42 | const TT_DOT = TT.DOT | ||
43 | |||
44 | function MENTION (this: any, value: any) { | ||
45 | this.v = value | ||
46 | } | ||
47 | |||
48 | linkify.inherits(MultiToken, MENTION, { | ||
49 | type: 'mentionWithDomain', | ||
50 | isLink: true, | ||
51 | toHref () { | ||
52 | return getAbsoluteAPIUrl() + '/services/redirect/accounts/' + this.toString().substr(1) | ||
53 | } | ||
54 | }) | ||
55 | |||
56 | const S_AT = S_START.jump(TT_AT) // @ | ||
57 | const S_AT_SYMS = new State() | ||
58 | const S_MENTION = new State(MENTION) | ||
59 | const S_MENTION_DIVIDER = new State() | ||
60 | const S_MENTION_DIVIDER_SYMS = new State() | ||
61 | |||
62 | // @_, | ||
63 | S_AT.on(TT_UNDERSCORE, S_AT_SYMS) | ||
64 | |||
65 | // @_* | ||
66 | S_AT_SYMS | ||
67 | .on(TT_UNDERSCORE, S_AT_SYMS) | ||
68 | .on(TT_DOT, S_AT_SYMS) | ||
69 | |||
70 | // Valid mention (not made up entirely of symbols) | ||
71 | S_AT | ||
72 | .on(TT_DOMAIN, S_MENTION) | ||
73 | .on(TT_LOCALHOST, S_MENTION) | ||
74 | .on(TT_TLD, S_MENTION) | ||
75 | .on(TT_NUM, S_MENTION) | ||
76 | |||
77 | S_AT_SYMS | ||
78 | .on(TT_DOMAIN, S_MENTION) | ||
79 | .on(TT_LOCALHOST, S_MENTION) | ||
80 | .on(TT_TLD, S_MENTION) | ||
81 | .on(TT_NUM, S_MENTION) | ||
82 | |||
83 | // More valid mentions | ||
84 | S_MENTION | ||
85 | .on(TT_DOMAIN, S_MENTION) | ||
86 | .on(TT_LOCALHOST, S_MENTION) | ||
87 | .on(TT_TLD, S_MENTION) | ||
88 | .on(TT_COLON, S_MENTION) | ||
89 | .on(TT_NUM, S_MENTION) | ||
90 | .on(TT_UNDERSCORE, S_MENTION) | ||
91 | |||
92 | // Mention with a divider | ||
93 | S_MENTION | ||
94 | .on(TT_AT, S_MENTION_DIVIDER) | ||
95 | .on(TT_SLASH, S_MENTION_DIVIDER) | ||
96 | .on(TT_DOT, S_MENTION_DIVIDER) | ||
97 | |||
98 | // Mention _ trailing stash plus syms | ||
99 | S_MENTION_DIVIDER.on(TT_UNDERSCORE, S_MENTION_DIVIDER_SYMS) | ||
100 | S_MENTION_DIVIDER_SYMS.on(TT_UNDERSCORE, S_MENTION_DIVIDER_SYMS) | ||
101 | |||
102 | // Once we get a word token, mentions can start up again | ||
103 | S_MENTION_DIVIDER | ||
104 | .on(TT_DOMAIN, S_MENTION) | ||
105 | .on(TT_LOCALHOST, S_MENTION) | ||
106 | .on(TT_TLD, S_MENTION) | ||
107 | .on(TT_NUM, S_MENTION) | ||
108 | |||
109 | S_MENTION_DIVIDER_SYMS | ||
110 | .on(TT_DOMAIN, S_MENTION) | ||
111 | .on(TT_LOCALHOST, S_MENTION) | ||
112 | .on(TT_TLD, S_MENTION) | ||
113 | .on(TT_NUM, S_MENTION) | ||
114 | } | ||
115 | } | ||
diff --git a/client/src/app/videos/+video-watch/comment/video-comment.component.ts b/client/src/app/videos/+video-watch/comment/video-comment.component.ts index 00f0460a1..aba7f9d1c 100644 --- a/client/src/app/videos/+video-watch/comment/video-comment.component.ts +++ b/client/src/app/videos/+video-watch/comment/video-comment.component.ts | |||
@@ -1,11 +1,10 @@ | |||
1 | import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core' | 1 | import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core' |
2 | import { LinkifierService } from '@app/videos/+video-watch/comment/linkifier.service' | ||
3 | import * as sanitizeHtml from 'sanitize-html' | ||
4 | import { UserRight } from '../../../../../../shared/models/users' | 2 | import { UserRight } from '../../../../../../shared/models/users' |
5 | import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model' | 3 | import { VideoCommentThreadTree } from '../../../../../../shared/models/videos/video-comment.model' |
6 | import { AuthService } from '../../../core/auth' | 4 | import { AuthService } from '../../../core/auth' |
7 | import { Video } from '../../../shared/video/video.model' | 5 | import { Video } from '../../../shared/video/video.model' |
8 | import { VideoComment } from './video-comment.model' | 6 | import { VideoComment } from './video-comment.model' |
7 | import { HtmlRendererService } from '@app/shared/renderer' | ||
9 | 8 | ||
10 | @Component({ | 9 | @Component({ |
11 | selector: 'my-video-comment', | 10 | selector: 'my-video-comment', |
@@ -29,7 +28,7 @@ export class VideoCommentComponent implements OnInit, OnChanges { | |||
29 | newParentComments: VideoComment[] = [] | 28 | newParentComments: VideoComment[] = [] |
30 | 29 | ||
31 | constructor ( | 30 | constructor ( |
32 | private linkifierService: LinkifierService, | 31 | private htmlRenderer: HtmlRendererService, |
33 | private authService: AuthService | 32 | private authService: AuthService |
34 | ) {} | 33 | ) {} |
35 | 34 | ||
@@ -87,27 +86,7 @@ export class VideoCommentComponent implements OnInit, OnChanges { | |||
87 | } | 86 | } |
88 | 87 | ||
89 | private init () { | 88 | private init () { |
90 | // Convert possible markdown to html | 89 | this.sanitizedCommentHTML = this.htmlRenderer.toSafeHtml(this.comment.text) |
91 | const html = this.linkifierService.linkify(this.comment.text) | ||
92 | |||
93 | this.sanitizedCommentHTML = sanitizeHtml(html, { | ||
94 | allowedTags: [ 'a', 'p', 'span', 'br' ], | ||
95 | allowedSchemes: [ 'http', 'https' ], | ||
96 | allowedAttributes: { | ||
97 | 'a': [ 'href', 'class', 'target' ] | ||
98 | }, | ||
99 | transformTags: { | ||
100 | a: (tagName, attribs) => { | ||
101 | return { | ||
102 | tagName, | ||
103 | attribs: Object.assign(attribs, { | ||
104 | target: '_blank', | ||
105 | rel: 'noopener noreferrer' | ||
106 | }) | ||
107 | } | ||
108 | } | ||
109 | } | ||
110 | }) | ||
111 | 90 | ||
112 | this.newParentComments = this.parentComments.concat([ this.comment ]) | 91 | this.newParentComments = this.parentComments.concat([ this.comment ]) |
113 | } | 92 | } |
diff --git a/client/src/app/videos/+video-watch/comment/video-comment.service.ts b/client/src/app/videos/+video-watch/comment/video-comment.service.ts index 921447d5b..b8e5878c5 100644 --- a/client/src/app/videos/+video-watch/comment/video-comment.service.ts +++ b/client/src/app/videos/+video-watch/comment/video-comment.service.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { catchError, map } from 'rxjs/operators' | 1 | import { catchError, map } from 'rxjs/operators' |
2 | import { HttpClient, HttpParams } from '@angular/common/http' | 2 | import { HttpClient, HttpParams } from '@angular/common/http' |
3 | import { Injectable } from '@angular/core' | 3 | import { Injectable } from '@angular/core' |
4 | import { lineFeedToHtml } from '@app/shared/misc/utils' | 4 | import { objectLineFeedToHtml } from '@app/shared/misc/utils' |
5 | import { Observable } from 'rxjs' | 5 | import { Observable } from 'rxjs' |
6 | import { ResultList, FeedFormat } from '../../../../../../shared/models' | 6 | import { ResultList, FeedFormat } from '../../../../../../shared/models' |
7 | import { | 7 | import { |
@@ -28,7 +28,7 @@ export class VideoCommentService { | |||
28 | 28 | ||
29 | addCommentThread (videoId: number | string, comment: VideoCommentCreate) { | 29 | addCommentThread (videoId: number | string, comment: VideoCommentCreate) { |
30 | const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comment-threads' | 30 | const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comment-threads' |
31 | const normalizedComment = lineFeedToHtml(comment, 'text') | 31 | const normalizedComment = objectLineFeedToHtml(comment, 'text') |
32 | 32 | ||
33 | return this.authHttp.post<{ comment: VideoCommentServerModel }>(url, normalizedComment) | 33 | return this.authHttp.post<{ comment: VideoCommentServerModel }>(url, normalizedComment) |
34 | .pipe( | 34 | .pipe( |
@@ -39,7 +39,7 @@ export class VideoCommentService { | |||
39 | 39 | ||
40 | addCommentReply (videoId: number | string, inReplyToCommentId: number, comment: VideoCommentCreate) { | 40 | addCommentReply (videoId: number | string, inReplyToCommentId: number, comment: VideoCommentCreate) { |
41 | const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comments/' + inReplyToCommentId | 41 | const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comments/' + inReplyToCommentId |
42 | const normalizedComment = lineFeedToHtml(comment, 'text') | 42 | const normalizedComment = objectLineFeedToHtml(comment, 'text') |
43 | 43 | ||
44 | return this.authHttp.post<{ comment: VideoCommentServerModel }>(url, normalizedComment) | 44 | return this.authHttp.post<{ comment: VideoCommentServerModel }>(url, normalizedComment) |
45 | .pipe( | 45 | .pipe( |
diff --git a/client/src/app/videos/+video-watch/modal/video-support.component.ts b/client/src/app/videos/+video-watch/modal/video-support.component.ts index 154002120..deb8fbc67 100644 --- a/client/src/app/videos/+video-watch/modal/video-support.component.ts +++ b/client/src/app/videos/+video-watch/modal/video-support.component.ts | |||
@@ -1,8 +1,7 @@ | |||
1 | import { Component, Input, ViewChild } from '@angular/core' | 1 | import { Component, Input, ViewChild } from '@angular/core' |
2 | import { MarkdownService } from '@app/videos/shared' | ||
3 | |||
4 | import { VideoDetails } from '../../../shared/video/video-details.model' | 2 | import { VideoDetails } from '../../../shared/video/video-details.model' |
5 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | 3 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
4 | import { MarkdownService } from '@app/shared/renderer' | ||
6 | 5 | ||
7 | @Component({ | 6 | @Component({ |
8 | selector: 'my-video-support', | 7 | selector: 'my-video-support', |
diff --git a/client/src/app/videos/+video-watch/video-watch.component.ts b/client/src/app/videos/+video-watch/video-watch.component.ts index 67c5254b3..ee504bc58 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.ts +++ b/client/src/app/videos/+video-watch/video-watch.component.ts | |||
@@ -19,7 +19,6 @@ import { AuthService, ConfirmService } from '../../core' | |||
19 | import { RestExtractor, VideoBlacklistService } from '../../shared' | 19 | import { RestExtractor, VideoBlacklistService } from '../../shared' |
20 | import { VideoDetails } from '../../shared/video/video-details.model' | 20 | import { VideoDetails } from '../../shared/video/video-details.model' |
21 | import { VideoService } from '../../shared/video/video.service' | 21 | import { VideoService } from '../../shared/video/video.service' |
22 | import { MarkdownService } from '../shared' | ||
23 | import { VideoDownloadComponent } from './modal/video-download.component' | 22 | import { VideoDownloadComponent } from './modal/video-download.component' |
24 | import { VideoReportComponent } from './modal/video-report.component' | 23 | import { VideoReportComponent } from './modal/video-report.component' |
25 | import { VideoShareComponent } from './modal/video-share.component' | 24 | import { VideoShareComponent } from './modal/video-share.component' |
@@ -30,6 +29,7 @@ import { I18n } from '@ngx-translate/i18n-polyfill' | |||
30 | import { environment } from '../../../environments/environment' | 29 | import { environment } from '../../../environments/environment' |
31 | import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' | 30 | import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' |
32 | import { VideoCaptionService } from '@app/shared/video-caption' | 31 | import { VideoCaptionService } from '@app/shared/video-caption' |
32 | import { MarkdownService } from '@app/shared/renderer' | ||
33 | 33 | ||
34 | @Component({ | 34 | @Component({ |
35 | selector: 'my-video-watch', | 35 | selector: 'my-video-watch', |
diff --git a/client/src/app/videos/+video-watch/video-watch.module.ts b/client/src/app/videos/+video-watch/video-watch.module.ts index 54a12c126..2f448db78 100644 --- a/client/src/app/videos/+video-watch/video-watch.module.ts +++ b/client/src/app/videos/+video-watch/video-watch.module.ts | |||
@@ -1,9 +1,7 @@ | |||
1 | import { NgModule } from '@angular/core' | 1 | import { NgModule } from '@angular/core' |
2 | import { LinkifierService } from '@app/videos/+video-watch/comment/linkifier.service' | ||
3 | import { VideoSupportComponent } from '@app/videos/+video-watch/modal/video-support.component' | 2 | import { VideoSupportComponent } from '@app/videos/+video-watch/modal/video-support.component' |
4 | import { ClipboardModule } from 'ngx-clipboard' | 3 | import { ClipboardModule } from 'ngx-clipboard' |
5 | import { SharedModule } from '../../shared' | 4 | import { SharedModule } from '../../shared' |
6 | import { MarkdownService } from '../shared' | ||
7 | import { VideoCommentAddComponent } from './comment/video-comment-add.component' | 5 | import { VideoCommentAddComponent } from './comment/video-comment-add.component' |
8 | import { VideoCommentComponent } from './comment/video-comment.component' | 6 | import { VideoCommentComponent } from './comment/video-comment.component' |
9 | import { VideoCommentService } from './comment/video-comment.service' | 7 | import { VideoCommentService } from './comment/video-comment.service' |
@@ -46,8 +44,6 @@ import { RecommendationsModule } from '@app/videos/recommendations/recommendatio | |||
46 | ], | 44 | ], |
47 | 45 | ||
48 | providers: [ | 46 | providers: [ |
49 | MarkdownService, | ||
50 | LinkifierService, | ||
51 | VideoCommentService | 47 | VideoCommentService |
52 | ] | 48 | ] |
53 | }) | 49 | }) |