express.d.ts 5.4 KB

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