diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-26 15:04:37 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-26 15:04:37 +0200 |
commit | 15a7eafb892441957ba7dd6fcbf556086fe5b2b3 (patch) | |
tree | 0786bd1a96c7d168a097ffcf5893737db2ab578e | |
parent | 9162fdd36300d2478f13d6ad346ec2c323f40faa (diff) | |
download | PeerTube-15a7eafb892441957ba7dd6fcbf556086fe5b2b3.tar.gz PeerTube-15a7eafb892441957ba7dd6fcbf556086fe5b2b3.tar.zst PeerTube-15a7eafb892441957ba7dd6fcbf556086fe5b2b3.zip |
Refactor video links builders
41 files changed, 279 insertions, 252 deletions
diff --git a/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts b/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts index 3af20ea0a..4fe5ec441 100644 --- a/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts +++ b/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { SortMeta } from 'primeng/api' | 1 | import { SortMeta } from 'primeng/api' |
2 | import { switchMap } from 'rxjs/operators' | 2 | import { switchMap } from 'rxjs/operators' |
3 | import { buildVideoEmbedLink, buildVideoOrPlaylistEmbed, decorateVideoLink } from 'src/assets/player/utils' | 3 | import { buildVideoOrPlaylistEmbed } from 'src/assets/player/utils' |
4 | import { environment } from 'src/environments/environment' | 4 | import { environment } from 'src/environments/environment' |
5 | import { Component, OnInit } from '@angular/core' | 5 | import { Component, OnInit } from '@angular/core' |
6 | import { DomSanitizer } from '@angular/platform-browser' | 6 | import { DomSanitizer } from '@angular/platform-browser' |
@@ -9,6 +9,7 @@ import { ConfirmService, MarkdownService, Notifier, RestPagination, RestTable, S | |||
9 | import { AdvancedInputFilter } from '@app/shared/shared-forms' | 9 | import { AdvancedInputFilter } from '@app/shared/shared-forms' |
10 | import { DropdownAction, Video, VideoService } from '@app/shared/shared-main' | 10 | import { DropdownAction, Video, VideoService } from '@app/shared/shared-main' |
11 | import { VideoBlockService } from '@app/shared/shared-moderation' | 11 | import { VideoBlockService } from '@app/shared/shared-moderation' |
12 | import { buildVideoEmbedLink, decorateVideoLink } from '@shared/core-utils' | ||
12 | import { VideoBlacklist, VideoBlacklistType } from '@shared/models' | 13 | import { VideoBlacklist, VideoBlacklistType } from '@shared/models' |
13 | 14 | ||
14 | @Component({ | 15 | @Component({ |
diff --git a/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts b/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts index 6af224920..968abcbe5 100644 --- a/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts +++ b/client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts | |||
@@ -4,7 +4,7 @@ import { ActivatedRoute, Router } from '@angular/router' | |||
4 | import { PluginApiService } from '@app/+admin/plugins/shared/plugin-api.service' | 4 | import { PluginApiService } from '@app/+admin/plugins/shared/plugin-api.service' |
5 | import { ComponentPagination, ConfirmService, hasMoreItems, Notifier } from '@app/core' | 5 | import { ComponentPagination, ConfirmService, hasMoreItems, Notifier } from '@app/core' |
6 | import { PluginService } from '@app/core/plugins/plugin.service' | 6 | import { PluginService } from '@app/core/plugins/plugin.service' |
7 | import { compareSemVer } from '@shared/core-utils/miscs/miscs' | 7 | import { compareSemVer } from '@shared/core-utils' |
8 | import { PeerTubePlugin, PluginType } from '@shared/models' | 8 | import { PeerTubePlugin, PluginType } from '@shared/models' |
9 | 9 | ||
10 | @Component({ | 10 | @Component({ |
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 9212b78be..ccb9c5e71 100644 --- a/client/src/app/+videos/+video-watch/video-watch.component.ts +++ b/client/src/app/+videos/+video-watch/video-watch.component.ts | |||
@@ -21,6 +21,7 @@ import { isXPercentInViewport, scrollToTop } from '@app/helpers' | |||
21 | import { Video, VideoCaptionService, VideoDetails, VideoService } from '@app/shared/shared-main' | 21 | import { Video, VideoCaptionService, VideoDetails, VideoService } from '@app/shared/shared-main' |
22 | import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription' | 22 | import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription' |
23 | import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist' | 23 | import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist' |
24 | import { timeToInt } from '@shared/core-utils' | ||
24 | import { | 25 | import { |
25 | HTMLServerConfig, | 26 | HTMLServerConfig, |
26 | HttpStatusCode, | 27 | HttpStatusCode, |
@@ -39,7 +40,6 @@ import { | |||
39 | PlayerMode, | 40 | PlayerMode, |
40 | videojs | 41 | videojs |
41 | } from '../../../assets/player/peertube-player-manager' | 42 | } from '../../../assets/player/peertube-player-manager' |
42 | import { timeToInt } from '../../../assets/player/utils' | ||
43 | import { environment } from '../../../environments/environment' | 43 | import { environment } from '../../../environments/environment' |
44 | import { VideoWatchPlaylistComponent } from './shared' | 44 | import { VideoWatchPlaylistComponent } from './shared' |
45 | 45 | ||
diff --git a/client/src/app/core/renderer/markdown.service.ts b/client/src/app/core/renderer/markdown.service.ts index 01d44864b..36258ca98 100644 --- a/client/src/app/core/renderer/markdown.service.ts +++ b/client/src/app/core/renderer/markdown.service.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import * as MarkdownIt from 'markdown-it' | 1 | import * as MarkdownIt from 'markdown-it' |
2 | import { buildVideoLink, decorateVideoLink } from 'src/assets/player/utils' | ||
3 | import { Injectable } from '@angular/core' | 2 | import { Injectable } from '@angular/core' |
3 | import { buildVideoLink, decorateVideoLink } from '@shared/core-utils' | ||
4 | import { | 4 | import { |
5 | COMPLETE_RULES, | 5 | COMPLETE_RULES, |
6 | ENHANCED_RULES, | 6 | ENHANCED_RULES, |
diff --git a/client/src/app/shared/shared-abuse-list/abuse-list-table.component.ts b/client/src/app/shared/shared-abuse-list/abuse-list-table.component.ts index 393108ac9..a7932ebab 100644 --- a/client/src/app/shared/shared-abuse-list/abuse-list-table.component.ts +++ b/client/src/app/shared/shared-abuse-list/abuse-list-table.component.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as debug from 'debug' | 1 | import * as debug from 'debug' |
2 | import truncate from 'lodash-es/truncate' | 2 | import truncate from 'lodash-es/truncate' |
3 | import { SortMeta } from 'primeng/api' | 3 | import { SortMeta } from 'primeng/api' |
4 | import { buildVideoEmbedLink, buildVideoOrPlaylistEmbed, decorateVideoLink } from 'src/assets/player/utils' | 4 | import { buildVideoOrPlaylistEmbed } from 'src/assets/player/utils' |
5 | import { environment } from 'src/environments/environment' | 5 | import { environment } from 'src/environments/environment' |
6 | import { Component, Input, OnInit, ViewChild } from '@angular/core' | 6 | import { Component, Input, OnInit, ViewChild } from '@angular/core' |
7 | import { DomSanitizer } from '@angular/platform-browser' | 7 | import { DomSanitizer } from '@angular/platform-browser' |
@@ -10,6 +10,7 @@ import { ConfirmService, MarkdownService, Notifier, RestPagination, RestTable } | |||
10 | import { Account, Actor, DropdownAction, Video, VideoService } from '@app/shared/shared-main' | 10 | import { Account, Actor, DropdownAction, Video, VideoService } from '@app/shared/shared-main' |
11 | import { AbuseService, BlocklistService, VideoBlockService } from '@app/shared/shared-moderation' | 11 | import { AbuseService, BlocklistService, VideoBlockService } from '@app/shared/shared-moderation' |
12 | import { VideoCommentService } from '@app/shared/shared-video-comment' | 12 | import { VideoCommentService } from '@app/shared/shared-video-comment' |
13 | import { buildVideoEmbedLink, decorateVideoLink } from '@shared/core-utils' | ||
13 | import { AbuseState, AdminAbuse } from '@shared/models' | 14 | import { AbuseState, AdminAbuse } from '@shared/models' |
14 | import { AdvancedInputFilter } from '../shared-forms' | 15 | import { AdvancedInputFilter } from '../shared-forms' |
15 | import { AbuseMessageModalComponent } from './abuse-message-modal.component' | 16 | import { AbuseMessageModalComponent } from './abuse-message-modal.component' |
diff --git a/client/src/app/shared/shared-custom-markup/peertube-custom-tags/embed-markup.component.ts b/client/src/app/shared/shared-custom-markup/peertube-custom-tags/embed-markup.component.ts index ba8969d5b..53b70cc47 100644 --- a/client/src/app/shared/shared-custom-markup/peertube-custom-tags/embed-markup.component.ts +++ b/client/src/app/shared/shared-custom-markup/peertube-custom-tags/embed-markup.component.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { buildPlaylistEmbedLink, buildVideoEmbedLink, buildVideoOrPlaylistEmbed } from 'src/assets/player/utils' | 1 | import { buildVideoOrPlaylistEmbed } from 'src/assets/player/utils' |
2 | import { environment } from 'src/environments/environment' | 2 | import { environment } from 'src/environments/environment' |
3 | import { Component, ElementRef, Input, OnInit } from '@angular/core' | 3 | import { Component, ElementRef, Input, OnInit } from '@angular/core' |
4 | import { buildPlaylistEmbedLink, buildVideoEmbedLink } from '@shared/core-utils' | ||
4 | import { CustomMarkupComponent } from './shared' | 5 | import { CustomMarkupComponent } from './shared' |
5 | 6 | ||
6 | @Component({ | 7 | @Component({ |
diff --git a/client/src/app/shared/shared-forms/timestamp-input.component.ts b/client/src/app/shared/shared-forms/timestamp-input.component.ts index 0ffd03d02..3fc705905 100644 --- a/client/src/app/shared/shared-forms/timestamp-input.component.ts +++ b/client/src/app/shared/shared-forms/timestamp-input.component.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { ChangeDetectorRef, Component, EventEmitter, forwardRef, Input, OnInit, Output } from '@angular/core' | 1 | import { ChangeDetectorRef, Component, EventEmitter, forwardRef, Input, OnInit, Output } from '@angular/core' |
2 | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms' | 2 | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms' |
3 | import { secondsToTime, timeToInt } from '../../../assets/player/utils' | 3 | import { secondsToTime, timeToInt } from '@shared/core-utils' |
4 | 4 | ||
5 | @Component({ | 5 | @Component({ |
6 | selector: 'my-timestamp-input', | 6 | selector: 'my-timestamp-input', |
diff --git a/client/src/app/shared/shared-main/video/video.model.ts b/client/src/app/shared/shared-main/video/video.model.ts index f0a4a3f37..b7720c8d2 100644 --- a/client/src/app/shared/shared-main/video/video.model.ts +++ b/client/src/app/shared/shared-main/video/video.model.ts | |||
@@ -2,6 +2,7 @@ import { AuthUser } from '@app/core' | |||
2 | import { User } from '@app/core/users/user.model' | 2 | import { User } from '@app/core/users/user.model' |
3 | import { durationToString, getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers' | 3 | import { durationToString, getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers' |
4 | import { Actor } from '@app/shared/shared-main/account/actor.model' | 4 | import { Actor } from '@app/shared/shared-main/account/actor.model' |
5 | import { buildVideoWatchPath } from '@shared/core-utils' | ||
5 | import { peertubeTranslate } from '@shared/core-utils/i18n' | 6 | import { peertubeTranslate } from '@shared/core-utils/i18n' |
6 | import { | 7 | import { |
7 | ActorImage, | 8 | ActorImage, |
@@ -92,7 +93,7 @@ export class Video implements VideoServerModel { | |||
92 | pluginData?: any | 93 | pluginData?: any |
93 | 94 | ||
94 | static buildWatchUrl (video: Partial<Pick<Video, 'uuid' | 'shortUUID'>>) { | 95 | static buildWatchUrl (video: Partial<Pick<Video, 'uuid' | 'shortUUID'>>) { |
95 | return '/w/' + (video.shortUUID || video.uuid) | 96 | return buildVideoWatchPath({ shortUUID: video.shortUUID || video.uuid }) |
96 | } | 97 | } |
97 | 98 | ||
98 | static buildUpdateUrl (video: Pick<Video, 'uuid'>) { | 99 | static buildUpdateUrl (video: Pick<Video, 'uuid'>) { |
diff --git a/client/src/app/shared/shared-moderation/report-modals/video-report.component.ts b/client/src/app/shared/shared-moderation/report-modals/video-report.component.ts index 41f4fa30d..e509ac88f 100644 --- a/client/src/app/shared/shared-moderation/report-modals/video-report.component.ts +++ b/client/src/app/shared/shared-moderation/report-modals/video-report.component.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { mapValues, pickBy } from 'lodash-es' | 1 | import { mapValues, pickBy } from 'lodash-es' |
2 | import { buildVideoOrPlaylistEmbed, decorateVideoLink } from 'src/assets/player/utils' | 2 | import { buildVideoOrPlaylistEmbed } from 'src/assets/player/utils' |
3 | import { Component, Input, OnInit, ViewChild } from '@angular/core' | 3 | import { Component, Input, OnInit, ViewChild } from '@angular/core' |
4 | import { DomSanitizer, SafeHtml } from '@angular/platform-browser' | 4 | import { DomSanitizer, SafeHtml } from '@angular/platform-browser' |
5 | import { Notifier } from '@app/core' | 5 | import { Notifier } from '@app/core' |
@@ -7,6 +7,7 @@ import { ABUSE_REASON_VALIDATOR } from '@app/shared/form-validators/abuse-valida | |||
7 | import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' | 7 | import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' |
8 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | 8 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
9 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | 9 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' |
10 | import { decorateVideoLink } from '@shared/core-utils' | ||
10 | import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse' | 11 | import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse' |
11 | import { AbusePredefinedReasonsString } from '@shared/models' | 12 | import { AbusePredefinedReasonsString } from '@shared/models' |
12 | import { Video } from '../../shared-main' | 13 | import { Video } from '../../shared-main' |
diff --git a/client/src/app/shared/shared-share-modal/video-share.component.ts b/client/src/app/shared/shared-share-modal/video-share.component.ts index cdfe50836..341abdc2b 100644 --- a/client/src/app/shared/shared-share-modal/video-share.component.ts +++ b/client/src/app/shared/shared-share-modal/video-share.component.ts | |||
@@ -2,14 +2,9 @@ import { Component, ElementRef, Input, ViewChild } from '@angular/core' | |||
2 | import { VideoDetails } from '@app/shared/shared-main' | 2 | import { VideoDetails } from '@app/shared/shared-main' |
3 | import { VideoPlaylist } from '@app/shared/shared-video-playlist' | 3 | import { VideoPlaylist } from '@app/shared/shared-video-playlist' |
4 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | 4 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
5 | import { buildPlaylistLink, buildVideoLink, decoratePlaylistLink, decorateVideoLink } from '@shared/core-utils' | ||
5 | import { VideoCaption } from '@shared/models' | 6 | import { VideoCaption } from '@shared/models' |
6 | import { | 7 | import { buildVideoOrPlaylistEmbed } from '../../../assets/player/utils' |
7 | buildPlaylistLink, | ||
8 | buildVideoLink, | ||
9 | buildVideoOrPlaylistEmbed, | ||
10 | decoratePlaylistLink, | ||
11 | decorateVideoLink | ||
12 | } from '../../../assets/player/utils' | ||
13 | 8 | ||
14 | type Customizations = { | 9 | type Customizations = { |
15 | startAtCheckbox: boolean | 10 | startAtCheckbox: boolean |
diff --git a/client/src/app/shared/shared-video-miniature/abstract-video-list.ts b/client/src/app/shared/shared-video-miniature/abstract-video-list.ts index 52e72d35b..33061a837 100644 --- a/client/src/app/shared/shared-video-miniature/abstract-video-list.ts +++ b/client/src/app/shared/shared-video-miniature/abstract-video-list.ts | |||
@@ -24,7 +24,7 @@ import { | |||
24 | } from '@app/core' | 24 | } from '@app/core' |
25 | import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook' | 25 | import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook' |
26 | import { GlobalIconName } from '@app/shared/shared-icons' | 26 | import { GlobalIconName } from '@app/shared/shared-icons' |
27 | import { isLastMonth, isLastWeek, isThisMonth, isToday, isYesterday } from '@shared/core-utils/miscs/date' | 27 | import { isLastMonth, isLastWeek, isThisMonth, isToday, isYesterday } from '@shared/core-utils' |
28 | import { HTMLServerConfig, UserRight, VideoFilter, VideoSortField } from '@shared/models' | 28 | import { HTMLServerConfig, UserRight, VideoFilter, VideoSortField } from '@shared/models' |
29 | import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type' | 29 | import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type' |
30 | import { Syndication, Video } from '../shared-main' | 30 | import { Syndication, Video } from '../shared-main' |
diff --git a/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.ts b/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.ts index 681e5becd..8b019103c 100644 --- a/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.ts +++ b/client/src/app/shared/shared-video-playlist/video-add-to-playlist.component.ts | |||
@@ -4,6 +4,7 @@ import { debounceTime, filter } from 'rxjs/operators' | |||
4 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core' | 4 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core' |
5 | import { AuthService, DisableForReuseHook, Notifier } from '@app/core' | 5 | import { AuthService, DisableForReuseHook, Notifier } from '@app/core' |
6 | import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' | 6 | import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' |
7 | import { secondsToTime } from '@shared/core-utils' | ||
7 | import { | 8 | import { |
8 | Video, | 9 | Video, |
9 | VideoExistInPlaylist, | 10 | VideoExistInPlaylist, |
@@ -12,7 +13,6 @@ import { | |||
12 | VideoPlaylistElementUpdate, | 13 | VideoPlaylistElementUpdate, |
13 | VideoPlaylistPrivacy | 14 | VideoPlaylistPrivacy |
14 | } from '@shared/models' | 15 | } from '@shared/models' |
15 | import { secondsToTime } from '../../../assets/player/utils' | ||
16 | import { VIDEO_PLAYLIST_DISPLAY_NAME_VALIDATOR } from '../form-validators/video-playlist-validators' | 16 | import { VIDEO_PLAYLIST_DISPLAY_NAME_VALIDATOR } from '../form-validators/video-playlist-validators' |
17 | import { CachedPlaylist, VideoPlaylistService } from './video-playlist.service' | 17 | import { CachedPlaylist, VideoPlaylistService } from './video-playlist.service' |
18 | 18 | ||
diff --git a/client/src/app/shared/shared-video-playlist/video-playlist-element-miniature.component.ts b/client/src/app/shared/shared-video-playlist/video-playlist-element-miniature.component.ts index d99170e4e..2e495ec26 100644 --- a/client/src/app/shared/shared-video-playlist/video-playlist-element-miniature.component.ts +++ b/client/src/app/shared/shared-video-playlist/video-playlist-element-miniature.component.ts | |||
@@ -2,8 +2,8 @@ import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, In | |||
2 | import { AuthService, Notifier, ServerService } from '@app/core' | 2 | import { AuthService, Notifier, ServerService } from '@app/core' |
3 | import { Video } from '@app/shared/shared-main' | 3 | import { Video } from '@app/shared/shared-main' |
4 | import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap' | 4 | import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap' |
5 | import { secondsToTime } from '@shared/core-utils' | ||
5 | import { HTMLServerConfig, VideoPlaylistElementType, VideoPlaylistElementUpdate } from '@shared/models' | 6 | import { HTMLServerConfig, VideoPlaylistElementType, VideoPlaylistElementUpdate } from '@shared/models' |
6 | import { secondsToTime } from '../../../assets/player/utils' | ||
7 | import { VideoPlaylistElement } from './video-playlist-element.model' | 7 | import { VideoPlaylistElement } from './video-playlist-element.model' |
8 | import { VideoPlaylist } from './video-playlist.model' | 8 | import { VideoPlaylist } from './video-playlist.model' |
9 | import { VideoPlaylistService } from './video-playlist.service' | 9 | import { VideoPlaylistService } from './video-playlist.service' |
diff --git a/client/src/app/shared/shared-video-playlist/video-playlist.model.ts b/client/src/app/shared/shared-video-playlist/video-playlist.model.ts index 55013e4c5..fcc2ce705 100644 --- a/client/src/app/shared/shared-video-playlist/video-playlist.model.ts +++ b/client/src/app/shared/shared-video-playlist/video-playlist.model.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers' | 1 | import { getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers' |
2 | import { Actor } from '@app/shared/shared-main' | 2 | import { Actor } from '@app/shared/shared-main' |
3 | import { buildPlaylistWatchPath } from '@shared/core-utils' | ||
3 | import { peertubeTranslate } from '@shared/core-utils/i18n' | 4 | import { peertubeTranslate } from '@shared/core-utils/i18n' |
4 | import { | 5 | import { |
5 | AccountSummary, | 6 | AccountSummary, |
@@ -44,7 +45,7 @@ export class VideoPlaylist implements ServerVideoPlaylist { | |||
44 | videoChannelBy?: string | 45 | videoChannelBy?: string |
45 | 46 | ||
46 | static buildWatchUrl (playlist: Pick<VideoPlaylist, 'uuid' | 'shortUUID'>) { | 47 | static buildWatchUrl (playlist: Pick<VideoPlaylist, 'uuid' | 'shortUUID'>) { |
47 | return '/w/p/' + (playlist.shortUUID || playlist.uuid) | 48 | return buildPlaylistWatchPath({ shortUUID: playlist.shortUUID || playlist.uuid }) |
48 | } | 49 | } |
49 | 50 | ||
50 | constructor (hash: ServerVideoPlaylist, translations: {}) { | 51 | constructor (hash: ServerVideoPlaylist, translations: {}) { |
diff --git a/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts b/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts index f1bd9f0c4..2eb849d2b 100644 --- a/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts +++ b/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts | |||
@@ -2,8 +2,8 @@ import * as Hlsjs from 'hls.js/dist/hls.light.js' | |||
2 | import { Events, Segment } from 'p2p-media-loader-core' | 2 | import { Events, Segment } from 'p2p-media-loader-core' |
3 | import { Engine, initHlsJsPlayer, initVideoJsContribHlsJsPlayer } from 'p2p-media-loader-hlsjs' | 3 | import { Engine, initHlsJsPlayer, initVideoJsContribHlsJsPlayer } from 'p2p-media-loader-hlsjs' |
4 | import videojs from 'video.js' | 4 | import videojs from 'video.js' |
5 | import { timeToInt } from '@shared/core-utils' | ||
5 | import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../peertube-videojs-typings' | 6 | import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../peertube-videojs-typings' |
6 | import { timeToInt } from '../utils' | ||
7 | import { registerConfigPlugin, registerSourceHandler } from './hls-plugin' | 7 | import { registerConfigPlugin, registerSourceHandler } from './hls-plugin' |
8 | 8 | ||
9 | registerConfigPlugin(videojs) | 9 | registerConfigPlugin(videojs) |
diff --git a/client/src/assets/player/peertube-player-manager.ts b/client/src/assets/player/peertube-player-manager.ts index 6f0b804cd..766ad203e 100644 --- a/client/src/assets/player/peertube-player-manager.ts +++ b/client/src/assets/player/peertube-player-manager.ts | |||
@@ -23,6 +23,7 @@ import './videojs-components/theater-button' | |||
23 | import './playlist/playlist-plugin' | 23 | import './playlist/playlist-plugin' |
24 | import videojs from 'video.js' | 24 | import videojs from 'video.js' |
25 | import { PluginsManager } from '@root-helpers/plugins-manager' | 25 | import { PluginsManager } from '@root-helpers/plugins-manager' |
26 | import { buildVideoLink, decorateVideoLink } from '@shared/core-utils' | ||
26 | import { isDefaultLocale } from '@shared/core-utils/i18n' | 27 | import { isDefaultLocale } from '@shared/core-utils/i18n' |
27 | import { VideoFile } from '@shared/models' | 28 | import { VideoFile } from '@shared/models' |
28 | import { copyToClipboard } from '../../root-helpers/utils' | 29 | import { copyToClipboard } from '../../root-helpers/utils' |
@@ -40,7 +41,7 @@ import { | |||
40 | VideoJSPluginOptions | 41 | VideoJSPluginOptions |
41 | } from './peertube-videojs-typings' | 42 | } from './peertube-videojs-typings' |
42 | import { TranslationsManager } from './translations-manager' | 43 | import { TranslationsManager } from './translations-manager' |
43 | import { buildVideoLink, buildVideoOrPlaylistEmbed, decorateVideoLink, getRtcConfig, isIOS, isSafari } from './utils' | 44 | import { buildVideoOrPlaylistEmbed, getRtcConfig, isIOS, isSafari } from './utils' |
44 | 45 | ||
45 | // Change 'Playback Rate' to 'Speed' (smaller for our settings menu) | 46 | // Change 'Playback Rate' to 'Speed' (smaller for our settings menu) |
46 | (videojs.getComponent('PlaybackRateMenuButton') as any).prototype.controlText_ = 'Speed' | 47 | (videojs.getComponent('PlaybackRateMenuButton') as any).prototype.controlText_ = 'Speed' |
diff --git a/client/src/assets/player/peertube-plugin.ts b/client/src/assets/player/peertube-plugin.ts index 07c7e33f6..919b7c239 100644 --- a/client/src/assets/player/peertube-plugin.ts +++ b/client/src/assets/player/peertube-plugin.ts | |||
@@ -1,12 +1,6 @@ | |||
1 | import videojs from 'video.js' | ||
2 | import './videojs-components/settings-menu-button' | 1 | import './videojs-components/settings-menu-button' |
3 | import { | 2 | import videojs from 'video.js' |
4 | PeerTubePluginOptions, | 3 | import { timeToInt } from '@shared/core-utils' |
5 | ResolutionUpdateData, | ||
6 | UserWatching, | ||
7 | VideoJSCaption | ||
8 | } from './peertube-videojs-typings' | ||
9 | import { isMobile, timeToInt } from './utils' | ||
10 | import { | 4 | import { |
11 | getStoredLastSubtitle, | 5 | getStoredLastSubtitle, |
12 | getStoredMute, | 6 | getStoredMute, |
@@ -16,6 +10,8 @@ import { | |||
16 | saveVideoWatchHistory, | 10 | saveVideoWatchHistory, |
17 | saveVolumeInStore | 11 | saveVolumeInStore |
18 | } from './peertube-player-local-storage' | 12 | } from './peertube-player-local-storage' |
13 | import { PeerTubePluginOptions, ResolutionUpdateData, UserWatching, VideoJSCaption } from './peertube-videojs-typings' | ||
14 | import { isMobile } from './utils' | ||
19 | 15 | ||
20 | const Plugin = videojs.getPlugin('plugin') | 16 | const Plugin = videojs.getPlugin('plugin') |
21 | 17 | ||
diff --git a/client/src/assets/player/playlist/playlist-menu-item.ts b/client/src/assets/player/playlist/playlist-menu-item.ts index 87a72b6a3..2519a34c7 100644 --- a/client/src/assets/player/playlist/playlist-menu-item.ts +++ b/client/src/assets/player/playlist/playlist-menu-item.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import videojs from 'video.js' | 1 | import videojs from 'video.js' |
2 | import { secondsToTime } from '@shared/core-utils' | ||
2 | import { VideoPlaylistElement } from '@shared/models' | 3 | import { VideoPlaylistElement } from '@shared/models' |
3 | import { PlaylistItemOptions } from '../peertube-videojs-typings' | 4 | import { PlaylistItemOptions } from '../peertube-videojs-typings' |
4 | import { secondsToTime } from '../utils' | ||
5 | 5 | ||
6 | const Component = videojs.getComponent('Component') | 6 | const Component = videojs.getComponent('Component') |
7 | 7 | ||
diff --git a/client/src/assets/player/stats/stats-card.ts b/client/src/assets/player/stats/stats-card.ts index a93f59506..b271d0526 100644 --- a/client/src/assets/player/stats/stats-card.ts +++ b/client/src/assets/player/stats/stats-card.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import videojs from 'video.js' | 1 | import videojs from 'video.js' |
2 | import { secondsToTime } from '@shared/core-utils' | ||
2 | import { PlayerNetworkInfo as EventPlayerNetworkInfo } from '../peertube-videojs-typings' | 3 | import { PlayerNetworkInfo as EventPlayerNetworkInfo } from '../peertube-videojs-typings' |
3 | import { bytes, secondsToTime } from '../utils' | 4 | import { bytes } from '../utils' |
4 | 5 | ||
5 | interface StatsCardOptions extends videojs.ComponentOptions { | 6 | interface StatsCardOptions extends videojs.ComponentOptions { |
6 | videoUUID: string | 7 | videoUUID: string |
diff --git a/client/src/assets/player/utils.ts b/client/src/assets/player/utils.ts index eb9302493..f0a1b1aee 100644 --- a/client/src/assets/player/utils.ts +++ b/client/src/assets/player/utils.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { Video, VideoFile, VideoPlaylist } from '@shared/models' | ||
2 | import { escapeHTML } from '@shared/core-utils/renderer' | 1 | import { escapeHTML } from '@shared/core-utils/renderer' |
2 | import { VideoFile } from '@shared/models' | ||
3 | 3 | ||
4 | function toTitleCase (str: string) { | 4 | function toTitleCase (str: string) { |
5 | return str.charAt(0).toUpperCase() + str.slice(1) | 5 | return str.charAt(0).toUpperCase() + str.slice(1) |
@@ -43,144 +43,9 @@ function isMobile () { | |||
43 | return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) | 43 | return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) |
44 | } | 44 | } |
45 | 45 | ||
46 | function buildPlaylistLink (playlist: Pick<VideoPlaylist, 'shortUUID'>, base?: string) { | ||
47 | return (base ?? window.location.origin) + '/w/p/' + playlist.shortUUID | ||
48 | } | ||
49 | |||
50 | function buildVideoLink (video: Pick<Video, 'shortUUID'>, base?: string) { | ||
51 | return (base ?? window.location.origin) + '/w/' + video.shortUUID | ||
52 | } | ||
53 | |||
54 | function buildPlaylistEmbedLink (playlist: Pick<VideoPlaylist, 'uuid'>, base?: string) { | ||
55 | return (base ?? window.location.origin) + '/video-playlists/embed/' + playlist.uuid | ||
56 | } | ||
57 | |||
58 | function buildVideoEmbedLink (video: Pick<Video, 'uuid'>, base?: string) { | ||
59 | return (base ?? window.location.origin) + '/videos/embed/' + video.uuid | ||
60 | } | ||
61 | |||
62 | function decorateVideoLink (options: { | ||
63 | url: string | ||
64 | |||
65 | startTime?: number | ||
66 | stopTime?: number | ||
67 | |||
68 | subtitle?: string | ||
69 | |||
70 | loop?: boolean | ||
71 | autoplay?: boolean | ||
72 | muted?: boolean | ||
73 | |||
74 | // Embed options | ||
75 | title?: boolean | ||
76 | warningTitle?: boolean | ||
77 | controls?: boolean | ||
78 | peertubeLink?: boolean | ||
79 | }) { | ||
80 | const { url } = options | ||
81 | |||
82 | const params = generateParams(window.location.search) | ||
83 | |||
84 | if (options.startTime !== undefined && options.startTime !== null) { | ||
85 | const startTimeInt = Math.floor(options.startTime) | ||
86 | params.set('start', secondsToTime(startTimeInt)) | ||
87 | } | ||
88 | |||
89 | if (options.stopTime) { | ||
90 | const stopTimeInt = Math.floor(options.stopTime) | ||
91 | params.set('stop', secondsToTime(stopTimeInt)) | ||
92 | } | ||
93 | |||
94 | if (options.subtitle) params.set('subtitle', options.subtitle) | ||
95 | |||
96 | if (options.loop === true) params.set('loop', '1') | ||
97 | if (options.autoplay === true) params.set('autoplay', '1') | ||
98 | if (options.muted === true) params.set('muted', '1') | ||
99 | if (options.title === false) params.set('title', '0') | ||
100 | if (options.warningTitle === false) params.set('warningTitle', '0') | ||
101 | if (options.controls === false) params.set('controls', '0') | ||
102 | if (options.peertubeLink === false) params.set('peertubeLink', '0') | ||
103 | |||
104 | return buildUrl(url, params) | ||
105 | } | ||
106 | |||
107 | function decoratePlaylistLink (options: { | ||
108 | url: string | ||
109 | |||
110 | playlistPosition?: number | ||
111 | }) { | ||
112 | const { url } = options | ||
113 | |||
114 | const params = generateParams(window.location.search) | ||
115 | |||
116 | if (options.playlistPosition) params.set('playlistPosition', '' + options.playlistPosition) | ||
117 | |||
118 | return buildUrl(url, params) | ||
119 | } | ||
120 | |||
121 | function buildUrl (url: string, params: URLSearchParams) { | ||
122 | let hasParams = false | ||
123 | params.forEach(() => hasParams = true) | ||
124 | |||
125 | if (hasParams) return url + '?' + params.toString() | ||
126 | |||
127 | return url | ||
128 | } | ||
129 | |||
130 | function generateParams (url: string) { | ||
131 | const params = new URLSearchParams(window.location.search) | ||
132 | // Unused parameters in embed | ||
133 | params.delete('videoId') | ||
134 | params.delete('resume') | ||
135 | |||
136 | return params | ||
137 | } | ||
138 | |||
139 | function timeToInt (time: number | string) { | ||
140 | if (!time) return 0 | ||
141 | if (typeof time === 'number') return time | ||
142 | |||
143 | const reg = /^((\d+)[h:])?((\d+)[m:])?((\d+)s?)?$/ | ||
144 | const matches = time.match(reg) | ||
145 | |||
146 | if (!matches) return 0 | ||
147 | |||
148 | const hours = parseInt(matches[2] || '0', 10) | ||
149 | const minutes = parseInt(matches[4] || '0', 10) | ||
150 | const seconds = parseInt(matches[6] || '0', 10) | ||
151 | |||
152 | return hours * 3600 + minutes * 60 + seconds | ||
153 | } | ||
154 | |||
155 | function secondsToTime (seconds: number, full = false, symbol?: string) { | ||
156 | let time = '' | ||
157 | |||
158 | if (seconds === 0 && !full) return '0s' | ||
159 | |||
160 | const hourSymbol = (symbol || 'h') | ||
161 | const minuteSymbol = (symbol || 'm') | ||
162 | const secondsSymbol = full ? '' : 's' | ||
163 | |||
164 | const hours = Math.floor(seconds / 3600) | ||
165 | if (hours >= 1) time = hours + hourSymbol | ||
166 | else if (full) time = '0' + hourSymbol | ||
167 | |||
168 | seconds %= 3600 | ||
169 | const minutes = Math.floor(seconds / 60) | ||
170 | if (minutes >= 1 && minutes < 10 && full) time += '0' + minutes + minuteSymbol | ||
171 | else if (minutes >= 1) time += minutes + minuteSymbol | ||
172 | else if (full) time += '00' + minuteSymbol | ||
173 | |||
174 | seconds %= 60 | ||
175 | if (seconds >= 1 && seconds < 10 && full) time += '0' + seconds + secondsSymbol | ||
176 | else if (seconds >= 1) time += seconds + secondsSymbol | ||
177 | else if (full) time += '00' | ||
178 | |||
179 | return time | ||
180 | } | ||
181 | |||
182 | function buildVideoOrPlaylistEmbed (embedUrl: string, embedTitle: string) { | 46 | function buildVideoOrPlaylistEmbed (embedUrl: string, embedTitle: string) { |
183 | const title = escapeHTML(embedTitle) | 47 | const title = escapeHTML(embedTitle) |
48 | |||
184 | return '<iframe width="560" height="315" ' + | 49 | return '<iframe width="560" height="315" ' + |
185 | 'sandbox="allow-same-origin allow-scripts allow-popups" ' + | 50 | 'sandbox="allow-same-origin allow-scripts allow-popups" ' + |
186 | 'title="' + title + '" ' + | 51 | 'title="' + title + '" ' + |
@@ -229,17 +94,8 @@ function getRtcConfig () { | |||
229 | export { | 94 | export { |
230 | getRtcConfig, | 95 | getRtcConfig, |
231 | toTitleCase, | 96 | toTitleCase, |
232 | timeToInt, | ||
233 | secondsToTime, | ||
234 | isWebRTCDisabled, | 97 | isWebRTCDisabled, |
235 | 98 | ||
236 | buildPlaylistLink, | ||
237 | buildVideoLink, | ||
238 | decorateVideoLink, | ||
239 | decoratePlaylistLink, | ||
240 | buildPlaylistEmbedLink, | ||
241 | buildVideoEmbedLink, | ||
242 | |||
243 | buildVideoOrPlaylistEmbed, | 99 | buildVideoOrPlaylistEmbed, |
244 | videoFileMaxByResolution, | 100 | videoFileMaxByResolution, |
245 | videoFileMinByResolution, | 101 | videoFileMinByResolution, |
diff --git a/client/src/assets/player/videojs-components/peertube-link-button.ts b/client/src/assets/player/videojs-components/peertube-link-button.ts index f47c165d9..9267b2ed4 100644 --- a/client/src/assets/player/videojs-components/peertube-link-button.ts +++ b/client/src/assets/player/videojs-components/peertube-link-button.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import videojs from 'video.js' | 1 | import videojs from 'video.js' |
2 | import { buildVideoLink, decorateVideoLink } from '@shared/core-utils' | ||
2 | import { PeerTubeLinkButtonOptions } from '../peertube-videojs-typings' | 3 | import { PeerTubeLinkButtonOptions } from '../peertube-videojs-typings' |
3 | import { buildVideoLink, decorateVideoLink } from '../utils' | ||
4 | 4 | ||
5 | const Button = videojs.getComponent('Button') | 5 | const Button = videojs.getComponent('Button') |
6 | class PeerTubeLinkButton extends Button { | 6 | class PeerTubeLinkButton extends Button { |
diff --git a/client/src/assets/player/webtorrent/webtorrent-plugin.ts b/client/src/assets/player/webtorrent/webtorrent-plugin.ts index b648b29e8..17d369c10 100644 --- a/client/src/assets/player/webtorrent/webtorrent-plugin.ts +++ b/client/src/assets/player/webtorrent/webtorrent-plugin.ts | |||
@@ -1,9 +1,7 @@ | |||
1 | import videojs from 'video.js' | 1 | import videojs from 'video.js' |
2 | import * as WebTorrent from 'webtorrent' | 2 | import * as WebTorrent from 'webtorrent' |
3 | import { renderVideo } from './video-renderer' | 3 | import { timeToInt } from '@shared/core-utils' |
4 | import { LoadedQualityData, PlayerNetworkInfo, WebtorrentPluginOptions } from '../peertube-videojs-typings' | 4 | import { VideoFile } from '@shared/models' |
5 | import { getRtcConfig, timeToInt, videoFileMaxByResolution, videoFileMinByResolution, isIOS, isSafari } from '../utils' | ||
6 | import { PeertubeChunkStore } from './peertube-chunk-store' | ||
7 | import { | 5 | import { |
8 | getAverageBandwidthInStore, | 6 | getAverageBandwidthInStore, |
9 | getStoredMute, | 7 | getStoredMute, |
@@ -11,7 +9,10 @@ import { | |||
11 | getStoredVolume, | 9 | getStoredVolume, |
12 | saveAverageBandwidth | 10 | saveAverageBandwidth |
13 | } from '../peertube-player-local-storage' | 11 | } from '../peertube-player-local-storage' |
14 | import { VideoFile } from '@shared/models' | 12 | import { LoadedQualityData, PlayerNetworkInfo, WebtorrentPluginOptions } from '../peertube-videojs-typings' |
13 | import { getRtcConfig, isIOS, videoFileMaxByResolution, videoFileMinByResolution } from '../utils' | ||
14 | import { PeertubeChunkStore } from './peertube-chunk-store' | ||
15 | import { renderVideo } from './video-renderer' | ||
15 | 16 | ||
16 | const CacheChunkStore = require('cache-chunk-store') | 17 | const CacheChunkStore = require('cache-chunk-store') |
17 | 18 | ||
diff --git a/scripts/parse-log.ts b/scripts/parse-log.ts index c16503589..6cd3a1860 100755 --- a/scripts/parse-log.ts +++ b/scripts/parse-log.ts | |||
@@ -6,9 +6,8 @@ import { createReadStream, readdir } from 'fs-extra' | |||
6 | import { join } from 'path' | 6 | import { join } from 'path' |
7 | import { createInterface } from 'readline' | 7 | import { createInterface } from 'readline' |
8 | import * as winston from 'winston' | 8 | import * as winston from 'winston' |
9 | import { labelFormatter } from '../server/helpers/logger' | 9 | import { labelFormatter, mtimeSortFilesDesc } from '../server/helpers/logger' |
10 | import { CONFIG } from '../server/initializers/config' | 10 | import { CONFIG } from '../server/initializers/config' |
11 | import { mtimeSortFilesDesc } from '../shared/core-utils/logs/logs' | ||
12 | import { inspect } from 'util' | 11 | import { inspect } from 'util' |
13 | import { format as sqlFormat } from 'sql-formatter' | 12 | import { format as sqlFormat } from 'sql-formatter' |
14 | 13 | ||
diff --git a/server/controllers/api/server/logs.ts b/server/controllers/api/server/logs.ts index f78607d35..39eceb654 100644 --- a/server/controllers/api/server/logs.ts +++ b/server/controllers/api/server/logs.ts | |||
@@ -1,8 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { readdir, readFile } from 'fs-extra' | 2 | import { readdir, readFile } from 'fs-extra' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { logger } from '@server/helpers/logger' | 4 | import { logger, mtimeSortFilesDesc } from '@server/helpers/logger' |
5 | import { mtimeSortFilesDesc } from '../../../../shared/core-utils/logs/logs' | ||
6 | import { LogLevel } from '../../../../shared/models/server/log-level.type' | 5 | import { LogLevel } from '../../../../shared/models/server/log-level.type' |
7 | import { UserRight } from '../../../../shared/models/users' | 6 | import { UserRight } from '../../../../shared/models/users' |
8 | import { CONFIG } from '../../../initializers/config' | 7 | import { CONFIG } from '../../../initializers/config' |
diff --git a/server/controllers/bots.ts b/server/controllers/bots.ts index 93aa0cf30..de0411608 100644 --- a/server/controllers/bots.ts +++ b/server/controllers/bots.ts | |||
@@ -1,13 +1,13 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { asyncMiddleware } from '../middlewares' | 2 | import { truncate } from 'lodash' |
3 | import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers/constants' | ||
4 | import { SitemapStream, streamToPromise } from 'sitemap' | 3 | import { SitemapStream, streamToPromise } from 'sitemap' |
4 | import { buildNSFWFilter } from '../helpers/express-utils' | ||
5 | import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers/constants' | ||
6 | import { asyncMiddleware } from '../middlewares' | ||
7 | import { cacheRoute } from '../middlewares/cache/cache' | ||
8 | import { AccountModel } from '../models/account/account' | ||
5 | import { VideoModel } from '../models/video/video' | 9 | import { VideoModel } from '../models/video/video' |
6 | import { VideoChannelModel } from '../models/video/video-channel' | 10 | import { VideoChannelModel } from '../models/video/video-channel' |
7 | import { AccountModel } from '../models/account/account' | ||
8 | import { cacheRoute } from '../middlewares/cache/cache' | ||
9 | import { buildNSFWFilter } from '../helpers/express-utils' | ||
10 | import { truncate } from 'lodash' | ||
11 | 11 | ||
12 | const botsRouter = express.Router() | 12 | const botsRouter = express.Router() |
13 | 13 | ||
@@ -75,13 +75,13 @@ async function getSitemapLocalVideoUrls () { | |||
75 | }) | 75 | }) |
76 | 76 | ||
77 | return data.map(v => ({ | 77 | return data.map(v => ({ |
78 | url: WEBSERVER.URL + '/w/' + v.uuid, | 78 | url: WEBSERVER.URL + v.getWatchStaticPath(), |
79 | video: [ | 79 | video: [ |
80 | { | 80 | { |
81 | title: v.name, | 81 | title: v.name, |
82 | // Sitemap description should be < 2000 characters | 82 | // Sitemap description should be < 2000 characters |
83 | description: truncate(v.description || v.name, { length: 2000, omission: '...' }), | 83 | description: truncate(v.description || v.name, { length: 2000, omission: '...' }), |
84 | player_loc: WEBSERVER.URL + '/videos/embed/' + v.uuid, | 84 | player_loc: WEBSERVER.URL + v.getEmbedStaticPath(), |
85 | thumbnail_loc: WEBSERVER.URL + v.getMiniatureStaticPath() | 85 | thumbnail_loc: WEBSERVER.URL + v.getMiniatureStaticPath() |
86 | } | 86 | } |
87 | ] | 87 | ] |
diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts index cdc6bfb8b..9fa70a7c8 100644 --- a/server/controllers/feeds.ts +++ b/server/controllers/feeds.ts | |||
@@ -286,7 +286,7 @@ function addVideosToFeed (feed, videos: VideoModel[]) { | |||
286 | feed.addItem({ | 286 | feed.addItem({ |
287 | title: video.name, | 287 | title: video.name, |
288 | id: video.url, | 288 | id: video.url, |
289 | link: WEBSERVER.URL + '/w/' + video.uuid, | 289 | link: WEBSERVER.URL + video.getWatchStaticPath(), |
290 | description: video.getTruncatedDescription(), | 290 | description: video.getTruncatedDescription(), |
291 | content: video.description, | 291 | content: video.description, |
292 | author: [ | 292 | author: [ |
diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts index 29e06860d..20c3c3edb 100644 --- a/server/helpers/logger.ts +++ b/server/helpers/logger.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | // Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/ | 1 | // Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/ |
2 | import { mkdirpSync } from 'fs-extra' | 2 | import { mkdirpSync, stat } from 'fs-extra' |
3 | import { omit } from 'lodash' | 3 | import { omit } from 'lodash' |
4 | import * as path from 'path' | 4 | import * as path from 'path' |
5 | import { format as sqlFormat } from 'sql-formatter' | 5 | import { format as sqlFormat } from 'sql-formatter' |
@@ -158,6 +158,26 @@ function loggerTagsFactory (...defaultTags: string[]): LoggerTagsFn { | |||
158 | } | 158 | } |
159 | } | 159 | } |
160 | 160 | ||
161 | async function mtimeSortFilesDesc (files: string[], basePath: string) { | ||
162 | const promises = [] | ||
163 | const out: { file: string, mtime: number }[] = [] | ||
164 | |||
165 | for (const file of files) { | ||
166 | const p = stat(basePath + '/' + file) | ||
167 | .then(stats => { | ||
168 | if (stats.isFile()) out.push({ file, mtime: stats.mtime.getTime() }) | ||
169 | }) | ||
170 | |||
171 | promises.push(p) | ||
172 | } | ||
173 | |||
174 | await Promise.all(promises) | ||
175 | |||
176 | out.sort((a, b) => b.mtime - a.mtime) | ||
177 | |||
178 | return out | ||
179 | } | ||
180 | |||
161 | // --------------------------------------------------------------------------- | 181 | // --------------------------------------------------------------------------- |
162 | 182 | ||
163 | export { | 183 | export { |
@@ -168,6 +188,7 @@ export { | |||
168 | labelFormatter, | 188 | labelFormatter, |
169 | consoleLoggerFormat, | 189 | consoleLoggerFormat, |
170 | jsonLoggerFormat, | 190 | jsonLoggerFormat, |
191 | mtimeSortFilesDesc, | ||
171 | logger, | 192 | logger, |
172 | loggerTagsFactory, | 193 | loggerTagsFactory, |
173 | bunyanLogger | 194 | bunyanLogger |
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index ee4503b2c..5f121d9a4 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -2,7 +2,7 @@ import { CronRepeatOptions, EveryRepeatOptions } from 'bull' | |||
2 | import { randomBytes } from 'crypto' | 2 | import { randomBytes } from 'crypto' |
3 | import { invert } from 'lodash' | 3 | import { invert } from 'lodash' |
4 | import { join } from 'path' | 4 | import { join } from 'path' |
5 | import { randomInt } from '../../shared/core-utils/miscs/miscs' | 5 | import { randomInt } from '../../shared/core-utils/common/miscs' |
6 | import { | 6 | import { |
7 | AbuseState, | 7 | AbuseState, |
8 | JobType, | 8 | JobType, |
diff --git a/server/lib/schedulers/plugins-check-scheduler.ts b/server/lib/schedulers/plugins-check-scheduler.ts index 9a1ae3ec5..c95e109b0 100644 --- a/server/lib/schedulers/plugins-check-scheduler.ts +++ b/server/lib/schedulers/plugins-check-scheduler.ts | |||
@@ -1,12 +1,12 @@ | |||
1 | import { chunk } from 'lodash' | ||
2 | import { compareSemVer } from '@shared/core-utils' | ||
1 | import { logger } from '../../helpers/logger' | 3 | import { logger } from '../../helpers/logger' |
2 | import { AbstractScheduler } from './abstract-scheduler' | ||
3 | import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants' | ||
4 | import { CONFIG } from '../../initializers/config' | 4 | import { CONFIG } from '../../initializers/config' |
5 | import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants' | ||
5 | import { PluginModel } from '../../models/server/plugin' | 6 | import { PluginModel } from '../../models/server/plugin' |
6 | import { chunk } from 'lodash' | ||
7 | import { getLatestPluginsVersion } from '../plugins/plugin-index' | ||
8 | import { compareSemVer } from '../../../shared/core-utils/miscs/miscs' | ||
9 | import { Notifier } from '../notifier' | 7 | import { Notifier } from '../notifier' |
8 | import { getLatestPluginsVersion } from '../plugins/plugin-index' | ||
9 | import { AbstractScheduler } from './abstract-scheduler' | ||
10 | 10 | ||
11 | export class PluginsCheckScheduler extends AbstractScheduler { | 11 | export class PluginsCheckScheduler extends AbstractScheduler { |
12 | 12 | ||
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index af81c9906..245475f94 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts | |||
@@ -20,7 +20,7 @@ import { | |||
20 | import { setAsUpdated } from '@server/helpers/database-utils' | 20 | import { setAsUpdated } from '@server/helpers/database-utils' |
21 | import { buildUUID, uuidToShort } from '@server/helpers/uuid' | 21 | import { buildUUID, uuidToShort } from '@server/helpers/uuid' |
22 | import { MAccountId, MChannelId } from '@server/types/models' | 22 | import { MAccountId, MChannelId } from '@server/types/models' |
23 | import { AttributesOnly } from '@shared/core-utils' | 23 | import { AttributesOnly, buildPlaylistEmbedPath, buildPlaylistLink, buildPlaylistWatchPath } from '@shared/core-utils' |
24 | import { ActivityIconObject } from '../../../shared/models/activitypub/objects' | 24 | import { ActivityIconObject } from '../../../shared/models/activitypub/objects' |
25 | import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object' | 25 | import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object' |
26 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' | 26 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' |
@@ -560,12 +560,12 @@ export class VideoPlaylistModel extends Model<Partial<AttributesOnly<VideoPlayli | |||
560 | return join(STATIC_PATHS.THUMBNAILS, this.Thumbnail.filename) | 560 | return join(STATIC_PATHS.THUMBNAILS, this.Thumbnail.filename) |
561 | } | 561 | } |
562 | 562 | ||
563 | getWatchUrl () { | 563 | getWatchStaticPath () { |
564 | return WEBSERVER.URL + '/w/p/' + this.uuid | 564 | return buildPlaylistWatchPath({ shortUUID: uuidToShort(this.uuid) }) |
565 | } | 565 | } |
566 | 566 | ||
567 | getEmbedStaticPath () { | 567 | getEmbedStaticPath () { |
568 | return '/video-playlists/embed/' + this.uuid | 568 | return buildPlaylistEmbedPath(this) |
569 | } | 569 | } |
570 | 570 | ||
571 | static async getStats () { | 571 | static async getStats () { |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 0f0f894e4..543e604bb 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -26,12 +26,13 @@ import { | |||
26 | } from 'sequelize-typescript' | 26 | } from 'sequelize-typescript' |
27 | import { setAsUpdated } from '@server/helpers/database-utils' | 27 | import { setAsUpdated } from '@server/helpers/database-utils' |
28 | import { buildNSFWFilter } from '@server/helpers/express-utils' | 28 | import { buildNSFWFilter } from '@server/helpers/express-utils' |
29 | import { shortToUUID } from '@server/helpers/uuid' | ||
29 | import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' | 30 | import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' |
30 | import { LiveManager } from '@server/lib/live/live-manager' | 31 | import { LiveManager } from '@server/lib/live/live-manager' |
31 | import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths' | 32 | import { getHLSDirectory, getVideoFilePath } from '@server/lib/video-paths' |
32 | import { getServerActor } from '@server/models/application/application' | 33 | import { getServerActor } from '@server/models/application/application' |
33 | import { ModelCache } from '@server/models/model-cache' | 34 | import { ModelCache } from '@server/models/model-cache' |
34 | import { AttributesOnly } from '@shared/core-utils' | 35 | import { AttributesOnly, buildVideoEmbedPath, buildVideoWatchPath } from '@shared/core-utils' |
35 | import { VideoFile } from '@shared/models/videos/video-file.model' | 36 | import { VideoFile } from '@shared/models/videos/video-file.model' |
36 | import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared' | 37 | import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared' |
37 | import { VideoObject } from '../../../shared/models/activitypub/objects' | 38 | import { VideoObject } from '../../../shared/models/activitypub/objects' |
@@ -1578,11 +1579,11 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1578 | } | 1579 | } |
1579 | 1580 | ||
1580 | getWatchStaticPath () { | 1581 | getWatchStaticPath () { |
1581 | return '/w/' + this.uuid | 1582 | return buildVideoWatchPath({ shortUUID: shortToUUID(this.uuid) }) |
1582 | } | 1583 | } |
1583 | 1584 | ||
1584 | getEmbedStaticPath () { | 1585 | getEmbedStaticPath () { |
1585 | return '/videos/embed/' + this.uuid | 1586 | return buildVideoEmbedPath(this) |
1586 | } | 1587 | } |
1587 | 1588 | ||
1588 | getMiniatureStaticPath () { | 1589 | getMiniatureStaticPath () { |
diff --git a/shared/core-utils/common/date.ts b/shared/core-utils/common/date.ts index 4f92f758f..3e4a3c08c 100644 --- a/shared/core-utils/common/date.ts +++ b/shared/core-utils/common/date.ts | |||
@@ -43,6 +43,49 @@ function isLastWeek (d: Date) { | |||
43 | return getDaysDifferences(now, d) <= 7 | 43 | return getDaysDifferences(now, d) <= 7 |
44 | } | 44 | } |
45 | 45 | ||
46 | function timeToInt (time: number | string) { | ||
47 | if (!time) return 0 | ||
48 | if (typeof time === 'number') return time | ||
49 | |||
50 | const reg = /^((\d+)[h:])?((\d+)[m:])?((\d+)s?)?$/ | ||
51 | const matches = time.match(reg) | ||
52 | |||
53 | if (!matches) return 0 | ||
54 | |||
55 | const hours = parseInt(matches[2] || '0', 10) | ||
56 | const minutes = parseInt(matches[4] || '0', 10) | ||
57 | const seconds = parseInt(matches[6] || '0', 10) | ||
58 | |||
59 | return hours * 3600 + minutes * 60 + seconds | ||
60 | } | ||
61 | |||
62 | function secondsToTime (seconds: number, full = false, symbol?: string) { | ||
63 | let time = '' | ||
64 | |||
65 | if (seconds === 0 && !full) return '0s' | ||
66 | |||
67 | const hourSymbol = (symbol || 'h') | ||
68 | const minuteSymbol = (symbol || 'm') | ||
69 | const secondsSymbol = full ? '' : 's' | ||
70 | |||
71 | const hours = Math.floor(seconds / 3600) | ||
72 | if (hours >= 1) time = hours + hourSymbol | ||
73 | else if (full) time = '0' + hourSymbol | ||
74 | |||
75 | seconds %= 3600 | ||
76 | const minutes = Math.floor(seconds / 60) | ||
77 | if (minutes >= 1 && minutes < 10 && full) time += '0' + minutes + minuteSymbol | ||
78 | else if (minutes >= 1) time += minutes + minuteSymbol | ||
79 | else if (full) time += '00' + minuteSymbol | ||
80 | |||
81 | seconds %= 60 | ||
82 | if (seconds >= 1 && seconds < 10 && full) time += '0' + seconds + secondsSymbol | ||
83 | else if (seconds >= 1) time += seconds + secondsSymbol | ||
84 | else if (full) time += '00' | ||
85 | |||
86 | return time | ||
87 | } | ||
88 | |||
46 | // --------------------------------------------------------------------------- | 89 | // --------------------------------------------------------------------------- |
47 | 90 | ||
48 | export { | 91 | export { |
@@ -51,7 +94,9 @@ export { | |||
51 | isThisMonth, | 94 | isThisMonth, |
52 | isToday, | 95 | isToday, |
53 | isLastMonth, | 96 | isLastMonth, |
54 | isLastWeek | 97 | isLastWeek, |
98 | timeToInt, | ||
99 | secondsToTime | ||
55 | } | 100 | } |
56 | 101 | ||
57 | // --------------------------------------------------------------------------- | 102 | // --------------------------------------------------------------------------- |
diff --git a/shared/core-utils/common/index.ts b/shared/core-utils/common/index.ts index 83f2ccbb6..0908ff981 100644 --- a/shared/core-utils/common/index.ts +++ b/shared/core-utils/common/index.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | export * from './date' | 1 | export * from './date' |
2 | export * from './miscs' | 2 | export * from './miscs' |
3 | export * from './regexp' | 3 | export * from './regexp' |
4 | export * from './promises' | ||
4 | export * from './types' | 5 | export * from './types' |
5 | export * from './url | 6 | export * from './url' |
diff --git a/shared/core-utils/common/miscs.ts b/shared/core-utils/common/miscs.ts index 4780ca922..bc65dc338 100644 --- a/shared/core-utils/common/miscs.ts +++ b/shared/core-utils/common/miscs.ts | |||
@@ -20,14 +20,6 @@ function compareSemVer (a: string, b: string) { | |||
20 | return segmentsA.length - segmentsB.length | 20 | return segmentsA.length - segmentsB.length |
21 | } | 21 | } |
22 | 22 | ||
23 | function isPromise (value: any) { | ||
24 | return value && typeof value.then === 'function' | ||
25 | } | ||
26 | |||
27 | function isCatchable (value: any) { | ||
28 | return value && typeof value.catch === 'function' | ||
29 | } | ||
30 | |||
31 | function sortObjectComparator (key: string, order: 'asc' | 'desc') { | 23 | function sortObjectComparator (key: string, order: 'asc' | 'desc') { |
32 | return (a: any, b: any) => { | 24 | return (a: any, b: any) => { |
33 | if (a[key] < b[key]) { | 25 | if (a[key] < b[key]) { |
@@ -45,7 +37,5 @@ function sortObjectComparator (key: string, order: 'asc' | 'desc') { | |||
45 | export { | 37 | export { |
46 | randomInt, | 38 | randomInt, |
47 | compareSemVer, | 39 | compareSemVer, |
48 | isPromise, | ||
49 | isCatchable, | ||
50 | sortObjectComparator | 40 | sortObjectComparator |
51 | } | 41 | } |
diff --git a/shared/core-utils/common/promises.ts b/shared/core-utils/common/promises.ts new file mode 100644 index 000000000..7ef9d60b6 --- /dev/null +++ b/shared/core-utils/common/promises.ts | |||
@@ -0,0 +1,12 @@ | |||
1 | function isPromise (value: any) { | ||
2 | return value && typeof value.then === 'function' | ||
3 | } | ||
4 | |||
5 | function isCatchable (value: any) { | ||
6 | return value && typeof value.catch === 'function' | ||
7 | } | ||
8 | |||
9 | export { | ||
10 | isPromise, | ||
11 | isCatchable | ||
12 | } | ||
diff --git a/shared/core-utils/common/url.ts b/shared/core-utils/common/url.ts index e69de29bb..52ed247c4 100644 --- a/shared/core-utils/common/url.ts +++ b/shared/core-utils/common/url.ts | |||
@@ -0,0 +1,130 @@ | |||
1 | import { Video, VideoPlaylist } from '../../models' | ||
2 | import { secondsToTime } from './date' | ||
3 | |||
4 | function buildPlaylistLink (playlist: Pick<VideoPlaylist, 'shortUUID'>, base?: string) { | ||
5 | return (base ?? window.location.origin) + buildPlaylistWatchPath(playlist) | ||
6 | } | ||
7 | |||
8 | function buildPlaylistWatchPath (playlist: Pick<VideoPlaylist, 'shortUUID'>) { | ||
9 | return '/w/p/' + playlist.shortUUID | ||
10 | } | ||
11 | |||
12 | function buildVideoWatchPath (video: Pick<Video, 'shortUUID'>) { | ||
13 | return '/w/' + video.shortUUID | ||
14 | } | ||
15 | |||
16 | function buildVideoLink (video: Pick<Video, 'shortUUID'>, base?: string) { | ||
17 | return (base ?? window.location.origin) + buildVideoWatchPath(video) | ||
18 | } | ||
19 | |||
20 | function buildPlaylistEmbedPath (playlist: Pick<VideoPlaylist, 'uuid'>) { | ||
21 | return '/video-playlists/embed/' + playlist.uuid | ||
22 | } | ||
23 | |||
24 | function buildPlaylistEmbedLink (playlist: Pick<VideoPlaylist, 'uuid'>, base?: string) { | ||
25 | return (base ?? window.location.origin) + buildPlaylistEmbedPath(playlist) | ||
26 | } | ||
27 | |||
28 | function buildVideoEmbedPath (video: Pick<Video, 'uuid'>) { | ||
29 | return '/videos/embed/' + video.uuid | ||
30 | } | ||
31 | |||
32 | function buildVideoEmbedLink (video: Pick<Video, 'uuid'>, base?: string) { | ||
33 | return (base ?? window.location.origin) + buildVideoEmbedPath(video) | ||
34 | } | ||
35 | |||
36 | function decorateVideoLink (options: { | ||
37 | url: string | ||
38 | |||
39 | startTime?: number | ||
40 | stopTime?: number | ||
41 | |||
42 | subtitle?: string | ||
43 | |||
44 | loop?: boolean | ||
45 | autoplay?: boolean | ||
46 | muted?: boolean | ||
47 | |||
48 | // Embed options | ||
49 | title?: boolean | ||
50 | warningTitle?: boolean | ||
51 | controls?: boolean | ||
52 | peertubeLink?: boolean | ||
53 | }) { | ||
54 | const { url } = options | ||
55 | |||
56 | const params = generateParams(window.location.search) | ||
57 | |||
58 | if (options.startTime !== undefined && options.startTime !== null) { | ||
59 | const startTimeInt = Math.floor(options.startTime) | ||
60 | params.set('start', secondsToTime(startTimeInt)) | ||
61 | } | ||
62 | |||
63 | if (options.stopTime) { | ||
64 | const stopTimeInt = Math.floor(options.stopTime) | ||
65 | params.set('stop', secondsToTime(stopTimeInt)) | ||
66 | } | ||
67 | |||
68 | if (options.subtitle) params.set('subtitle', options.subtitle) | ||
69 | |||
70 | if (options.loop === true) params.set('loop', '1') | ||
71 | if (options.autoplay === true) params.set('autoplay', '1') | ||
72 | if (options.muted === true) params.set('muted', '1') | ||
73 | if (options.title === false) params.set('title', '0') | ||
74 | if (options.warningTitle === false) params.set('warningTitle', '0') | ||
75 | if (options.controls === false) params.set('controls', '0') | ||
76 | if (options.peertubeLink === false) params.set('peertubeLink', '0') | ||
77 | |||
78 | return buildUrl(url, params) | ||
79 | } | ||
80 | |||
81 | function decoratePlaylistLink (options: { | ||
82 | url: string | ||
83 | |||
84 | playlistPosition?: number | ||
85 | }) { | ||
86 | const { url } = options | ||
87 | |||
88 | const params = generateParams(window.location.search) | ||
89 | |||
90 | if (options.playlistPosition) params.set('playlistPosition', '' + options.playlistPosition) | ||
91 | |||
92 | return buildUrl(url, params) | ||
93 | } | ||
94 | |||
95 | // --------------------------------------------------------------------------- | ||
96 | |||
97 | export { | ||
98 | buildPlaylistLink, | ||
99 | buildVideoLink, | ||
100 | |||
101 | buildVideoWatchPath, | ||
102 | buildPlaylistWatchPath, | ||
103 | |||
104 | buildPlaylistEmbedPath, | ||
105 | buildVideoEmbedPath, | ||
106 | |||
107 | buildPlaylistEmbedLink, | ||
108 | buildVideoEmbedLink, | ||
109 | |||
110 | decorateVideoLink, | ||
111 | decoratePlaylistLink | ||
112 | } | ||
113 | |||
114 | function buildUrl (url: string, params: URLSearchParams) { | ||
115 | let hasParams = false | ||
116 | params.forEach(() => { hasParams = true }) | ||
117 | |||
118 | if (hasParams) return url + '?' + params.toString() | ||
119 | |||
120 | return url | ||
121 | } | ||
122 | |||
123 | function generateParams (url: string) { | ||
124 | const params = new URLSearchParams(window.location.search) | ||
125 | // Unused parameters in embed | ||
126 | params.delete('videoId') | ||
127 | params.delete('resume') | ||
128 | |||
129 | return params | ||
130 | } | ||
diff --git a/shared/core-utils/index.ts b/shared/core-utils/index.ts index 0b05dc9eb..66d50ef93 100644 --- a/shared/core-utils/index.ts +++ b/shared/core-utils/index.ts | |||
@@ -1,7 +1,6 @@ | |||
1 | export * from './abuse' | 1 | export * from './abuse' |
2 | export * from './common' | 2 | export * from './common' |
3 | export * from './i18n' | 3 | export * from './i18n' |
4 | export * from './logs' | ||
5 | export * from './plugins' | 4 | export * from './plugins' |
6 | export * from './renderer' | 5 | export * from './renderer' |
7 | export * from './users' | 6 | export * from './users' |
diff --git a/shared/core-utils/logs/index.ts b/shared/core-utils/logs/index.ts deleted file mode 100644 index ceb5d7a7f..000000000 --- a/shared/core-utils/logs/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './logs' | ||
diff --git a/shared/core-utils/logs/logs.ts b/shared/core-utils/logs/logs.ts deleted file mode 100644 index d0996cf55..000000000 --- a/shared/core-utils/logs/logs.ts +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | import { stat } from 'fs-extra' | ||
2 | |||
3 | async function mtimeSortFilesDesc (files: string[], basePath: string) { | ||
4 | const promises = [] | ||
5 | const out: { file: string, mtime: number }[] = [] | ||
6 | |||
7 | for (const file of files) { | ||
8 | const p = stat(basePath + '/' + file) | ||
9 | .then(stats => { | ||
10 | if (stats.isFile()) out.push({ file, mtime: stats.mtime.getTime() }) | ||
11 | }) | ||
12 | |||
13 | promises.push(p) | ||
14 | } | ||
15 | |||
16 | await Promise.all(promises) | ||
17 | |||
18 | out.sort((a, b) => b.mtime - a.mtime) | ||
19 | |||
20 | return out | ||
21 | } | ||
22 | |||
23 | export { | ||
24 | mtimeSortFilesDesc | ||
25 | } | ||
diff --git a/shared/core-utils/plugins/hooks.ts b/shared/core-utils/plugins/hooks.ts index 5405e0529..92cb5ad68 100644 --- a/shared/core-utils/plugins/hooks.ts +++ b/shared/core-utils/plugins/hooks.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { HookType } from '../../models/plugins/hook-type.enum' | 1 | import { HookType } from '../../models/plugins/hook-type.enum' |
2 | import { isCatchable, isPromise } from '../miscs/miscs' | 2 | import { isCatchable, isPromise } from '../common/promises' |
3 | 3 | ||
4 | function getHookType (hookName: string) { | 4 | function getHookType (hookName: string) { |
5 | if (hookName.startsWith('filter:')) return HookType.FILTER | 5 | if (hookName.startsWith('filter:')) return HookType.FILTER |
diff --git a/shared/extra-utils/server/server.ts b/shared/extra-utils/server/server.ts index d37a7f39c..3c335b8e4 100644 --- a/shared/extra-utils/server/server.ts +++ b/shared/extra-utils/server/server.ts | |||
@@ -2,7 +2,7 @@ import { ChildProcess, fork } from 'child_process' | |||
2 | import { copy } from 'fs-extra' | 2 | import { copy } from 'fs-extra' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { root } from '@server/helpers/core-utils' | 4 | import { root } from '@server/helpers/core-utils' |
5 | import { randomInt } from '../../core-utils/miscs/miscs' | 5 | import { randomInt } from '@shared/core-utils' |
6 | import { Video, VideoChannel, VideoCreateResult, VideoDetails } from '../../models/videos' | 6 | import { Video, VideoChannel, VideoCreateResult, VideoDetails } from '../../models/videos' |
7 | import { BulkCommand } from '../bulk' | 7 | import { BulkCommand } from '../bulk' |
8 | import { CLICommand } from '../cli' | 8 | import { CLICommand } from '../cli' |