diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-31 14:34:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-08-11 15:02:33 +0200 |
commit | 3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch) | |
tree | e4510b39bdac9c318fdb4b47018d08f15368b8f0 /server/controllers/feeds/comment-feeds.ts | |
parent | 04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff) | |
download | PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip |
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge
conflicts, but it's a major step forward:
* Server can be faster at startup because imports() are async and we can
easily lazy import big modules
* Angular doesn't seem to support ES import (with .js extension), so we
had to correctly organize peertube into a monorepo:
* Use yarn workspace feature
* Use typescript reference projects for dependencies
* Shared projects have been moved into "packages", each one is now a
node module (with a dedicated package.json/tsconfig.json)
* server/tools have been moved into apps/ and is now a dedicated app
bundled and published on NPM so users don't have to build peertube
cli tools manually
* server/tests have been moved into packages/ so we don't compile
them every time we want to run the server
* Use isolatedModule option:
* Had to move from const enum to const
(https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums)
* Had to explictely specify "type" imports when used in decorators
* Prefer tsx (that uses esbuild under the hood) instead of ts-node to
load typescript files (tests with mocha or scripts):
* To reduce test complexity as esbuild doesn't support decorator
metadata, we only test server files that do not import server
models
* We still build tests files into js files for a faster CI
* Remove unmaintained peertube CLI import script
* Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'server/controllers/feeds/comment-feeds.ts')
-rw-r--r-- | server/controllers/feeds/comment-feeds.ts | 96 |
1 files changed, 0 insertions, 96 deletions
diff --git a/server/controllers/feeds/comment-feeds.ts b/server/controllers/feeds/comment-feeds.ts deleted file mode 100644 index c013662ea..000000000 --- a/server/controllers/feeds/comment-feeds.ts +++ /dev/null | |||
@@ -1,96 +0,0 @@ | |||
1 | import express from 'express' | ||
2 | import { toSafeHtml } from '@server/helpers/markdown' | ||
3 | import { cacheRouteFactory } from '@server/middlewares' | ||
4 | import { CONFIG } from '../../initializers/config' | ||
5 | import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../../initializers/constants' | ||
6 | import { | ||
7 | asyncMiddleware, | ||
8 | feedsFormatValidator, | ||
9 | setFeedFormatContentType, | ||
10 | videoCommentsFeedsValidator, | ||
11 | feedsAccountOrChannelFiltersValidator | ||
12 | } from '../../middlewares' | ||
13 | import { VideoCommentModel } from '../../models/video/video-comment' | ||
14 | import { buildFeedMetadata, initFeed, sendFeed } from './shared' | ||
15 | |||
16 | const commentFeedsRouter = express.Router() | ||
17 | |||
18 | // --------------------------------------------------------------------------- | ||
19 | |||
20 | const { middleware: cacheRouteMiddleware } = cacheRouteFactory({ | ||
21 | headerBlacklist: [ 'Content-Type' ] | ||
22 | }) | ||
23 | |||
24 | // --------------------------------------------------------------------------- | ||
25 | |||
26 | commentFeedsRouter.get('/video-comments.:format', | ||
27 | feedsFormatValidator, | ||
28 | setFeedFormatContentType, | ||
29 | cacheRouteMiddleware(ROUTE_CACHE_LIFETIME.FEEDS), | ||
30 | asyncMiddleware(feedsAccountOrChannelFiltersValidator), | ||
31 | asyncMiddleware(videoCommentsFeedsValidator), | ||
32 | asyncMiddleware(generateVideoCommentsFeed) | ||
33 | ) | ||
34 | |||
35 | // --------------------------------------------------------------------------- | ||
36 | |||
37 | export { | ||
38 | commentFeedsRouter | ||
39 | } | ||
40 | |||
41 | // --------------------------------------------------------------------------- | ||
42 | |||
43 | async function generateVideoCommentsFeed (req: express.Request, res: express.Response) { | ||
44 | const start = 0 | ||
45 | const video = res.locals.videoAll | ||
46 | const account = res.locals.account | ||
47 | const videoChannel = res.locals.videoChannel | ||
48 | |||
49 | const comments = await VideoCommentModel.listForFeed({ | ||
50 | start, | ||
51 | count: CONFIG.FEEDS.COMMENTS.COUNT, | ||
52 | videoId: video ? video.id : undefined, | ||
53 | accountId: account ? account.id : undefined, | ||
54 | videoChannelId: videoChannel ? videoChannel.id : undefined | ||
55 | }) | ||
56 | |||
57 | const { name, description, imageUrl, link } = await buildFeedMetadata({ video, account, videoChannel }) | ||
58 | |||
59 | const feed = initFeed({ | ||
60 | name, | ||
61 | description, | ||
62 | imageUrl, | ||
63 | isPodcast: false, | ||
64 | link, | ||
65 | resourceType: 'video-comments', | ||
66 | queryString: new URL(WEBSERVER.URL + req.originalUrl).search | ||
67 | }) | ||
68 | |||
69 | // Adding video items to the feed, one at a time | ||
70 | for (const comment of comments) { | ||
71 | const localLink = WEBSERVER.URL + comment.getCommentStaticPath() | ||
72 | |||
73 | let title = comment.Video.name | ||
74 | const author: { name: string, link: string }[] = [] | ||
75 | |||
76 | if (comment.Account) { | ||
77 | title += ` - ${comment.Account.getDisplayName()}` | ||
78 | author.push({ | ||
79 | name: comment.Account.getDisplayName(), | ||
80 | link: comment.Account.Actor.url | ||
81 | }) | ||
82 | } | ||
83 | |||
84 | feed.addItem({ | ||
85 | title, | ||
86 | id: localLink, | ||
87 | link: localLink, | ||
88 | content: toSafeHtml(comment.text), | ||
89 | author, | ||
90 | date: comment.createdAt | ||
91 | }) | ||
92 | } | ||
93 | |||
94 | // Now the feed generation is done, let's send it! | ||
95 | return sendFeed(feed, req, res) | ||
96 | } | ||