diff options
author | Chocobozzz <me@florianbigard.com> | 2021-06-28 17:30:59 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-06-29 14:56:35 +0200 |
commit | d4a8e7a65f97bb3257facc13e1ae8ffdbad61ddb (patch) | |
tree | a4cb07318100031951c3dffc61f4f2cb95d2cbd0 /server/lib | |
parent | 62ddc31a9e4b92d7d27898ccfc363f68ab044139 (diff) | |
download | PeerTube-d4a8e7a65f97bb3257facc13e1ae8ffdbad61ddb.tar.gz PeerTube-d4a8e7a65f97bb3257facc13e1ae8ffdbad61ddb.tar.zst PeerTube-d4a8e7a65f97bb3257facc13e1ae8ffdbad61ddb.zip |
Support short uuid for GET video/playlist
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/actors/shared/object-to-model-attributes.ts | 4 | ||||
-rw-r--r-- | server/lib/client-html.ts | 9 | ||||
-rw-r--r-- | server/lib/local-actor.ts | 4 | ||||
-rw-r--r-- | server/lib/user.ts | 4 |
4 files changed, 13 insertions, 8 deletions
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 @@ | |||
1 | import { v4 as uuidv4 } from 'uuid' | ||
2 | import { getLowercaseExtension } from '@server/helpers/core-utils' | 1 | import { getLowercaseExtension } from '@server/helpers/core-utils' |
3 | import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc' | 2 | import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc' |
3 | import { buildUUID } from '@server/helpers/uuid' | ||
4 | import { MIMETYPES } from '@server/initializers/constants' | 4 | import { MIMETYPES } from '@server/initializers/constants' |
5 | import { ActorModel } from '@server/models/actor/actor' | 5 | import { ActorModel } from '@server/models/actor/actor' |
6 | import { FilteredModelAttributes } from '@server/types' | 6 | import { FilteredModelAttributes } from '@server/types' |
@@ -51,7 +51,7 @@ function getImageInfoFromObject (actorObject: ActivityPubActor, type: ActorImage | |||
51 | if (!extension) return undefined | 51 | if (!extension) return undefined |
52 | 52 | ||
53 | return { | 53 | return { |
54 | name: uuidv4() + extension, | 54 | name: buildUUID() + extension, |
55 | fileUrl: icon.url, | 55 | fileUrl: icon.url, |
56 | height: icon.height, | 56 | height: icon.height, |
57 | width: icon.width, | 57 | 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' | |||
27 | import { VideoPlaylistModel } from '../models/video/video-playlist' | 27 | import { VideoPlaylistModel } from '../models/video/video-playlist' |
28 | import { MAccountActor, MChannelActor } from '../types/models' | 28 | import { MAccountActor, MChannelActor } from '../types/models' |
29 | import { ServerConfigManager } from './server-config-manager' | 29 | import { ServerConfigManager } from './server-config-manager' |
30 | import { toCompleteUUID } from '@server/helpers/custom-validators/misc' | ||
30 | 31 | ||
31 | type Tags = { | 32 | type Tags = { |
32 | ogType: string | 33 | ogType: string |
@@ -78,7 +79,9 @@ class ClientHtml { | |||
78 | return customHtml | 79 | return customHtml |
79 | } | 80 | } |
80 | 81 | ||
81 | static async getWatchHTMLPage (videoId: string, req: express.Request, res: express.Response) { | 82 | static async getWatchHTMLPage (videoIdArg: string, req: express.Request, res: express.Response) { |
83 | const videoId = toCompleteUUID(videoIdArg) | ||
84 | |||
82 | // Let Angular application handle errors | 85 | // Let Angular application handle errors |
83 | if (!validator.isInt(videoId) && !validator.isUUID(videoId, 4)) { | 86 | if (!validator.isInt(videoId) && !validator.isUUID(videoId, 4)) { |
84 | res.status(HttpStatusCode.NOT_FOUND_404) | 87 | res.status(HttpStatusCode.NOT_FOUND_404) |
@@ -136,7 +139,9 @@ class ClientHtml { | |||
136 | return customHtml | 139 | return customHtml |
137 | } | 140 | } |
138 | 141 | ||
139 | static async getWatchPlaylistHTMLPage (videoPlaylistId: string, req: express.Request, res: express.Response) { | 142 | static async getWatchPlaylistHTMLPage (videoPlaylistIdArg: string, req: express.Request, res: express.Response) { |
143 | const videoPlaylistId = toCompleteUUID(videoPlaylistIdArg) | ||
144 | |||
140 | // Let Angular application handle errors | 145 | // Let Angular application handle errors |
141 | if (!validator.isInt(videoPlaylistId) && !validator.isUUID(videoPlaylistId, 4)) { | 146 | if (!validator.isInt(videoPlaylistId) && !validator.isUUID(videoPlaylistId, 4)) { |
142 | res.status(HttpStatusCode.NOT_FOUND_404) | 147 | 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' | |||
2 | import { queue } from 'async' | 2 | import { queue } from 'async' |
3 | import * as LRUCache from 'lru-cache' | 3 | import * as LRUCache from 'lru-cache' |
4 | import { join } from 'path' | 4 | import { join } from 'path' |
5 | import { v4 as uuidv4 } from 'uuid' | ||
6 | import { getLowercaseExtension } from '@server/helpers/core-utils' | 5 | import { getLowercaseExtension } from '@server/helpers/core-utils' |
6 | import { buildUUID } from '@server/helpers/uuid' | ||
7 | import { ActorModel } from '@server/models/actor/actor' | 7 | import { ActorModel } from '@server/models/actor/actor' |
8 | import { ActivityPubActorType, ActorImageType } from '@shared/models' | 8 | import { ActivityPubActorType, ActorImageType } from '@shared/models' |
9 | import { retryTransactionWrapper } from '../helpers/database-utils' | 9 | import { retryTransactionWrapper } from '../helpers/database-utils' |
@@ -44,7 +44,7 @@ async function updateLocalActorImageFile ( | |||
44 | 44 | ||
45 | const extension = getLowercaseExtension(imagePhysicalFile.filename) | 45 | const extension = getLowercaseExtension(imagePhysicalFile.filename) |
46 | 46 | ||
47 | const imageName = uuidv4() + extension | 47 | const imageName = buildUUID() + extension |
48 | const destination = join(CONFIG.STORAGE.ACTOR_IMAGES, imageName) | 48 | const destination = join(CONFIG.STORAGE.ACTOR_IMAGES, imageName) |
49 | await processImage(imagePhysicalFile.path, destination, imageSize) | 49 | await processImage(imagePhysicalFile.path, destination, imageSize) |
50 | 50 | ||
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 @@ | |||
1 | import { Transaction } from 'sequelize/types' | 1 | import { Transaction } from 'sequelize/types' |
2 | import { v4 as uuidv4 } from 'uuid' | 2 | import { buildUUID } from '@server/helpers/uuid' |
3 | import { UserModel } from '@server/models/user/user' | 3 | import { UserModel } from '@server/models/user/user' |
4 | import { MActorDefault } from '@server/types/models/actor' | 4 | import { MActorDefault } from '@server/types/models/actor' |
5 | import { ActivityPubActorType } from '../../shared/models/activitypub' | 5 | import { ActivityPubActorType } from '../../shared/models/activitypub' |
@@ -210,7 +210,7 @@ async function buildChannelAttributes (user: MUser, transaction?: Transaction, c | |||
210 | 210 | ||
211 | // Conflict, generate uuid instead | 211 | // Conflict, generate uuid instead |
212 | const actor = await ActorModel.loadLocalByName(channelName, transaction) | 212 | const actor = await ActorModel.loadLocalByName(channelName, transaction) |
213 | if (actor) channelName = uuidv4() | 213 | if (actor) channelName = buildUUID() |
214 | 214 | ||
215 | const videoChannelDisplayName = `Main ${user.username} channel` | 215 | const videoChannelDisplayName = `Main ${user.username} channel` |
216 | 216 | ||