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) => {
return {
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) => {
return {
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('-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')

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 { 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 { 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 { 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.Respons
const 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)

View file

@ -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 !== null

View file

@ -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)
}
// ---------------------------------------------------------------------------

View file

@ -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 errors
if (!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)

View file

@ -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 errors
if (!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)