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