aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/types/express.d.ts
blob: 510b9f94ea27d3c6ec0f6c0451254a54465378d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import { OutgoingHttpHeaders } from 'http'
import { Writable } from 'stream'
import { RegisterServerAuthExternalOptions } from '@server/types'
import {
  MAbuseMessage,
  MAbuseReporter,
  MAccountBlocklist,
  MActorFollowActorsDefault,
  MActorUrl,
  MChannelBannerAccountDefault,
  MChannelSyncChannel,
  MRegistration,
  MStreamingPlaylist,
  MUserAccountUrl,
  MVideoChangeOwnershipFull,
  MVideoFile,
  MVideoFormattableDetails,
  MVideoId,
  MVideoImmutable,
  MVideoLiveFormattable,
  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 './models'
import { MRunner, MRunnerJobRunner, MRunnerRegistrationToken } from './models/runners'
import { MVideoSource } from './models/video/video-source'

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
    size: number
  }

  export type UploadFilesForCheck = {
    [fieldname: string]: UploadFileForCheck[]
  } | UploadFileForCheck[]

  // Upload file with a duration added by our middleware
  export type VideoUploadFile = Pick<Express.Multer.File, 'path' | 'filename' | 'size', 'originalname'> & {
    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 <T extends Metadata> = UploadXFile & { metadata: T }

  export type EnhancedUploadXFile = CustomUploadXFile<UploadXFileMetadata> & {
    duration: number
    path: string
    filename: string
    originalname: string
  }

  // Extends Response with added functions and potential variables passed by middlewares
  interface Response {
    fail: (options: {
      message: string

      title?: string
      status?: number
      type?: ServerErrorCode | string
      instance?: string

      data?: PeerTubeProblemDocumentData

      tags?: string[]
    }) => void

    locals: {
      requestStart: number

      apicacheGroups: string[]

      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?: MVideoLiveFormattable
      videoLiveSession?: MVideoLiveSession

      videoShare?: MVideoShareActor

      videoSource?: MVideoSource

      videoFile?: MVideoFile

      videoFileResumable?: EnhancedUploadXFile

      videoImport?: MVideoImportDefault

      videoBlacklist?: MVideoBlacklist

      videoCaption?: MVideoCaptionVideo

      abuse?: MAbuseReporter
      abuseMessage?: MAbuseMessage

      videoStreamingPlaylist?: MStreamingPlaylist

      videoChannel?: MChannelBannerAccountDefault
      videoChannelSync?: MChannelSyncChannel

      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
      userRegistration?: MRegistration

      server?: MServer

      videoRedundancy?: MVideoRedundancyVideo

      accountBlock?: MAccountBlocklist
      serverBlock?: MServerBlocklist

      oauth?: {
        token: MOAuthTokenUser
      }

      signature?: {
        actor: MActorAccountChannelId
      }

      videoFileToken?: {
        user: MUserAccountUrl
      }

      authenticated?: boolean

      registeredPlugin?: RegisteredPlugin

      externalAuth?: RegisterServerAuthExternalOptions

      plugin?: MPlugin

      localViewerFull?: MLocalVideoViewerWithWatchSections

      runner?: MRunner
      runnerRegistrationToken?: MRunnerRegistrationToken
      runnerJob?: MRunnerJobRunner
    }
  }
}