ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

210 lines
6.0 KiB

  1. import cors from 'cors'
  2. import express from 'express'
  3. import { HttpNodeinfoDiasporaSoftwareNsSchema20, HttpStatusCode } from '@peertube/peertube-models'
  4. import { CONFIG, isEmailEnabled } from '@server/initializers/config.js'
  5. import { serveIndexHTML } from '@server/lib/html/client-html.js'
  6. import { ServerConfigManager } from '@server/lib/server-config-manager.js'
  7. import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION, ROUTE_CACHE_LIFETIME } from '../initializers/constants.js'
  8. import { getThemeOrDefault } from '../lib/plugins/theme-utils.js'
  9. import { cacheRoute } from '../middlewares/cache/cache.js'
  10. import { apiRateLimiter, asyncMiddleware } from '../middlewares/index.js'
  11. import { UserModel } from '../models/user/user.js'
  12. import { VideoCommentModel } from '../models/video/video-comment.js'
  13. import { VideoModel } from '../models/video/video.js'
  14. const miscRouter = express.Router()
  15. miscRouter.use(cors())
  16. miscRouter.use('/nodeinfo/:version.json',
  17. apiRateLimiter,
  18. cacheRoute(ROUTE_CACHE_LIFETIME.NODEINFO),
  19. asyncMiddleware(generateNodeinfo)
  20. )
  21. // robots.txt service
  22. miscRouter.get('/robots.txt',
  23. apiRateLimiter,
  24. cacheRoute(ROUTE_CACHE_LIFETIME.ROBOTS),
  25. (_, res: express.Response) => {
  26. res.type('text/plain')
  27. return res.send(CONFIG.INSTANCE.ROBOTS)
  28. }
  29. )
  30. miscRouter.all('/teapot',
  31. apiRateLimiter,
  32. getCup,
  33. asyncMiddleware(serveIndexHTML)
  34. )
  35. // security.txt service
  36. miscRouter.get('/security.txt',
  37. apiRateLimiter,
  38. (_, res: express.Response) => {
  39. return res.redirect(HttpStatusCode.MOVED_PERMANENTLY_301, '/.well-known/security.txt')
  40. }
  41. )
  42. // ---------------------------------------------------------------------------
  43. export {
  44. miscRouter
  45. }
  46. // ---------------------------------------------------------------------------
  47. async function generateNodeinfo (req: express.Request, res: express.Response) {
  48. const { totalVideos } = await VideoModel.getStats()
  49. const { totalLocalVideoComments } = await VideoCommentModel.getStats()
  50. const { totalUsers, totalMonthlyActiveUsers, totalHalfYearActiveUsers } = await UserModel.getStats()
  51. if (!req.params.version || req.params.version !== '2.0') {
  52. return res.fail({
  53. status: HttpStatusCode.NOT_FOUND_404,
  54. message: 'Nodeinfo schema version not handled'
  55. })
  56. }
  57. const json = {
  58. version: '2.0',
  59. software: {
  60. name: 'peertube',
  61. version: PEERTUBE_VERSION
  62. },
  63. protocols: [
  64. 'activitypub'
  65. ],
  66. services: {
  67. inbound: [],
  68. outbound: [
  69. 'atom1.0',
  70. 'rss2.0'
  71. ]
  72. },
  73. openRegistrations: CONFIG.SIGNUP.ENABLED,
  74. usage: {
  75. users: {
  76. total: totalUsers,
  77. activeMonth: totalMonthlyActiveUsers,
  78. activeHalfyear: totalHalfYearActiveUsers
  79. },
  80. localPosts: totalVideos,
  81. localComments: totalLocalVideoComments
  82. },
  83. metadata: {
  84. taxonomy: {
  85. postsName: 'Videos'
  86. },
  87. nodeName: CONFIG.INSTANCE.NAME,
  88. nodeDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION,
  89. nodeConfig: {
  90. search: {
  91. remoteUri: {
  92. users: CONFIG.SEARCH.REMOTE_URI.USERS,
  93. anonymous: CONFIG.SEARCH.REMOTE_URI.ANONYMOUS
  94. }
  95. },
  96. plugin: {
  97. registered: ServerConfigManager.Instance.getRegisteredPlugins()
  98. },
  99. theme: {
  100. registered: ServerConfigManager.Instance.getRegisteredThemes(),
  101. default: getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME)
  102. },
  103. email: {
  104. enabled: isEmailEnabled()
  105. },
  106. contactForm: {
  107. enabled: CONFIG.CONTACT_FORM.ENABLED
  108. },
  109. transcoding: {
  110. hls: {
  111. enabled: CONFIG.TRANSCODING.HLS.ENABLED
  112. },
  113. web_videos: {
  114. enabled: CONFIG.TRANSCODING.WEB_VIDEOS.ENABLED
  115. },
  116. enabledResolutions: ServerConfigManager.Instance.getEnabledResolutions('vod')
  117. },
  118. live: {
  119. enabled: CONFIG.LIVE.ENABLED,
  120. transcoding: {
  121. enabled: CONFIG.LIVE.TRANSCODING.ENABLED,
  122. enabledResolutions: ServerConfigManager.Instance.getEnabledResolutions('live')
  123. }
  124. },
  125. import: {
  126. videos: {
  127. http: {
  128. enabled: CONFIG.IMPORT.VIDEOS.HTTP.ENABLED
  129. },
  130. torrent: {
  131. enabled: CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED
  132. }
  133. }
  134. },
  135. autoBlacklist: {
  136. videos: {
  137. ofUsers: {
  138. enabled: CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED
  139. }
  140. }
  141. },
  142. avatar: {
  143. file: {
  144. size: {
  145. max: CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max
  146. },
  147. extensions: CONSTRAINTS_FIELDS.ACTORS.IMAGE.EXTNAME
  148. }
  149. },
  150. video: {
  151. image: {
  152. extensions: CONSTRAINTS_FIELDS.VIDEOS.IMAGE.EXTNAME,
  153. size: {
  154. max: CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max
  155. }
  156. },
  157. file: {
  158. extensions: CONSTRAINTS_FIELDS.VIDEOS.EXTNAME
  159. }
  160. },
  161. videoCaption: {
  162. file: {
  163. size: {
  164. max: CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max
  165. },
  166. extensions: CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.EXTNAME
  167. }
  168. },
  169. user: {
  170. videoQuota: CONFIG.USER.VIDEO_QUOTA,
  171. videoQuotaDaily: CONFIG.USER.VIDEO_QUOTA_DAILY
  172. },
  173. trending: {
  174. videos: {
  175. intervalDays: CONFIG.TRENDING.VIDEOS.INTERVAL_DAYS
  176. }
  177. },
  178. tracker: {
  179. enabled: CONFIG.TRACKER.ENABLED
  180. }
  181. }
  182. }
  183. } as HttpNodeinfoDiasporaSoftwareNsSchema20
  184. res.contentType('application/json; profile="http://nodeinfo.diaspora.software/ns/schema/2.0#"')
  185. .send(json)
  186. .end()
  187. }
  188. function getCup (req: express.Request, res: express.Response, next: express.NextFunction) {
  189. res.status(HttpStatusCode.I_AM_A_TEAPOT_418)
  190. res.setHeader('Accept-Additions', 'Non-Dairy;1,Sugar;1')
  191. res.setHeader('Safe', 'if-sepia-awake')
  192. return next()
  193. }