From f8360396ffabd2f95e9ece9c5755173bae0114b6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 3 Jan 2022 17:13:11 +0100 Subject: Stop using tsconfig register Prefer to replace paths at compile time --- server/types/express-handler.ts | 3 + server/types/express.d.ts | 189 ++++++++++++++++++++++++++++++++++++++++ server/types/express.ts | 3 - 3 files changed, 192 insertions(+), 3 deletions(-) create mode 100644 server/types/express-handler.ts create mode 100644 server/types/express.d.ts delete mode 100644 server/types/express.ts (limited to 'server/types') diff --git a/server/types/express-handler.ts b/server/types/express-handler.ts new file mode 100644 index 000000000..e72be36e4 --- /dev/null +++ b/server/types/express-handler.ts @@ -0,0 +1,3 @@ +import { NextFunction, Request, Response } from 'express' + +export type ExpressPromiseHandler = (req: Request, res: Response, next: NextFunction) => Promise diff --git a/server/types/express.d.ts b/server/types/express.d.ts new file mode 100644 index 000000000..1a99b598a --- /dev/null +++ b/server/types/express.d.ts @@ -0,0 +1,189 @@ + +import { OutgoingHttpHeaders } from 'http' +import { RegisterServerAuthExternalOptions } from '@server/types' +import { + MAbuseMessage, + MAbuseReporter, + MAccountBlocklist, + MActorFollowActorsDefault, + MActorUrl, + MChannelBannerAccountDefault, + MStreamingPlaylist, + MVideoChangeOwnershipFull, + MVideoFile, + MVideoFormattableDetails, + MVideoId, + MVideoImmutable, + MVideoLive, + MVideoPlaylistFull, + MVideoPlaylistFullSummary +} from '@server/types/models' +import { MOAuthTokenUser } from '@server/types/models/oauth/oauth-token' +import { MPlugin, MServer, MServerBlocklist } from '@server/types/models/server' +import { MVideoImportDefault } from '@server/types/models/video/video-import' +import { MVideoPlaylistElement, MVideoPlaylistElementVideoUrlPlaylistPrivacy } from '@server/types/models/video/video-playlist-element' +import { MAccountVideoRateAccountVideo } from '@server/types/models/video/video-rate' +import { HttpMethod, PeerTubeProblemDocumentData, ServerErrorCode, VideoCreate } from '@shared/models' +import { File as UploadXFile, Metadata } from '@uploadx/core' +import { RegisteredPlugin } from '../../lib/plugins/plugin-manager' +import { + MAccountDefault, + MActorAccountChannelId, + MActorFollowActorsDefaultSubscription, + MActorFull, + MComment, + MCommentOwnerVideoReply, + MUserDefault, + MVideoBlacklist, + MVideoCaptionVideo, + MVideoFullLight, + MVideoRedundancyVideo, + MVideoShareActor, + MVideoThumbnail +} from '../../types/models' +import { Writable } from 'stream' + +declare module 'express' { + export interface Request { + query: any + method: HttpMethod + } + + // Upload using multer or uploadx middleware + export type MulterOrUploadXFile = UploadXFile | Express.Multer.File + + export type UploadFiles = { + [fieldname: string]: MulterOrUploadXFile[] + } | MulterOrUploadXFile[] + + // Partial object used by some functions to check the file mimetype/extension + export type UploadFileForCheck = { + originalname: string + mimetype: string + } + + export type UploadFilesForCheck = { + [fieldname: string]: UploadFileForCheck[] + } | UploadFileForCheck[] + + // Upload file with a duration added by our middleware + export type VideoUploadFile = Pick & { + duration: number + } + + // Extends Metadata property of UploadX object + export type UploadXFileMetadata = Metadata & VideoCreate & { + previewfile: Express.Multer.File[] + thumbnailfile: Express.Multer.File[] + } + + // Our custom UploadXFile object using our custom metadata + export type CustomUploadXFile = UploadXFile & { metadata: T } + + export type EnhancedUploadXFile = CustomUploadXFile & { + duration: number + path: string + filename: string + } + + // Extends Response with added functions and potential variables passed by middlewares + interface Response { + fail: (options: { + message: string + + title?: string + status?: number + type?: ServerErrorCode + instance?: string + + data?: PeerTubeProblemDocumentData + }) => void + + locals: { + apicache: { + content: string | Buffer + write: Writable['write'] + writeHead: Response['writeHead'] + end: Response['end'] + cacheable: boolean + headers: OutgoingHttpHeaders + } + + docUrl?: string + + videoAPI?: MVideoFormattableDetails + videoAll?: MVideoFullLight + onlyImmutableVideo?: MVideoImmutable + onlyVideo?: MVideoThumbnail + videoId?: MVideoId + + videoLive?: MVideoLive + + videoShare?: MVideoShareActor + + videoFile?: MVideoFile + + videoFileResumable?: EnhancedUploadXFile + + videoImport?: MVideoImportDefault + + videoBlacklist?: MVideoBlacklist + + videoCaption?: MVideoCaptionVideo + + abuse?: MAbuseReporter + abuseMessage?: MAbuseMessage + + videoStreamingPlaylist?: MStreamingPlaylist + + videoChannel?: MChannelBannerAccountDefault + + videoPlaylistFull?: MVideoPlaylistFull + videoPlaylistSummary?: MVideoPlaylistFullSummary + + videoPlaylistElement?: MVideoPlaylistElement + videoPlaylistElementAP?: MVideoPlaylistElementVideoUrlPlaylistPrivacy + + accountVideoRate?: MAccountVideoRateAccountVideo + + videoCommentFull?: MCommentOwnerVideoReply + videoCommentThread?: MComment + + follow?: MActorFollowActorsDefault + subscription?: MActorFollowActorsDefaultSubscription + + nextOwner?: MAccountDefault + videoChangeOwnership?: MVideoChangeOwnershipFull + + account?: MAccountDefault + + actorUrl?: MActorUrl + actorFull?: MActorFull + + user?: MUserDefault + + server?: MServer + + videoRedundancy?: MVideoRedundancyVideo + + accountBlock?: MAccountBlocklist + serverBlock?: MServerBlocklist + + oauth?: { + token: MOAuthTokenUser + } + + signature?: { + actor: MActorAccountChannelId + } + + authenticated?: boolean + + registeredPlugin?: RegisteredPlugin + + externalAuth?: RegisterServerAuthExternalOptions + + plugin?: MPlugin + } + } +} diff --git a/server/types/express.ts b/server/types/express.ts deleted file mode 100644 index e72be36e4..000000000 --- a/server/types/express.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { NextFunction, Request, Response } from 'express' - -export type ExpressPromiseHandler = (req: Request, res: Response, next: NextFunction) => Promise -- cgit v1.2.3