mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
Server shares user videos
This commit is contained in:
parent
efc32059d9
commit
20494f1221
16 changed files with 215 additions and 111 deletions
|
@ -5,6 +5,8 @@ import { database as db } from '../../initializers'
|
|||
import { AccountInstance } from '../../models/account/account-interface'
|
||||
import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc'
|
||||
import Bluebird = require('bluebird')
|
||||
import { getOrCreateVideoChannel } from '../../helpers/activitypub'
|
||||
import { VideoChannelInstance } from '../../models/video/video-channel-interface'
|
||||
|
||||
async function processAddActivity (activity: ActivityAdd) {
|
||||
const activityObject = activity.object
|
||||
|
@ -12,7 +14,10 @@ async function processAddActivity (activity: ActivityAdd) {
|
|||
const account = await getOrCreateAccount(activity.actor)
|
||||
|
||||
if (activityType === 'Video') {
|
||||
return processAddVideo(account, activity.id, activityObject as VideoTorrentObject)
|
||||
const videoChannelUrl = activity.target
|
||||
const videoChannel = await getOrCreateVideoChannel(account, videoChannelUrl)
|
||||
|
||||
return processAddVideo(account, videoChannel, activityObject as VideoTorrentObject)
|
||||
}
|
||||
|
||||
logger.warn('Unknown activity object type %s when creating activity.', activityType, { activity: activity.id })
|
||||
|
@ -27,16 +32,16 @@ export {
|
|||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function processAddVideo (account: AccountInstance, videoChannelUrl: string, video: VideoTorrentObject) {
|
||||
function processAddVideo (account: AccountInstance, videoChannel: VideoChannelInstance, video: VideoTorrentObject) {
|
||||
const options = {
|
||||
arguments: [ account, videoChannelUrl, video ],
|
||||
arguments: [ account, videoChannel, video ],
|
||||
errorMessage: 'Cannot insert the remote video with many retries.'
|
||||
}
|
||||
|
||||
return retryTransactionWrapper(addRemoteVideo, options)
|
||||
}
|
||||
|
||||
async function addRemoteVideo (account: AccountInstance, videoChannelUrl: string, videoToCreateData: VideoTorrentObject) {
|
||||
function addRemoteVideo (account: AccountInstance, videoChannel: VideoChannelInstance, videoToCreateData: VideoTorrentObject) {
|
||||
logger.debug('Adding remote video %s.', videoToCreateData.url)
|
||||
|
||||
return db.sequelize.transaction(async t => {
|
||||
|
@ -44,9 +49,6 @@ async function addRemoteVideo (account: AccountInstance, videoChannelUrl: string
|
|||
transaction: t
|
||||
}
|
||||
|
||||
const videoChannel = await db.VideoChannel.loadByUrl(videoChannelUrl, t)
|
||||
if (!videoChannel) throw new Error('Video channel not found.')
|
||||
|
||||
if (videoChannel.Account.id !== account.id) throw new Error('Video channel is not owned by this account.')
|
||||
|
||||
const videoData = await videoActivityObjectToDBAttributes(videoChannel, videoToCreateData, t)
|
||||
|
@ -59,8 +61,11 @@ async function addRemoteVideo (account: AccountInstance, videoChannelUrl: string
|
|||
const videoCreated = await video.save(sequelizeOptions)
|
||||
|
||||
const videoFileAttributes = await videoFileActivityUrlToDBAttributes(videoCreated, videoToCreateData)
|
||||
if (videoFileAttributes.length === 0) {
|
||||
throw new Error('Cannot find valid files for video %s ' + videoToCreateData.url)
|
||||
}
|
||||
|
||||
const tasks: Bluebird<any>[] = videoFileAttributes.map(f => db.VideoFile.create(f))
|
||||
const tasks: Bluebird<any>[] = videoFileAttributes.map(f => db.VideoFile.create(f, { transaction: t }))
|
||||
await Promise.all(tasks)
|
||||
|
||||
const tags = videoToCreateData.tag.map(t => t.name)
|
||||
|
@ -71,5 +76,4 @@ async function addRemoteVideo (account: AccountInstance, videoChannelUrl: string
|
|||
|
||||
return videoCreated
|
||||
})
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue