aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2018-07-21 23:00:25 +0200
committerChocobozzz <me@florianbigard.com>2018-07-24 14:08:44 +0200
commit3f6d68d9671ddb7ba1c4f3a35021b84856dafb6a (patch)
tree4a84a6a532fa042710c88edbaa5a5613173e00e3 /server/controllers
parent4278710d5b48546709720fac46657b84bba52a18 (diff)
downloadPeerTube-3f6d68d9671ddb7ba1c4f3a35021b84856dafb6a.tar.gz
PeerTube-3f6d68d9671ddb7ba1c4f3a35021b84856dafb6a.tar.zst
PeerTube-3f6d68d9671ddb7ba1c4f3a35021b84856dafb6a.zip
adding initial support for nodeinfo
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/activitypub/client.ts5
-rw-r--r--server/controllers/feeds.ts6
-rw-r--r--server/controllers/static.ts85
3 files changed, 85 insertions, 11 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts
index 3e6361906..ebb2c06a2 100644
--- a/server/controllers/activitypub/client.ts
+++ b/server/controllers/activitypub/client.ts
@@ -16,7 +16,7 @@ import { VideoModel } from '../../models/video/video'
16import { VideoChannelModel } from '../../models/video/video-channel' 16import { VideoChannelModel } from '../../models/video/video-channel'
17import { VideoCommentModel } from '../../models/video/video-comment' 17import { VideoCommentModel } from '../../models/video/video-comment'
18import { VideoShareModel } from '../../models/video/video-share' 18import { VideoShareModel } from '../../models/video/video-share'
19import { cacheRoute } from '../../middlewares/cache' 19import { cache } from '../../middlewares/cache'
20import { activityPubResponse } from './utils' 20import { activityPubResponse } from './utils'
21import { AccountVideoRateModel } from '../../models/account/account-video-rate' 21import { AccountVideoRateModel } from '../../models/account/account-video-rate'
22import { 22import {
@@ -25,7 +25,6 @@ import {
25 getVideoLikesActivityPubUrl, 25 getVideoLikesActivityPubUrl,
26 getVideoSharesActivityPubUrl 26 getVideoSharesActivityPubUrl
27} from '../../lib/activitypub' 27} from '../../lib/activitypub'
28import { VideoCaption } from '../../../shared/models/videos/video-caption.model'
29import { VideoCaptionModel } from '../../models/video/video-caption' 28import { VideoCaptionModel } from '../../models/video/video-caption'
30 29
31const activityPubClientRouter = express.Router() 30const activityPubClientRouter = express.Router()
@@ -44,7 +43,7 @@ activityPubClientRouter.get('/accounts?/:name/following',
44) 43)
45 44
46activityPubClientRouter.get('/videos/watch/:id', 45activityPubClientRouter.get('/videos/watch/:id',
47 executeIfActivityPub(asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS))), 46 executeIfActivityPub(asyncMiddleware(cache(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS))),
48 executeIfActivityPub(asyncMiddleware(videosGetValidator)), 47 executeIfActivityPub(asyncMiddleware(videosGetValidator)),
49 executeIfActivityPub(asyncMiddleware(videoController)) 48 executeIfActivityPub(asyncMiddleware(videoController))
50) 49)
diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts
index 682f4abda..6cbe42a2a 100644
--- a/server/controllers/feeds.ts
+++ b/server/controllers/feeds.ts
@@ -5,7 +5,7 @@ import { asyncMiddleware, setDefaultSort, videoCommentsFeedsValidator, videoFeed
5import { VideoModel } from '../models/video/video' 5import { VideoModel } from '../models/video/video'
6import * as Feed from 'pfeed' 6import * as Feed from 'pfeed'
7import { AccountModel } from '../models/account/account' 7import { AccountModel } from '../models/account/account'
8import { cacheRoute } from '../middlewares/cache' 8import { cache } from '../middlewares/cache'
9import { VideoChannelModel } from '../models/video/video-channel' 9import { VideoChannelModel } from '../models/video/video-channel'
10import { VideoCommentModel } from '../models/video/video-comment' 10import { VideoCommentModel } from '../models/video/video-comment'
11import { buildNSFWFilter } from '../helpers/express-utils' 11import { buildNSFWFilter } from '../helpers/express-utils'
@@ -13,7 +13,7 @@ import { buildNSFWFilter } from '../helpers/express-utils'
13const feedsRouter = express.Router() 13const feedsRouter = express.Router()
14 14
15feedsRouter.get('/feeds/video-comments.:format', 15feedsRouter.get('/feeds/video-comments.:format',
16 asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.FEEDS)), 16 asyncMiddleware(cache(ROUTE_CACHE_LIFETIME.FEEDS)),
17 asyncMiddleware(videoCommentsFeedsValidator), 17 asyncMiddleware(videoCommentsFeedsValidator),
18 asyncMiddleware(generateVideoCommentsFeed) 18 asyncMiddleware(generateVideoCommentsFeed)
19) 19)
@@ -21,7 +21,7 @@ feedsRouter.get('/feeds/video-comments.:format',
21feedsRouter.get('/feeds/videos.:format', 21feedsRouter.get('/feeds/videos.:format',
22 videosSortValidator, 22 videosSortValidator,
23 setDefaultSort, 23 setDefaultSort,
24 asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.FEEDS)), 24 asyncMiddleware(cache(ROUTE_CACHE_LIFETIME.FEEDS)),
25 asyncMiddleware(videoFeedsValidator), 25 asyncMiddleware(videoFeedsValidator),
26 asyncMiddleware(generateVideoFeed) 26 asyncMiddleware(generateVideoFeed)
27) 27)
diff --git a/server/controllers/static.ts b/server/controllers/static.ts
index 8de9c5a78..ce5d0c5fa 100644
--- a/server/controllers/static.ts
+++ b/server/controllers/static.ts
@@ -1,11 +1,16 @@
1import * as cors from 'cors' 1import * as cors from 'cors'
2import * as express from 'express' 2import * as express from 'express'
3import { CONFIG, STATIC_DOWNLOAD_PATHS, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers' 3import { CONFIG, STATIC_DOWNLOAD_PATHS, STATIC_MAX_AGE, STATIC_PATHS, ROUTE_CACHE_LIFETIME } from '../initializers'
4import { VideosPreviewCache } from '../lib/cache' 4import { VideosPreviewCache } from '../lib/cache'
5import { cache } from '../middlewares/cache'
5import { asyncMiddleware, videosGetValidator } from '../middlewares' 6import { asyncMiddleware, videosGetValidator } from '../middlewares'
6import { VideoModel } from '../models/video/video' 7import { VideoModel } from '../models/video/video'
7import { VideosCaptionCache } from '../lib/cache/videos-caption-cache' 8import { VideosCaptionCache } from '../lib/cache/videos-caption-cache'
9import { UserModel } from '../models/account/user'
10import { VideoCommentModel } from '../models/video/video-comment'
11import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../models/nodeinfo'
8 12
13const packageJSON = require('../../../package.json')
9const staticRouter = express.Router() 14const staticRouter = express.Router()
10 15
11staticRouter.use(cors()) 16staticRouter.use(cors())
@@ -65,10 +70,32 @@ staticRouter.use(
65) 70)
66 71
67// robots.txt service 72// robots.txt service
68staticRouter.get('/robots.txt', (req: express.Request, res: express.Response) => { 73staticRouter.get('/robots.txt',
69 res.type('text/plain') 74 asyncMiddleware(cache(ROUTE_CACHE_LIFETIME.ROBOTS)),
70 return res.send(CONFIG.INSTANCE.ROBOTS) 75 (_, res: express.Response) => {
71}) 76 res.type('text/plain')
77 return res.send(CONFIG.INSTANCE.ROBOTS)
78 }
79)
80
81// nodeinfo service
82staticRouter.use('/.well-known/nodeinfo',
83 asyncMiddleware(cache(ROUTE_CACHE_LIFETIME.NODEINFO)),
84 (_, res: express.Response) => {
85 return res.json({
86 links: [
87 {
88 rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0',
89 href: CONFIG.WEBSERVER.URL + '/nodeinfo/2.0.json'
90 }
91 ]
92 })
93 }
94)
95staticRouter.use('/nodeinfo/:version.json',
96 asyncMiddleware(cache(ROUTE_CACHE_LIFETIME.NODEINFO)),
97 asyncMiddleware(generateNodeinfo)
98)
72 99
73// --------------------------------------------------------------------------- 100// ---------------------------------------------------------------------------
74 101
@@ -95,6 +122,54 @@ async function getVideoCaption (req: express.Request, res: express.Response) {
95 return res.sendFile(path, { maxAge: STATIC_MAX_AGE }) 122 return res.sendFile(path, { maxAge: STATIC_MAX_AGE })
96} 123}
97 124
125async function generateNodeinfo (req: express.Request, res: express.Response, next: express.NextFunction) {
126 const { totalVideos } = await VideoModel.getStats()
127 const { totalLocalVideoComments } = await VideoCommentModel.getStats()
128 const { totalUsers } = await UserModel.getStats()
129 let json = {}
130
131 if (req.params.version && (req.params.version === '2.0')) {
132 json = {
133 version: '2.0',
134 software: {
135 name: 'peertube',
136 version: packageJSON.version
137 },
138 protocols: [
139 'activitypub'
140 ],
141 services: {
142 inbound: [],
143 outbound: [
144 'atom1.0',
145 'rss2.0'
146 ]
147 },
148 openRegistrations: CONFIG.SIGNUP.ENABLED,
149 usage: {
150 users: {
151 total: totalUsers
152 },
153 localPosts: totalVideos,
154 localComments: totalLocalVideoComments
155 },
156 metadata: {
157 taxonomy: {
158 postsName: 'Videos'
159 },
160 nodeName: CONFIG.INSTANCE.NAME,
161 nodeDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION
162 }
163 } as HttpNodeinfoDiasporaSoftwareNsSchema20
164 res.set('Content-Type', 'application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8')
165 } else {
166 json = { error: 'Nodeinfo schema version not handled' }
167 res.status(404)
168 }
169
170 return res.end(JSON.stringify(json))
171}
172
98async function downloadTorrent (req: express.Request, res: express.Response, next: express.NextFunction) { 173async function downloadTorrent (req: express.Request, res: express.Response, next: express.NextFunction) {
99 const { video, videoFile } = getVideoAndFile(req, res) 174 const { video, videoFile } = getVideoAndFile(req, res)
100 if (!videoFile) return res.status(404).end() 175 if (!videoFile) return res.status(404).end()