Update torrents info name on video update
This commit is contained in:
parent
9b293cd6a2
commit
38d69d6501
4 changed files with 18 additions and 8 deletions
|
@ -131,7 +131,7 @@ export class MenuComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
getExternalLoginHref () {
|
getExternalLoginHref () {
|
||||||
if (this.serverConfig.client.menu.login.redirectOnSingleExternalAuth !== true) return undefined
|
if (!this.serverConfig || this.serverConfig.client.menu.login.redirectOnSingleExternalAuth !== true) return undefined
|
||||||
|
|
||||||
const externalAuths = this.serverConfig.plugin.registeredExternalAuths
|
const externalAuths = this.serverConfig.plugin.registeredExternalAuths
|
||||||
if (externalAuths.length !== 1) return undefined
|
if (externalAuths.length !== 1) return undefined
|
||||||
|
|
|
@ -69,7 +69,7 @@ async function updateVideo (req: express.Request, res: express.Response) {
|
||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const videoInstanceUpdated = await sequelizeTypescript.transaction(async t => {
|
const { videoInstanceUpdated, isNewVideo } = await sequelizeTypescript.transaction(async t => {
|
||||||
// Refresh video since thumbnails to prevent concurrent updates
|
// Refresh video since thumbnails to prevent concurrent updates
|
||||||
const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoFromReq.id, t)
|
const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoFromReq.id, t)
|
||||||
|
|
||||||
|
@ -138,8 +138,6 @@ async function updateVideo (req: express.Request, res: express.Response) {
|
||||||
transaction: t
|
transaction: t
|
||||||
})
|
})
|
||||||
|
|
||||||
await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
|
|
||||||
|
|
||||||
auditLogger.update(
|
auditLogger.update(
|
||||||
getAuditIdFromRes(res),
|
getAuditIdFromRes(res),
|
||||||
new VideoAuditView(videoInstanceUpdated.toFormattedDetailsJSON()),
|
new VideoAuditView(videoInstanceUpdated.toFormattedDetailsJSON()),
|
||||||
|
@ -147,10 +145,13 @@ async function updateVideo (req: express.Request, res: express.Response) {
|
||||||
)
|
)
|
||||||
logger.info('Video with name %s and uuid %s updated.', video.name, video.uuid, lTags(video.uuid))
|
logger.info('Video with name %s and uuid %s updated.', video.name, video.uuid, lTags(video.uuid))
|
||||||
|
|
||||||
return videoInstanceUpdated
|
return { videoInstanceUpdated, isNewVideo }
|
||||||
})
|
})
|
||||||
|
|
||||||
if (videoInfoToUpdate.name) await updateTorrentsMetadata(videoInstanceUpdated)
|
if (videoInfoToUpdate.name) await updateTorrentsMetadata(videoInstanceUpdated)
|
||||||
|
|
||||||
|
await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, undefined)
|
||||||
|
|
||||||
if (wasConfidentialVideo) Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated)
|
if (wasConfidentialVideo) Notifier.Instance.notifyOnNewVideoIfNeeded(videoInstanceUpdated)
|
||||||
|
|
||||||
Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated, body: req.body, req, res })
|
Hooks.runAction('action:api.video.updated', { video: videoInstanceUpdated, body: req.body, req, res })
|
||||||
|
@ -203,5 +204,7 @@ function updateSchedule (videoInstance: MVideoFullLight, videoInfoToUpdate: Vide
|
||||||
async function updateTorrentsMetadata (video: MVideoFullLight) {
|
async function updateTorrentsMetadata (video: MVideoFullLight) {
|
||||||
for (const file of video.getAllFiles()) {
|
for (const file of video.getAllFiles()) {
|
||||||
await updateTorrentMetadata(video, file)
|
await updateTorrentMetadata(video, file)
|
||||||
|
|
||||||
|
await file.save()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import { MVideo } from '@server/types/models/video/video'
|
||||||
import { MVideoFile, MVideoFileRedundanciesOpt } from '@server/types/models/video/video-file'
|
import { MVideoFile, MVideoFileRedundanciesOpt } from '@server/types/models/video/video-file'
|
||||||
import { MStreamingPlaylistVideo } from '@server/types/models/video/video-streaming-playlist'
|
import { MStreamingPlaylistVideo } from '@server/types/models/video/video-streaming-playlist'
|
||||||
import { CONFIG } from '../initializers/config'
|
import { CONFIG } from '../initializers/config'
|
||||||
import { promisify2 } from './core-utils'
|
import { promisify2, sha1 } from './core-utils'
|
||||||
import { logger } from './logger'
|
import { logger } from './logger'
|
||||||
import { generateVideoImportTmpPath } from './utils'
|
import { generateVideoImportTmpPath } from './utils'
|
||||||
import { extractVideo } from './video'
|
import { extractVideo } from './video'
|
||||||
|
@ -145,6 +145,7 @@ async function updateTorrentMetadata (videoOrPlaylist: MVideo | MStreamingPlayli
|
||||||
await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename))
|
await remove(join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename))
|
||||||
|
|
||||||
videoFile.torrentFilename = newTorrentFilename
|
videoFile.torrentFilename = newTorrentFilename
|
||||||
|
videoFile.infoHash = sha1(encode(decoded.info))
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateMagnetUri (
|
function generateMagnetUri (
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
import { ProblemDocument, ProblemDocumentExtension } from 'http-problem-details'
|
import { ProblemDocument, ProblemDocumentExtension } from 'http-problem-details'
|
||||||
|
import { logger } from '@server/helpers/logger'
|
||||||
import { HttpStatusCode } from '@shared/models'
|
import { HttpStatusCode } from '@shared/models'
|
||||||
|
|
||||||
function apiFailMiddleware (req: express.Request, res: express.Response, next: express.NextFunction) {
|
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
|
||||||
|
|
||||||
res.status(status)
|
res.status(status)
|
||||||
res.setHeader('Content-Type', 'application/problem+json')
|
res.setHeader('Content-Type', 'application/problem+json')
|
||||||
res.json(new ProblemDocument({
|
|
||||||
|
const json = new ProblemDocument({
|
||||||
status,
|
status,
|
||||||
title,
|
title,
|
||||||
instance,
|
instance,
|
||||||
|
@ -28,7 +30,11 @@ function apiFailMiddleware (req: express.Request, res: express.Response, next: e
|
||||||
type: type
|
type: type
|
||||||
? `https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/${type}`
|
? `https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/${type}`
|
||||||
: undefined
|
: undefined
|
||||||
}, extension))
|
}, extension)
|
||||||
|
|
||||||
|
logger.debug('Bad HTTP request.', { json })
|
||||||
|
|
||||||
|
res.json(json)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (next) next()
|
if (next) next()
|
||||||
|
|
Loading…
Add table
Reference in a new issue