Send server announce when users upload a video
This commit is contained in:
parent
d846501818
commit
efc32059d9
22 changed files with 161 additions and 80 deletions
|
@ -1,15 +1,19 @@
|
|||
import { join } from 'path'
|
||||
import * as request from 'request'
|
||||
import * as Sequelize from 'sequelize'
|
||||
import * as url from 'url'
|
||||
import { ActivityIconObject } from '../../shared/index'
|
||||
import { ActivityPubActor } from '../../shared/models/activitypub/activitypub-actor'
|
||||
import { ResultList } from '../../shared/models/result-list.model'
|
||||
import { database as db, REMOTE_SCHEME } from '../initializers'
|
||||
import { ACTIVITY_PUB_ACCEPT_HEADER, CONFIG, STATIC_PATHS } from '../initializers/constants'
|
||||
import { sendAnnounce } from '../lib/activitypub/send-request'
|
||||
import { VideoChannelInstance } from '../models/video/video-channel-interface'
|
||||
import { VideoInstance } from '../models/video/video-interface'
|
||||
import { isRemoteAccountValid } from './custom-validators'
|
||||
import { logger } from './logger'
|
||||
import { doRequest, doRequestAndSaveToFile } from './requests'
|
||||
import { getServerAccount } from './utils'
|
||||
|
||||
function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObject) {
|
||||
const thumbnailName = video.getThumbnailName()
|
||||
|
@ -22,6 +26,28 @@ function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObjec
|
|||
return doRequestAndSaveToFile(options, thumbnailPath)
|
||||
}
|
||||
|
||||
async function shareVideoChannelByServer (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
|
||||
const serverAccount = await getServerAccount()
|
||||
|
||||
await db.VideoChannelShare.create({
|
||||
accountId: serverAccount.id,
|
||||
videoChannelId: videoChannel.id
|
||||
}, { transaction: t })
|
||||
|
||||
return sendAnnounce(serverAccount, videoChannel, t)
|
||||
}
|
||||
|
||||
async function shareVideoByServer (video: VideoInstance, t: Sequelize.Transaction) {
|
||||
const serverAccount = await getServerAccount()
|
||||
|
||||
await db.VideoShare.create({
|
||||
accountId: serverAccount.id,
|
||||
videoId: video.id
|
||||
}, { transaction: t })
|
||||
|
||||
return sendAnnounce(serverAccount, video, t)
|
||||
}
|
||||
|
||||
function getActivityPubUrl (type: 'video' | 'videoChannel' | 'account' | 'videoAbuse', id: string) {
|
||||
if (type === 'video') return CONFIG.WEBSERVER.URL + '/videos/watch/' + id
|
||||
else if (type === 'videoChannel') return CONFIG.WEBSERVER.URL + '/video-channels/' + id
|
||||
|
@ -172,7 +198,9 @@ export {
|
|||
generateThumbnailFromUrl,
|
||||
getOrCreateAccount,
|
||||
fetchRemoteVideoPreview,
|
||||
fetchRemoteVideoDescription
|
||||
fetchRemoteVideoDescription,
|
||||
shareVideoChannelByServer,
|
||||
shareVideoByServer
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue