diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/server/logs.ts | 3 | ||||
-rw-r--r-- | server/controllers/bots.ts | 16 | ||||
-rw-r--r-- | server/controllers/feeds.ts | 2 | ||||
-rw-r--r-- | server/helpers/logger.ts | 23 | ||||
-rw-r--r-- | server/initializers/constants.ts | 2 | ||||
-rw-r--r-- | server/lib/schedulers/plugins-check-scheduler.ts | 10 | ||||
-rw-r--r-- | server/models/video/video-playlist.ts | 8 | ||||
-rw-r--r-- | server/models/video/video.ts | 7 |
8 files changed, 46 insertions, 25 deletions
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 () { |