ActivityPub-federated video streaming platform using P2P directly in your web browser
Convert video short uuid to uuid
Chocobozzz56b8bff325b5
diff --git a/packages/tests/fixtures/peertube-plugin-test/main.js b/packages/tests/fixtures/peertube-plugin-test/main.jsindex 11669d3265..5a13d3be6c 100644--- a/packages/tests/fixtures/peertube-plugin-test/main.js+++ b/packages/tests/fixtures/peertube-plugin-test/main.js@@ -382,7 +382,7 @@ async function register ({ registerHook, registerSetting, settingsManager, storahandler: (result, params) => {return {allowed: false,- html: 'Lu Bu'+ html: 'Lu Bu ' + params.req.params.id}}})@@ -392,7 +392,7 @@ async function register ({ registerHook, registerSetting, settingsManager, storahandler: (result, params) => {return {allowed: false,- html: 'Diao Chan'+ html: 'Diao Chan ' + params.req.params.id}}})diff --git a/packages/tests/src/plugins/filter-hooks.ts b/packages/tests/src/plugins/filter-hooks.tsindex ac7be95c44..71a84dda39 100644--- a/packages/tests/src/plugins/filter-hooks.ts+++ b/packages/tests/src/plugins/filter-hooks.ts@@ -49,7 +49,7 @@ describe('Test plugin filter hooks', function () {await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() })await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') }){- ({ uuid: videoPlaylistUUID } = await servers[0].playlists.create({+ ;({ uuid: videoPlaylistUUID } = await servers[0].playlists.create({attributes: {displayName: 'my super playlist',privacy: VideoPlaylistPrivacy.PUBLIC,@@ -100,7 +100,6 @@ describe('Test plugin filter hooks', function () {})describe('Videos', function () {-it('Should run filter:api.videos.list.params', async function () {const { data } = await servers[0].videos.list({ start: 0, count: 2 })@@ -198,7 +197,6 @@ describe('Test plugin filter hooks', function () {})describe('Video/live/import accept', function () {-it('Should run filter:api.video.upload.accept.result', async function () {const options = { attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }await servers[0].videos.upload({ mode: 'legacy', ...options })@@ -312,7 +310,6 @@ describe('Test plugin filter hooks', function () {})describe('Video comments accept', function () {-it('Should run filter:api.video-thread.create.accept.result', async function () {await servers[0].comments.createThread({videoId: videoUUID,@@ -386,7 +383,6 @@ describe('Test plugin filter hooks', function () {})describe('Video comments', function () {-it('Should run filter:api.video-threads.list.params', async function () {const { data } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 })@@ -419,7 +415,6 @@ describe('Test plugin filter hooks', function () {})describe('filter:video.auto-blacklist.result', function () {-async function checkIsBlacklisted (id: number | string, value: boolean) {const video = await servers[0].videos.getWithToken({ id })expect(video.blacklisted).to.equal(value)@@ -483,7 +478,6 @@ describe('Test plugin filter hooks', function () {})describe('Should run filter:api.user.signup.allowed.result', function () {-before(async function () {await servers[0].config.updateExistingConfig({ newConfig: { signup: { requiresApproval: false } } })})@@ -508,7 +502,6 @@ describe('Test plugin filter hooks', function () {})describe('Should run filter:api.user.request-signup.allowed.result', function () {-before(async function () {await servers[0].config.updateExistingConfig({ newConfig: { signup: { requiresApproval: true } } })})@@ -635,12 +628,12 @@ describe('Test plugin filter hooks', function () {it('Should run filter:html.embed.video.allowed.result', async function () {const res = await makeGetRequest({ url: servers[0].url, path: embedVideos[0].embedPath, expectedStatus: HttpStatusCode.OK_200 })- expect(res.text).to.equal('Lu Bu')+ expect(res.text).to.equal('Lu Bu ' + embedVideos[0].uuid)})it('Should run filter:html.embed.video-playlist.allowed.result', async function () {const res = await makeGetRequest({ url: servers[0].url, path: embedPlaylists[0].embedPath, expectedStatus: HttpStatusCode.OK_200 })- expect(res.text).to.equal('Diao Chan')+ expect(res.text).to.equal('Diao Chan ' + embedPlaylists[0].uuid)})})@@ -666,7 +659,6 @@ describe('Test plugin filter hooks', function () {})describe('Search filters', function () {-before(async function () {await servers[0].config.updateExistingConfig({newConfig: {@@ -758,7 +750,6 @@ describe('Test plugin filter hooks', function () {})describe('Upload/import/live attributes filters', function () {-before(async function () {await servers[0].config.enableLive({ transcoding: false, allowReplay: false })await servers[0].config.enableVideoImports()@@ -827,13 +818,11 @@ describe('Test plugin filter hooks', function () {})describe('Stats filters', function () {-it('Should run filter:api.server.stats.get.result', async function () {const data = await servers[0].stats.get()expect((data as any).customStats).to.equal(14)})-})describe('Job queue filters', function () {@@ -883,7 +872,6 @@ describe('Test plugin filter hooks', function () {})describe('Transcoding filters', async function () {-it('Should run filter:transcoding.auto.resolutions-to-transcode.result', async function () {const { uuid } = await servers[0].videos.quickUpload({ name: 'transcode-filter' })@@ -896,7 +884,6 @@ describe('Test plugin filter hooks', function () {})describe('Video channel filters', async function () {-it('Should run filter:api.video-channels.list.params', async function () {const { data } = await servers[0].channels.list({ start: 0, count: 0 })@@ -918,7 +905,6 @@ describe('Test plugin filter hooks', function () {})describe('Activity Pub', function () {-it('Should run filter:activity-pub.activity.context.build.result', async function () {const { body } = await makeActivityPubGetRequest(servers[0].url, '/w/' + videoUUID)expect(body.type).to.equal('Video')diff --git a/server/core/controllers/client.ts b/server/core/controllers/client.tsindex e23716bd93..4d7909a108 100644--- a/server/core/controllers/client.ts+++ b/server/core/controllers/client.ts@@ -1,13 +1,14 @@-import express from 'express'-import { constants, promises as fs } from 'fs'-import { readFile } from 'fs/promises'-import { join } from 'path'import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@peertube/peertube-core-utils'import { HttpStatusCode } from '@peertube/peertube-models'+import { currentDir, root } from '@peertube/peertube-node-utils'+import { toCompleteUUID } from '@server/helpers/custom-validators/misc.js'import { logger } from '@server/helpers/logger.js'import { CONFIG } from '@server/initializers/config.js'import { Hooks } from '@server/lib/plugins/hooks.js'-import { currentDir, root } from '@peertube/peertube-node-utils'+import express from 'express'+import { constants, promises as fs } from 'fs'+import { readFile } from 'fs/promises'+import { join } from 'path'import { STATIC_MAX_AGE } from '../initializers/constants.js'import { ClientHtml, sendHTML, serveIndexHTML } from '../lib/html/client-html.js'import { asyncMiddleware, buildRateLimiter, embedCSP } from '../middlewares/index.js'@@ -129,6 +130,8 @@ function serveServerTranslations (req: express.Request, res: express.Response) {}async function generateVideoEmbedHtmlPage (req: express.Request, res: express.Response) {+ req.params.id = toCompleteUUID(req.params.id)+const allowParameters = { req }const allowedResult = await Hooks.wrapFun(@@ -149,6 +152,8 @@ async function generateVideoEmbedHtmlPage (req: express.Request, res: express.Re}async function generateVideoPlaylistEmbedHtmlPage (req: express.Request, res: express.Response) {+ req.params.id = toCompleteUUID(req.params.id)+const allowParameters = { req }const allowedResult = await Hooks.wrapFun(@@ -176,12 +181,16 @@ async function generateWatchHtmlPage (req: express.Request, res: express.Responsconst threadIdIndex = videoId.indexOf(';threadId')if (threadIdIndex !== -1) videoId = videoId.substring(0, threadIdIndex)+ videoId = toCompleteUUID(videoId)+const html = await ClientHtml.getWatchHTMLPage(videoId, req, res)return sendHTML(html, res, true)}async function generateWatchPlaylistHtmlPage (req: express.Request, res: express.Response) {+ req.params.id = toCompleteUUID(req.params.id)+const html = await ClientHtml.getWatchPlaylistHTMLPage(req.params.id + '', req, res)return sendHTML(html, res, true)diff --git a/server/core/helpers/custom-validators/misc.ts b/server/core/helpers/custom-validators/misc.tsindex b77cb5c923..fb8ae3b373 100644--- a/server/core/helpers/custom-validators/misc.ts+++ b/server/core/helpers/custom-validators/misc.ts@@ -1,8 +1,8 @@-import 'multer'+import { isShortUUID, shortToUUID } from '@peertube/peertube-node-utils'import { UploadFilesForCheck } from 'express'+import 'multer'import { sep } from 'path'import validator from 'validator'-import { isShortUUID, shortToUUID } from '@peertube/peertube-node-utils'export function exists (value: any) {return value !== undefined && value !== nulldiff --git a/server/core/lib/html/client-html.ts b/server/core/lib/html/client-html.tsindex e5ad6e3989..b8695b9600 100644--- a/server/core/lib/html/client-html.ts+++ b/server/core/lib/html/client-html.ts@@ -18,22 +18,22 @@ class ClientHtml {// ---------------------------------------------------------------------------- static getWatchHTMLPage (videoIdArg: string, req: express.Request, res: express.Response) {- return VideoHtml.getWatchVideoHTML(videoIdArg, req, res)+ static getWatchHTMLPage (videoId: string, req: express.Request, res: express.Response) {+ return VideoHtml.getWatchVideoHTML(videoId, req, res)}- static getVideoEmbedHTML (videoIdArg: string) {- return VideoHtml.getEmbedVideoHTML(videoIdArg)+ static getVideoEmbedHTML (videoId: string) {+ return VideoHtml.getEmbedVideoHTML(videoId)}// ---------------------------------------------------------------------------- static getWatchPlaylistHTMLPage (videoPlaylistIdArg: string, req: express.Request, res: express.Response) {- return PlaylistHtml.getWatchPlaylistHTML(videoPlaylistIdArg, req, res)+ static getWatchPlaylistHTMLPage (videoPlaylistId: string, req: express.Request, res: express.Response) {+ return PlaylistHtml.getWatchPlaylistHTML(videoPlaylistId, req, res)}- static getVideoPlaylistEmbedHTML (playlistIdArg: string) {- return PlaylistHtml.getEmbedPlaylistHTML(playlistIdArg)+ static getVideoPlaylistEmbedHTML (playlistId: string) {+ return PlaylistHtml.getEmbedPlaylistHTML(playlistId)}// ---------------------------------------------------------------------------diff --git a/server/core/lib/html/shared/playlist-html.ts b/server/core/lib/html/shared/playlist-html.tsindex 89b4d8047e..5adf723043 100644--- a/server/core/lib/html/shared/playlist-html.ts+++ b/server/core/lib/html/shared/playlist-html.ts@@ -1,6 +1,5 @@import { addQueryParams, escapeHTML, getDefaultRSSFeeds } from '@peertube/peertube-core-utils'import { HttpStatusCode, VideoPlaylistPrivacy } from '@peertube/peertube-models'-import { toCompleteUUID } from '@server/helpers/custom-validators/misc.js'import { Memoize } from '@server/helpers/memoize.js'import { VideoPlaylistModel } from '@server/models/video/video-playlist.js'import { MVideoPlaylist, MVideoPlaylistFull } from '@server/types/models/index.js'@@ -13,9 +12,7 @@ import { PageHtml } from './page-html.js'import { TagsHtml } from './tags-html.js'export class PlaylistHtml {- static async getWatchPlaylistHTML (videoPlaylistIdArg: string, req: express.Request, res: express.Response) {- const videoPlaylistId = toCompleteUUID(videoPlaylistIdArg)-+ static async getWatchPlaylistHTML (videoPlaylistId: string, req: express.Request, res: express.Response) {// Let Angular application handle errorsif (!validator.default.isInt(videoPlaylistId) && !validator.default.isUUID(videoPlaylistId, 4)) {res.status(HttpStatusCode.NOT_FOUND_404)@@ -46,9 +43,7 @@ export class PlaylistHtml {}@Memoize({ maxAge: MEMOIZE_TTL.EMBED_HTML })- static async getEmbedPlaylistHTML (playlistIdArg: string) {- const playlistId = toCompleteUUID(playlistIdArg)-+ static async getEmbedPlaylistHTML (playlistId: string) {const playlistPromise: Promise<MVideoPlaylistFull> = validator.default.isInt(playlistId) || validator.default.isUUID(playlistId, 4)? VideoPlaylistModel.loadWithAccountAndChannel(playlistId, null): Promise.resolve(undefined)diff --git a/server/core/lib/html/shared/video-html.ts b/server/core/lib/html/shared/video-html.tsindex b7dcc1a64c..d2ce8d466d 100644--- a/server/core/lib/html/shared/video-html.ts+++ b/server/core/lib/html/shared/video-html.ts@@ -1,6 +1,5 @@import { addQueryParams, escapeHTML, getVideoWatchRSSFeeds } from '@peertube/peertube-core-utils'import { HttpStatusCode, VideoPrivacy } from '@peertube/peertube-models'-import { toCompleteUUID } from '@server/helpers/custom-validators/misc.js'import { Memoize } from '@server/helpers/memoize.js'import express from 'express'import validator from 'validator'@@ -15,9 +14,7 @@ import { PageHtml } from './page-html.js'import { TagsHtml } from './tags-html.js'export class VideoHtml {- static async getWatchVideoHTML (videoIdArg: string, req: express.Request, res: express.Response) {- const videoId = toCompleteUUID(videoIdArg)-+ static async getWatchVideoHTML (videoId: string, req: express.Request, res: express.Response) {// Let Angular application handle errorsif (!validator.default.isInt(videoId) && !validator.default.isUUID(videoId, 4)) {res.status(HttpStatusCode.NOT_FOUND_404)@@ -47,9 +44,7 @@ export class VideoHtml {}@Memoize({ maxAge: MEMOIZE_TTL.EMBED_HTML })- static async getEmbedVideoHTML (videoIdArg: string) {- const videoId = toCompleteUUID(videoIdArg)-+ static async getEmbedVideoHTML (videoId: string) {const videoPromise: Promise<MVideoThumbnailBlacklist> = validator.default.isInt(videoId) || validator.default.isUUID(videoId, 4)? VideoModel.loadWithBlacklist(videoId): Promise.resolve(undefined)