From d4a8e7a65f97bb3257facc13e1ae8ffdbad61ddb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 28 Jun 2021 17:30:59 +0200 Subject: Support short uuid for GET video/playlist --- .../lib/activitypub/actors/shared/object-to-model-attributes.ts | 4 ++-- server/lib/client-html.ts | 9 +++++++-- server/lib/local-actor.ts | 4 ++-- server/lib/user.ts | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) (limited to 'server/lib') diff --git a/server/lib/activitypub/actors/shared/object-to-model-attributes.ts b/server/lib/activitypub/actors/shared/object-to-model-attributes.ts index f53b98448..1612b3ad0 100644 --- a/server/lib/activitypub/actors/shared/object-to-model-attributes.ts +++ b/server/lib/activitypub/actors/shared/object-to-model-attributes.ts @@ -1,6 +1,6 @@ -import { v4 as uuidv4 } from 'uuid' import { getLowercaseExtension } from '@server/helpers/core-utils' import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc' +import { buildUUID } from '@server/helpers/uuid' import { MIMETYPES } from '@server/initializers/constants' import { ActorModel } from '@server/models/actor/actor' import { FilteredModelAttributes } from '@server/types' @@ -51,7 +51,7 @@ function getImageInfoFromObject (actorObject: ActivityPubActor, type: ActorImage if (!extension) return undefined return { - name: uuidv4() + extension, + name: buildUUID() + extension, fileUrl: icon.url, height: icon.height, width: icon.width, diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index 0191b55ef..72194416d 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts @@ -27,6 +27,7 @@ import { VideoChannelModel } from '../models/video/video-channel' import { VideoPlaylistModel } from '../models/video/video-playlist' import { MAccountActor, MChannelActor } from '../types/models' import { ServerConfigManager } from './server-config-manager' +import { toCompleteUUID } from '@server/helpers/custom-validators/misc' type Tags = { ogType: string @@ -78,7 +79,9 @@ class ClientHtml { return customHtml } - static async getWatchHTMLPage (videoId: string, req: express.Request, res: express.Response) { + static async getWatchHTMLPage (videoIdArg: string, req: express.Request, res: express.Response) { + const videoId = toCompleteUUID(videoIdArg) + // Let Angular application handle errors if (!validator.isInt(videoId) && !validator.isUUID(videoId, 4)) { res.status(HttpStatusCode.NOT_FOUND_404) @@ -136,7 +139,9 @@ class ClientHtml { return customHtml } - static async getWatchPlaylistHTMLPage (videoPlaylistId: string, req: express.Request, res: express.Response) { + static async getWatchPlaylistHTMLPage (videoPlaylistIdArg: string, req: express.Request, res: express.Response) { + const videoPlaylistId = toCompleteUUID(videoPlaylistIdArg) + // Let Angular application handle errors if (!validator.isInt(videoPlaylistId) && !validator.isUUID(videoPlaylistId, 4)) { res.status(HttpStatusCode.NOT_FOUND_404) diff --git a/server/lib/local-actor.ts b/server/lib/local-actor.ts index 2d2bd43a1..77667f6b0 100644 --- a/server/lib/local-actor.ts +++ b/server/lib/local-actor.ts @@ -2,8 +2,8 @@ import 'multer' import { queue } from 'async' import * as LRUCache from 'lru-cache' import { join } from 'path' -import { v4 as uuidv4 } from 'uuid' import { getLowercaseExtension } from '@server/helpers/core-utils' +import { buildUUID } from '@server/helpers/uuid' import { ActorModel } from '@server/models/actor/actor' import { ActivityPubActorType, ActorImageType } from '@shared/models' import { retryTransactionWrapper } from '../helpers/database-utils' @@ -44,7 +44,7 @@ async function updateLocalActorImageFile ( const extension = getLowercaseExtension(imagePhysicalFile.filename) - const imageName = uuidv4() + extension + const imageName = buildUUID() + extension const destination = join(CONFIG.STORAGE.ACTOR_IMAGES, imageName) await processImage(imagePhysicalFile.path, destination, imageSize) diff --git a/server/lib/user.ts b/server/lib/user.ts index 8820e8243..936403692 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts @@ -1,5 +1,5 @@ import { Transaction } from 'sequelize/types' -import { v4 as uuidv4 } from 'uuid' +import { buildUUID } from '@server/helpers/uuid' import { UserModel } from '@server/models/user/user' import { MActorDefault } from '@server/types/models/actor' import { ActivityPubActorType } from '../../shared/models/activitypub' @@ -210,7 +210,7 @@ async function buildChannelAttributes (user: MUser, transaction?: Transaction, c // Conflict, generate uuid instead const actor = await ActorModel.loadLocalByName(channelName, transaction) - if (actor) channelName = uuidv4() + if (actor) channelName = buildUUID() const videoChannelDisplayName = `Main ${user.username} channel` -- cgit v1.2.3