diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-08 11:32:45 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-08 16:12:49 +0100 |
commit | 38d69d65012c8bf01bceb672be99f94fe414f275 (patch) | |
tree | 80ba6d43c4ce7ccff0c64d0c0817f43cc02a6531 /server | |
parent | 9b293cd6a2ce9ed1e1ccd41adbf7f2dbe2da8231 (diff) | |
download | PeerTube-38d69d65012c8bf01bceb672be99f94fe414f275.tar.gz PeerTube-38d69d65012c8bf01bceb672be99f94fe414f275.tar.zst PeerTube-38d69d65012c8bf01bceb672be99f94fe414f275.zip |
Update torrents info name on video update
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/videos/update.ts | 11 | ||||
-rw-r--r-- | server/helpers/webtorrent.ts | 3 | ||||
-rw-r--r-- | server/middlewares/error.ts | 10 |
3 files changed, 17 insertions, 7 deletions
diff --git a/server/controllers/api/videos/update.ts b/server/controllers/api/videos/update.ts index 6f14a6788..c0eb4ebee 100644 --- a/server/controllers/api/videos/update.ts +++ b/server/controllers/api/videos/update.ts | |||
@@ -69,7 +69,7 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
69 | }) | 69 | }) |
70 | 70 | ||
71 | try { | 71 | try { |
72 | const videoInstanceUpdated = await sequelizeTypescript.transaction(async t => { | 72 | const { videoInstanceUpdated, isNewVideo } = await sequelizeTypescript.transaction(async t => { |
73 | // Refresh video since thumbnails to prevent concurrent updates | 73 | // Refresh video since thumbnails to prevent concurrent updates |
74 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoFromReq.id, t) | 74 | const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoFromReq.id, t) |
75 | 75 | ||
@@ -138,8 +138,6 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
138 | transaction: t | 138 | transaction: t |
139 | }) | 139 | }) |
140 | 140 | ||
141 | await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t) | ||
142 | |||
143 | auditLogger.update( | 141 | auditLogger.update( |
144 | getAuditIdFromRes(res), | 142 | getAuditIdFromRes(res), |
145 | new VideoAuditView(videoInstanceUpdated.toFormattedDetailsJSON()), | 143 | new VideoAuditView(videoInstanceUpdated.toFormattedDetailsJSON()), |
@@ -147,10 +145,13 @@ async function updateVideo (req: express.Request, res: express.Response) { | |||
147 | ) | 145 | ) |
148 | logger.info('Video with name %s and uuid %s updated.', video.name, video.uuid, lTags(video.uuid)) | 146 | logger.info('Video with name %s and uuid %s updated.', video.name, video.uuid, lTags(video.uuid)) |
149 | 147 | ||
150 | return videoInstanceUpdated | 148 | return { videoInstanceUpdated, isNewVideo } |
151 | }) | 149 | }) |
152 | 150 | ||
153 | if (videoInfoToUpdate.name) await updateTorrentsMetadata(videoInstanceUpdated) | 151 | if (videoInfoToUpdate.name) await updateTorrentsMetadata(videoInstanceUpdated) |
152 | |||
153 | await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, undefined) | ||
154 | |||
154 | if (wasConfidentialVideo) Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated) | 155 | if (wasConfidentialVideo) Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated) |
155 | 156 | ||
156 | Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated, body: req.body, req, res }) | 157 | Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated, body: req.body, req, res }) |
@@ -203,5 +204,7 @@ function updateSchedule (videoInstance: MVideoFullLight, videoInfoToUpdate: Vide | |||
203 | async function updateTorrentsMetadata (video: MVideoFullLight) { | 204 | async function updateTorrentsMetadata (video: MVideoFullLight) { |
204 | for (const file of video.getAllFiles()) { | 205 | for (const file of video.getAllFiles()) { |
205 | await updateTorrentMetadata(video, file) | 206 | await updateTorrentMetadata(video, file) |
207 | |||
208 | await file.save() | ||
206 | } | 209 | } |
207 | } | 210 | } |
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts index b350c9718..ecc703646 100644 --- a/server/helpers/webtorrent.ts +++ b/server/helpers/webtorrent.ts | |||
@@ -14,7 +14,7 @@ import { MVideo } from '@server/types/models/video/video' | |||
14 | import { MVideoFile, MVideoFileRedundanciesOpt } from '@server/types/models/video/video-file' | 14 | import { MVideoFile, MVideoFileRedundanciesOpt } from '@server/types/models/video/video-file' |
15 | import { MStreamingPlaylistVideo } from '@server/types/models/video/video-streaming-playlist' | 15 | import { MStreamingPlaylistVideo } from '@server/types/models/video/video-streaming-playlist' |
16 | import { CONFIG } from '../initializers/config' | 16 | import { CONFIG } from '../initializers/config' |
17 | import { promisify2 } from './core-utils' | 17 | import { promisify2, sha1 } from './core-utils' |
18 | import { logger } from './logger' | 18 | import { logger } from './logger' |
19 | import { generateVideoImportTmpPath } from './utils' | 19 | import { generateVideoImportTmpPath } from './utils' |
20 | import { extractVideo } from './video' | 20 | import { extractVideo } from './video' |
@@ -145,6 +145,7 @@ async function updateTorrentMetadata (videoOrPlaylist: MVideo | MStreamingPlayli | |||
145 | await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)) | 145 | await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)) |
146 | 146 | ||
147 | videoFile.torrentFilename = newTorrentFilename | 147 | videoFile.torrentFilename = newTorrentFilename |
148 | videoFile.infoHash = sha1(encode(decoded.info)) | ||
148 | } | 149 | } |
149 | 150 | ||
150 | function generateMagnetUri ( | 151 | function generateMagnetUri ( |
diff --git a/server/middlewares/error.ts b/server/middlewares/error.ts index 6c52ce7bd..34c87a26d 100644 --- a/server/middlewares/error.ts +++ b/server/middlewares/error.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { ProblemDocument, ProblemDocumentExtension } from 'http-problem-details' | 2 | import { ProblemDocument, ProblemDocumentExtension } from 'http-problem-details' |
3 | import { logger } from '@server/helpers/logger' | ||
3 | import { HttpStatusCode } from '@shared/models' | 4 | import { HttpStatusCode } from '@shared/models' |
4 | 5 | ||
5 | function apiFailMiddleware (req: express.Request, res: express.Response, next: express.NextFunction) { | 6 | function apiFailMiddleware (req: express.Request, res: express.Response, next: express.NextFunction) { |
@@ -18,7 +19,8 @@ function apiFailMiddleware (req: express.Request, res: express.Response, next: e | |||
18 | 19 | ||
19 | res.status(status) | 20 | res.status(status) |
20 | res.setHeader('Content-Type', 'application/problem+json') | 21 | res.setHeader('Content-Type', 'application/problem+json') |
21 | res.json(new ProblemDocument({ | 22 | |
23 | const json = new ProblemDocument({ | ||
22 | status, | 24 | status, |
23 | title, | 25 | title, |
24 | instance, | 26 | instance, |
@@ -28,7 +30,11 @@ function apiFailMiddleware (req: express.Request, res: express.Response, next: e | |||
28 | type: type | 30 | type: type |
29 | ? `https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/${type}` | 31 | ? `https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/${type}` |
30 | : undefined | 32 | : undefined |
31 | }, extension)) | 33 | }, extension) |
34 | |||
35 | logger.debug('Bad HTTP request.', { json }) | ||
36 | |||
37 | res.json(json) | ||
32 | } | 38 | } |
33 | 39 | ||
34 | if (next) next() | 40 | if (next) next() |