mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
Federate video views
This commit is contained in:
parent
c46edbc2f6
commit
40ff57078e
19 changed files with 188 additions and 44 deletions
|
@ -148,10 +148,17 @@ async function removeFollow (req: express.Request, res: express.Response, next:
|
|||
const follow: AccountFollowInstance = res.locals.follow
|
||||
|
||||
await db.sequelize.transaction(async t => {
|
||||
await sendUndoFollow(follow, t)
|
||||
if (follow.state === 'accepted') await sendUndoFollow(follow, t)
|
||||
|
||||
await follow.destroy({ transaction: t })
|
||||
})
|
||||
|
||||
// Destroy the account that will destroy video channels, videos and video files too
|
||||
// This could be long so don't wait this task
|
||||
const following = follow.AccountFollowing
|
||||
following.destroy()
|
||||
.catch(err => logger.error('Cannot destroy account that we do not follow anymore %s.', following.url, err))
|
||||
|
||||
return res.status(204).end()
|
||||
}
|
||||
|
||||
|
|
|
@ -11,10 +11,15 @@ import {
|
|||
resetSequelizeInstance,
|
||||
retryTransactionWrapper
|
||||
} from '../../../helpers'
|
||||
import { getServerAccount } from '../../../helpers/utils'
|
||||
import { CONFIG, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_MIMETYPE_EXT, VIDEO_PRIVACIES } from '../../../initializers'
|
||||
import { database as db } from '../../../initializers/database'
|
||||
import { sendAddVideo } from '../../../lib/activitypub/send/send-add'
|
||||
import { sendUpdateVideo } from '../../../lib/activitypub/send/send-update'
|
||||
import { shareVideoByServer } from '../../../lib/activitypub/share'
|
||||
import { getVideoActivityPubUrl } from '../../../lib/activitypub/url'
|
||||
import { fetchRemoteVideoDescription } from '../../../lib/activitypub/videos'
|
||||
import { sendCreateViewToVideoFollowers } from '../../../lib/index'
|
||||
import { transcodingJobScheduler } from '../../../lib/jobs/transcoding-job-scheduler/transcoding-job-scheduler'
|
||||
import {
|
||||
asyncMiddleware,
|
||||
|
@ -35,9 +40,7 @@ import { abuseVideoRouter } from './abuse'
|
|||
import { blacklistRouter } from './blacklist'
|
||||
import { videoChannelRouter } from './channel'
|
||||
import { rateVideoRouter } from './rate'
|
||||
import { getVideoActivityPubUrl } from '../../../lib/activitypub/url'
|
||||
import { shareVideoByServer } from '../../../lib/activitypub/share'
|
||||
import { fetchRemoteVideoDescription } from '../../../lib/activitypub/videos'
|
||||
import { sendCreateViewToOrigin } from '../../../lib/activitypub/send/send-create'
|
||||
|
||||
const videosRouter = express.Router()
|
||||
|
||||
|
@ -311,17 +314,18 @@ async function updateVideo (req: express.Request, res: express.Response) {
|
|||
async function getVideo (req: express.Request, res: express.Response) {
|
||||
const videoInstance = res.locals.video
|
||||
|
||||
const baseIncrementPromise = videoInstance.increment('views')
|
||||
.then(() => getServerAccount())
|
||||
|
||||
if (videoInstance.isOwned()) {
|
||||
// The increment is done directly in the database, not using the instance value
|
||||
// FIXME: make a real view system
|
||||
// For example, only add a view when a user watch a video during 30s etc
|
||||
videoInstance.increment('views')
|
||||
.then(() => {
|
||||
// TODO: send to followers a notification
|
||||
})
|
||||
.catch(err => logger.error('Cannot add view to video %s.', videoInstance.uuid, err))
|
||||
baseIncrementPromise
|
||||
.then(serverAccount => sendCreateViewToVideoFollowers(serverAccount, videoInstance, undefined))
|
||||
.catch(err => logger.error('Cannot add view to video/send view to followers for %s.', videoInstance.uuid, err))
|
||||
} else {
|
||||
// TODO: send view event to followers
|
||||
baseIncrementPromise
|
||||
.then(serverAccount => sendCreateViewToOrigin(serverAccount, videoInstance, undefined))
|
||||
.catch(err => logger.error('Cannot send view to origin server for %s.', videoInstance.uuid, err))
|
||||
}
|
||||
|
||||
// Do not wait the view system
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue