express.d.ts 6.6 KB

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