1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 09:49:20 +02:00

Convert video short uuid to uuid

This commit is contained in:
Chocobozzz 2025-07-08 16:38:58 +02:00
parent 3f4c267ec9
commit 56b8bff325
No known key found for this signature in database
GPG key ID: 583A612D890159BE
7 changed files with 34 additions and 49 deletions

View file

@ -382,7 +382,7 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
handler: (result, params) => { handler: (result, params) => {
return { return {
allowed: false, allowed: false,
html: 'Lu Bu' html: 'Lu Bu ' + params.req.params.id
} }
} }
}) })
@ -392,7 +392,7 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
handler: (result, params) => { handler: (result, params) => {
return { return {
allowed: false, allowed: false,
html: 'Diao Chan' html: 'Diao Chan ' + params.req.params.id
} }
} }
}) })

View file

@ -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() })
await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') }) 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: { attributes: {
displayName: 'my super playlist', displayName: 'my super playlist',
privacy: VideoPlaylistPrivacy.PUBLIC, privacy: VideoPlaylistPrivacy.PUBLIC,
@ -100,7 +100,6 @@ describe('Test plugin filter hooks', function () {
}) })
describe('Videos', function () { describe('Videos', function () {
it('Should run filter:api.videos.list.params', async function () { it('Should run filter:api.videos.list.params', async function () {
const { data } = await servers[0].videos.list({ start: 0, count: 2 }) 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 () { describe('Video/live/import accept', function () {
it('Should run filter:api.video.upload.accept.result', async function () { it('Should run filter:api.video.upload.accept.result', async function () {
const options = { attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 } const options = { attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }
await servers[0].videos.upload({ mode: 'legacy', ...options }) await servers[0].videos.upload({ mode: 'legacy', ...options })
@ -312,7 +310,6 @@ describe('Test plugin filter hooks', function () {
}) })
describe('Video comments accept', function () { describe('Video comments accept', function () {
it('Should run filter:api.video-thread.create.accept.result', async function () { it('Should run filter:api.video-thread.create.accept.result', async function () {
await servers[0].comments.createThread({ await servers[0].comments.createThread({
videoId: videoUUID, videoId: videoUUID,
@ -386,7 +383,6 @@ describe('Test plugin filter hooks', function () {
}) })
describe('Video comments', function () { describe('Video comments', function () {
it('Should run filter:api.video-threads.list.params', async 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 }) 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 () { describe('filter:video.auto-blacklist.result', function () {
async function checkIsBlacklisted (id: number | string, value: boolean) { async function checkIsBlacklisted (id: number | string, value: boolean) {
const video = await servers[0].videos.getWithToken({ id }) const video = await servers[0].videos.getWithToken({ id })
expect(video.blacklisted).to.equal(value) 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 () { describe('Should run filter:api.user.signup.allowed.result', function () {
before(async function () { before(async function () {
await servers[0].config.updateExistingConfig({ newConfig: { signup: { requiresApproval: false } } }) 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 () { describe('Should run filter:api.user.request-signup.allowed.result', function () {
before(async function () { before(async function () {
await servers[0].config.updateExistingConfig({ newConfig: { signup: { requiresApproval: true } } }) 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 () { 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 }) 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 () { 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 }) 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 () { describe('Search filters', function () {
before(async function () { before(async function () {
await servers[0].config.updateExistingConfig({ await servers[0].config.updateExistingConfig({
newConfig: { newConfig: {
@ -758,7 +750,6 @@ describe('Test plugin filter hooks', function () {
}) })
describe('Upload/import/live attributes filters', function () { describe('Upload/import/live attributes filters', function () {
before(async function () { before(async function () {
await servers[0].config.enableLive({ transcoding: false, allowReplay: false }) await servers[0].config.enableLive({ transcoding: false, allowReplay: false })
await servers[0].config.enableVideoImports() await servers[0].config.enableVideoImports()
@ -827,13 +818,11 @@ describe('Test plugin filter hooks', function () {
}) })
describe('Stats filters', function () { describe('Stats filters', function () {
it('Should run filter:api.server.stats.get.result', async function () { it('Should run filter:api.server.stats.get.result', async function () {
const data = await servers[0].stats.get() const data = await servers[0].stats.get()
expect((data as any).customStats).to.equal(14) expect((data as any).customStats).to.equal(14)
}) })
}) })
describe('Job queue filters', function () { describe('Job queue filters', function () {
@ -883,7 +872,6 @@ describe('Test plugin filter hooks', function () {
}) })
describe('Transcoding filters', async function () { describe('Transcoding filters', async function () {
it('Should run filter:transcoding.auto.resolutions-to-transcode.result', async function () { it('Should run filter:transcoding.auto.resolutions-to-transcode.result', async function () {
const { uuid } = await servers[0].videos.quickUpload({ name: 'transcode-filter' }) 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 () { describe('Video channel filters', async function () {
it('Should run filter:api.video-channels.list.params', async function () { it('Should run filter:api.video-channels.list.params', async function () {
const { data } = await servers[0].channels.list({ start: 0, count: 0 }) 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 () { describe('Activity Pub', function () {
it('Should run filter:activity-pub.activity.context.build.result', async function () { it('Should run filter:activity-pub.activity.context.build.result', async function () {
const { body } = await makeActivityPubGetRequest(servers[0].url, '/w/' + videoUUID) const { body } = await makeActivityPubGetRequest(servers[0].url, '/w/' + videoUUID)
expect(body.type).to.equal('Video') expect(body.type).to.equal('Video')

View file

@ -1,13 +1,14 @@
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 express from 'express' import express from 'express'
import { constants, promises as fs } from 'fs' import { constants, promises as fs } from 'fs'
import { readFile } from 'fs/promises' import { readFile } from 'fs/promises'
import { join } from 'path' import { join } from 'path'
import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@peertube/peertube-core-utils'
import { HttpStatusCode } from '@peertube/peertube-models'
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 { STATIC_MAX_AGE } from '../initializers/constants.js' import { STATIC_MAX_AGE } from '../initializers/constants.js'
import { ClientHtml, sendHTML, serveIndexHTML } from '../lib/html/client-html.js' import { ClientHtml, sendHTML, serveIndexHTML } from '../lib/html/client-html.js'
import { asyncMiddleware, buildRateLimiter, embedCSP } from '../middlewares/index.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) { async function generateVideoEmbedHtmlPage (req: express.Request, res: express.Response) {
req.params.id = toCompleteUUID(req.params.id)
const allowParameters = { req } const allowParameters = { req }
const allowedResult = await Hooks.wrapFun( 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) { async function generateVideoPlaylistEmbedHtmlPage (req: express.Request, res: express.Response) {
req.params.id = toCompleteUUID(req.params.id)
const allowParameters = { req } const allowParameters = { req }
const allowedResult = await Hooks.wrapFun( const allowedResult = await Hooks.wrapFun(
@ -176,12 +181,16 @@ async function generateWatchHtmlPage (req: express.Request, res: express.Respons
const threadIdIndex = videoId.indexOf(';threadId') const threadIdIndex = videoId.indexOf(';threadId')
if (threadIdIndex !== -1) videoId = videoId.substring(0, threadIdIndex) if (threadIdIndex !== -1) videoId = videoId.substring(0, threadIdIndex)
videoId = toCompleteUUID(videoId)
const html = await ClientHtml.getWatchHTMLPage(videoId, req, res) const html = await ClientHtml.getWatchHTMLPage(videoId, req, res)
return sendHTML(html, res, true) return sendHTML(html, res, true)
} }
async function generateWatchPlaylistHtmlPage (req: express.Request, res: express.Response) { 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) const html = await ClientHtml.getWatchPlaylistHTMLPage(req.params.id + '', req, res)
return sendHTML(html, res, true) return sendHTML(html, res, true)

View file

@ -1,8 +1,8 @@
import 'multer' import { isShortUUID, shortToUUID } from '@peertube/peertube-node-utils'
import { UploadFilesForCheck } from 'express' import { UploadFilesForCheck } from 'express'
import 'multer'
import { sep } from 'path' import { sep } from 'path'
import validator from 'validator' import validator from 'validator'
import { isShortUUID, shortToUUID } from '@peertube/peertube-node-utils'
export function exists (value: any) { export function exists (value: any) {
return value !== undefined && value !== null return value !== undefined && value !== null

View file

@ -18,22 +18,22 @@ class ClientHtml {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
static getWatchHTMLPage (videoIdArg: string, req: express.Request, res: express.Response) { static getWatchHTMLPage (videoId: string, req: express.Request, res: express.Response) {
return VideoHtml.getWatchVideoHTML(videoIdArg, req, res) return VideoHtml.getWatchVideoHTML(videoId, req, res)
} }
static getVideoEmbedHTML (videoIdArg: string) { static getVideoEmbedHTML (videoId: string) {
return VideoHtml.getEmbedVideoHTML(videoIdArg) return VideoHtml.getEmbedVideoHTML(videoId)
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
static getWatchPlaylistHTMLPage (videoPlaylistIdArg: string, req: express.Request, res: express.Response) { static getWatchPlaylistHTMLPage (videoPlaylistId: string, req: express.Request, res: express.Response) {
return PlaylistHtml.getWatchPlaylistHTML(videoPlaylistIdArg, req, res) return PlaylistHtml.getWatchPlaylistHTML(videoPlaylistId, req, res)
} }
static getVideoPlaylistEmbedHTML (playlistIdArg: string) { static getVideoPlaylistEmbedHTML (playlistId: string) {
return PlaylistHtml.getEmbedPlaylistHTML(playlistIdArg) return PlaylistHtml.getEmbedPlaylistHTML(playlistId)
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View file

@ -1,6 +1,5 @@
import { addQueryParams, escapeHTML, getDefaultRSSFeeds } from '@peertube/peertube-core-utils' import { addQueryParams, escapeHTML, getDefaultRSSFeeds } from '@peertube/peertube-core-utils'
import { HttpStatusCode, VideoPlaylistPrivacy } from '@peertube/peertube-models' import { HttpStatusCode, VideoPlaylistPrivacy } from '@peertube/peertube-models'
import { toCompleteUUID } from '@server/helpers/custom-validators/misc.js'
import { Memoize } from '@server/helpers/memoize.js' import { Memoize } from '@server/helpers/memoize.js'
import { VideoPlaylistModel } from '@server/models/video/video-playlist.js' import { VideoPlaylistModel } from '@server/models/video/video-playlist.js'
import { MVideoPlaylist, MVideoPlaylistFull } from '@server/types/models/index.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' import { TagsHtml } from './tags-html.js'
export class PlaylistHtml { export class PlaylistHtml {
static async getWatchPlaylistHTML (videoPlaylistIdArg: string, req: express.Request, res: express.Response) { static async getWatchPlaylistHTML (videoPlaylistId: string, req: express.Request, res: express.Response) {
const videoPlaylistId = toCompleteUUID(videoPlaylistIdArg)
// Let Angular application handle errors // Let Angular application handle errors
if (!validator.default.isInt(videoPlaylistId) && !validator.default.isUUID(videoPlaylistId, 4)) { if (!validator.default.isInt(videoPlaylistId) && !validator.default.isUUID(videoPlaylistId, 4)) {
res.status(HttpStatusCode.NOT_FOUND_404) res.status(HttpStatusCode.NOT_FOUND_404)
@ -46,9 +43,7 @@ export class PlaylistHtml {
} }
@Memoize({ maxAge: MEMOIZE_TTL.EMBED_HTML }) @Memoize({ maxAge: MEMOIZE_TTL.EMBED_HTML })
static async getEmbedPlaylistHTML (playlistIdArg: string) { static async getEmbedPlaylistHTML (playlistId: string) {
const playlistId = toCompleteUUID(playlistIdArg)
const playlistPromise: Promise<MVideoPlaylistFull> = validator.default.isInt(playlistId) || validator.default.isUUID(playlistId, 4) const playlistPromise: Promise<MVideoPlaylistFull> = validator.default.isInt(playlistId) || validator.default.isUUID(playlistId, 4)
? VideoPlaylistModel.loadWithAccountAndChannel(playlistId, null) ? VideoPlaylistModel.loadWithAccountAndChannel(playlistId, null)
: Promise.resolve(undefined) : Promise.resolve(undefined)

View file

@ -1,6 +1,5 @@
import { addQueryParams, escapeHTML, getVideoWatchRSSFeeds } from '@peertube/peertube-core-utils' import { addQueryParams, escapeHTML, getVideoWatchRSSFeeds } from '@peertube/peertube-core-utils'
import { HttpStatusCode, VideoPrivacy } from '@peertube/peertube-models' import { HttpStatusCode, VideoPrivacy } from '@peertube/peertube-models'
import { toCompleteUUID } from '@server/helpers/custom-validators/misc.js'
import { Memoize } from '@server/helpers/memoize.js' import { Memoize } from '@server/helpers/memoize.js'
import express from 'express' import express from 'express'
import validator from 'validator' import validator from 'validator'
@ -15,9 +14,7 @@ import { PageHtml } from './page-html.js'
import { TagsHtml } from './tags-html.js' import { TagsHtml } from './tags-html.js'
export class VideoHtml { export class VideoHtml {
static async getWatchVideoHTML (videoIdArg: string, req: express.Request, res: express.Response) { static async getWatchVideoHTML (videoId: string, req: express.Request, res: express.Response) {
const videoId = toCompleteUUID(videoIdArg)
// Let Angular application handle errors // Let Angular application handle errors
if (!validator.default.isInt(videoId) && !validator.default.isUUID(videoId, 4)) { if (!validator.default.isInt(videoId) && !validator.default.isUUID(videoId, 4)) {
res.status(HttpStatusCode.NOT_FOUND_404) res.status(HttpStatusCode.NOT_FOUND_404)
@ -47,9 +44,7 @@ export class VideoHtml {
} }
@Memoize({ maxAge: MEMOIZE_TTL.EMBED_HTML }) @Memoize({ maxAge: MEMOIZE_TTL.EMBED_HTML })
static async getEmbedVideoHTML (videoIdArg: string) { static async getEmbedVideoHTML (videoId: string) {
const videoId = toCompleteUUID(videoIdArg)
const videoPromise: Promise<MVideoThumbnailBlacklist> = validator.default.isInt(videoId) || validator.default.isUUID(videoId, 4) const videoPromise: Promise<MVideoThumbnailBlacklist> = validator.default.isInt(videoId) || validator.default.isUUID(videoId, 4)
? VideoModel.loadWithBlacklist(videoId) ? VideoModel.loadWithBlacklist(videoId)
: Promise.resolve(undefined) : Promise.resolve(undefined)