]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/typings/express/index.d.ts
Refactor server errors handler
[github/Chocobozzz/PeerTube.git] / server / typings / express / index.d.ts
... / ...
CommitLineData
1
2import { RegisterServerAuthExternalOptions } from '@server/types'
3import {
4 MAbuseMessage,
5 MAbuseReporter,
6 MAccountBlocklist,
7 MActorFollowActorsDefault,
8 MActorUrl,
9 MChannelBannerAccountDefault,
10 MStreamingPlaylist,
11 MVideoChangeOwnershipFull,
12 MVideoFile,
13 MVideoImmutable,
14 MVideoLive,
15 MVideoPlaylistFull,
16 MVideoPlaylistFullSummary
17} from '@server/types/models'
18import { MOAuthTokenUser } from '@server/types/models/oauth/oauth-token'
19import { MPlugin, MServer, MServerBlocklist } from '@server/types/models/server'
20import { MVideoImportDefault } from '@server/types/models/video/video-import'
21import { MVideoPlaylistElement, MVideoPlaylistElementVideoUrlPlaylistPrivacy } from '@server/types/models/video/video-playlist-element'
22import { MAccountVideoRateAccountVideo } from '@server/types/models/video/video-rate'
23import { HttpMethod } from '@shared/core-utils/miscs/http-methods'
24import { PeerTubeProblemDocumentData, ServerErrorCode, VideoCreate } from '@shared/models'
25import { File as UploadXFile, Metadata } from '@uploadx/core'
26import { RegisteredPlugin } from '../../lib/plugins/plugin-manager'
27import {
28 MAccountDefault,
29 MActorAccountChannelId,
30 MActorFollowActorsDefaultSubscription,
31 MActorFull,
32 MComment,
33 MCommentOwnerVideoReply,
34 MUserDefault,
35 MVideoBlacklist,
36 MVideoCaptionVideo,
37 MVideoFullLight,
38 MVideoIdThumbnail,
39 MVideoRedundancyVideo,
40 MVideoShareActor,
41 MVideoThumbnail,
42 MVideoWithRights
43} from '../../types/models'
44
45declare module 'express' {
46 export interface Request {
47 query: any
48 method: HttpMethod
49 }
50
51 // Upload using multer or uploadx middleware
52 export type MulterOrUploadXFile = UploadXFile | Express.Multer.File
53
54 export type UploadFiles = {
55 [fieldname: string]: MulterOrUploadXFile[]
56 } | MulterOrUploadXFile[]
57
58 // Partial object used by some functions to check the file mimetype/extension
59 export type UploadFileForCheck = {
60 originalname: string
61 mimetype: string
62 }
63
64 export type UploadFilesForCheck = {
65 [fieldname: string]: UploadFileForCheck[]
66 } | UploadFileForCheck[]
67
68 // Upload file with a duration added by our middleware
69 export type VideoUploadFile = Pick<Express.Multer.File, 'path' | 'filename' | 'size'> & {
70 duration: number
71 }
72
73 // Extends Metadata property of UploadX object
74 export type UploadXFileMetadata = Metadata & VideoCreate & {
75 previewfile: Express.Multer.File[]
76 thumbnailfile: Express.Multer.File[]
77 }
78
79 // Our custom UploadXFile object using our custom metadata
80 export type CustomUploadXFile <T extends Metadata> = UploadXFile & { metadata: T }
81
82 export type EnhancedUploadXFile = CustomUploadXFile<UploadXFileMetadata> & {
83 duration: number
84 path: string
85 filename: string
86 }
87
88 // Extends Response with added functions and potential variables passed by middlewares
89 interface Response {
90 fail: (options: {
91 message: string
92
93 title?: string
94 status?: number
95 type?: ServerErrorCode
96 instance?: string
97
98 data?: PeerTubeProblemDocumentData
99 }) => void
100
101 locals: {
102 docUrl?: string
103
104 videoAll?: MVideoFullLight
105 onlyImmutableVideo?: MVideoImmutable
106 onlyVideo?: MVideoThumbnail
107 onlyVideoWithRights?: MVideoWithRights
108 videoId?: MVideoIdThumbnail
109
110 videoLive?: MVideoLive
111
112 videoShare?: MVideoShareActor
113
114 videoFile?: MVideoFile
115
116 videoFileResumable?: EnhancedUploadXFile
117
118 videoImport?: MVideoImportDefault
119
120 videoBlacklist?: MVideoBlacklist
121
122 videoCaption?: MVideoCaptionVideo
123
124 abuse?: MAbuseReporter
125 abuseMessage?: MAbuseMessage
126
127 videoStreamingPlaylist?: MStreamingPlaylist
128
129 videoChannel?: MChannelBannerAccountDefault
130
131 videoPlaylistFull?: MVideoPlaylistFull
132 videoPlaylistSummary?: MVideoPlaylistFullSummary
133
134 videoPlaylistElement?: MVideoPlaylistElement
135 videoPlaylistElementAP?: MVideoPlaylistElementVideoUrlPlaylistPrivacy
136
137 accountVideoRate?: MAccountVideoRateAccountVideo
138
139 videoCommentFull?: MCommentOwnerVideoReply
140 videoCommentThread?: MComment
141
142 follow?: MActorFollowActorsDefault
143 subscription?: MActorFollowActorsDefaultSubscription
144
145 nextOwner?: MAccountDefault
146 videoChangeOwnership?: MVideoChangeOwnershipFull
147
148 account?: MAccountDefault
149
150 actorUrl?: MActorUrl
151 actorFull?: MActorFull
152
153 user?: MUserDefault
154
155 server?: MServer
156
157 videoRedundancy?: MVideoRedundancyVideo
158
159 accountBlock?: MAccountBlocklist
160 serverBlock?: MServerBlocklist
161
162 oauth?: {
163 token: MOAuthTokenUser
164 }
165
166 signature?: {
167 actor: MActorAccountChannelId
168 }
169
170 authenticated?: boolean
171
172 registeredPlugin?: RegisteredPlugin
173
174 externalAuth?: RegisterServerAuthExternalOptions
175
176 plugin?: MPlugin
177 }
178 }
179}