mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Cleanup model types
This commit is contained in:
@@ -24,15 +24,17 @@ import { ActorFetchByUrlType, fetchActorByUrl } from '../../helpers/actor'
|
||||
import { sequelizeTypescript } from '../../initializers/database'
|
||||
import {
|
||||
MAccount,
|
||||
MAccountDefault,
|
||||
MActor,
|
||||
MActorAccountChannelId,
|
||||
MActorAccountChannelIdActor,
|
||||
MActorAccountId,
|
||||
MActorDefault,
|
||||
MActorFull,
|
||||
MActorFullActor,
|
||||
MActorId,
|
||||
MActorAccountChannelIdActor,
|
||||
MChannel,
|
||||
MActorFullActor, MAccountActorDefault, MChannelActorDefault, MChannelActorAccountDefault
|
||||
MChannelAccountDefault
|
||||
} from '../../typings/models'
|
||||
|
||||
// Set account keys, this could be long so process after the account creation and do not block the client
|
||||
@@ -374,12 +376,11 @@ function saveActorAndServerAndModelIfNotExist (
|
||||
})
|
||||
|
||||
if (actorCreated.type === 'Person' || actorCreated.type === 'Application') {
|
||||
actorCreated.Account = await saveAccount(actorCreated, result, t) as MAccountActorDefault
|
||||
actorCreated.Account = await saveAccount(actorCreated, result, t) as MAccountDefault
|
||||
actorCreated.Account.Actor = actorCreated
|
||||
} else if (actorCreated.type === 'Group') { // Video channel
|
||||
actorCreated.VideoChannel = await saveVideoChannel(actorCreated, result, ownerActor, t) as MChannelActorAccountDefault
|
||||
actorCreated.VideoChannel.Actor = actorCreated
|
||||
actorCreated.VideoChannel.Account = ownerActor.Account
|
||||
const channel = await saveVideoChannel(actorCreated, result, ownerActor, t)
|
||||
actorCreated.VideoChannel = Object.assign(channel, { Actor: actorCreated, Account: ownerActor.Account })
|
||||
}
|
||||
|
||||
actorCreated.Server = server
|
||||
|
||||
@@ -7,7 +7,7 @@ import { getOrCreateVideoAndAccountAndChannel } from '../videos'
|
||||
import { Notifier } from '../../notifier'
|
||||
import { logger } from '../../../helpers/logger'
|
||||
import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
|
||||
import { MActorSignature, MVideoAccountAllFiles } from '../../../typings/models'
|
||||
import { MActorSignature, MVideoAccountLightBlacklistAllFiles } from '../../../typings/models'
|
||||
|
||||
async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) {
|
||||
const { activity, byActor: actorAnnouncer } = options
|
||||
@@ -28,7 +28,7 @@ export {
|
||||
async function processVideoShare (actorAnnouncer: MActorSignature, activity: ActivityAnnounce, notify: boolean) {
|
||||
const objectUri = typeof activity.object === 'string' ? activity.object : activity.object.id
|
||||
|
||||
let video: MVideoAccountAllFiles
|
||||
let video: MVideoAccountLightBlacklistAllFiles
|
||||
let videoCreated: boolean
|
||||
|
||||
try {
|
||||
|
||||
@@ -11,7 +11,7 @@ import { Notifier } from '../../notifier'
|
||||
import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object'
|
||||
import { createOrUpdateVideoPlaylist } from '../playlist'
|
||||
import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
|
||||
import { MActorSignature, MCommentOwnerVideo, MVideoAccountAllFiles } from '../../../typings/models'
|
||||
import { MActorSignature, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFiles } from '../../../typings/models'
|
||||
|
||||
async function processCreateActivity (options: APProcessorOptions<ActivityCreate>) {
|
||||
const { activity, byActor } = options
|
||||
@@ -81,7 +81,7 @@ async function processCreateVideoComment (activity: ActivityCreate, byActor: MAc
|
||||
|
||||
if (!byAccount) throw new Error('Cannot create video comment with the non account actor ' + byActor.url)
|
||||
|
||||
let video: MVideoAccountAllFiles
|
||||
let video: MVideoAccountLightBlacklistAllFiles
|
||||
let created: boolean
|
||||
let comment: MCommentOwnerVideo
|
||||
try {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { getOrCreateActorAndServerAndModel } from './actor'
|
||||
import { getOrCreateVideoAndAccountAndChannel } from './videos'
|
||||
import * as Bluebird from 'bluebird'
|
||||
import { checkUrlsSameHost } from '../../helpers/activitypub'
|
||||
import { MCommentOwner, MCommentOwnerVideo, MVideoAccountAllFiles } from '../../typings/models/video'
|
||||
import { MCommentOwner, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFiles } from '../../typings/models/video'
|
||||
|
||||
type ResolveThreadParams = {
|
||||
url: string,
|
||||
@@ -15,7 +15,7 @@ type ResolveThreadParams = {
|
||||
isVideo?: boolean,
|
||||
commentCreated?: boolean
|
||||
}
|
||||
type ResolveThreadResult = Promise<{ video: MVideoAccountAllFiles, comment: MCommentOwnerVideo, commentCreated: boolean }>
|
||||
type ResolveThreadResult = Promise<{ video: MVideoAccountLightBlacklistAllFiles, comment: MCommentOwnerVideo, commentCreated: boolean }>
|
||||
|
||||
async function addVideoComments (commentUrls: string[]) {
|
||||
return Bluebird.map(commentUrls, commentUrl => {
|
||||
|
||||
@@ -58,7 +58,7 @@ import {
|
||||
MChannelDefault,
|
||||
MChannelId,
|
||||
MVideo,
|
||||
MVideoAccountAllFiles,
|
||||
MVideoAccountLightBlacklistAllFiles,
|
||||
MVideoAccountLight,
|
||||
MVideoAP,
|
||||
MVideoAPWithoutCaption,
|
||||
@@ -213,19 +213,19 @@ function getOrCreateVideoAndAccountAndChannel (options: {
|
||||
syncParam?: SyncParam,
|
||||
fetchType?: 'all',
|
||||
allowRefresh?: boolean
|
||||
}): Promise<{ video: MVideoAccountAllFiles, created: boolean, autoBlacklisted?: boolean }>
|
||||
}): Promise<{ video: MVideoAccountLightBlacklistAllFiles, created: boolean, autoBlacklisted?: boolean }>
|
||||
function getOrCreateVideoAndAccountAndChannel (options: {
|
||||
videoObject: { id: string } | string,
|
||||
syncParam?: SyncParam,
|
||||
fetchType?: VideoFetchByUrlType,
|
||||
allowRefresh?: boolean
|
||||
}): Promise<{ video: MVideoAccountAllFiles | MVideoThumbnail, created: boolean, autoBlacklisted?: boolean }>
|
||||
}): Promise<{ video: MVideoAccountLightBlacklistAllFiles | MVideoThumbnail, created: boolean, autoBlacklisted?: boolean }>
|
||||
async function getOrCreateVideoAndAccountAndChannel (options: {
|
||||
videoObject: { id: string } | string,
|
||||
syncParam?: SyncParam,
|
||||
fetchType?: VideoFetchByUrlType,
|
||||
allowRefresh?: boolean // true by default
|
||||
}): Promise<{ video: MVideoAccountAllFiles | MVideoThumbnail, created: boolean, autoBlacklisted?: boolean }> {
|
||||
}): Promise<{ video: MVideoAccountLightBlacklistAllFiles | MVideoThumbnail, created: boolean, autoBlacklisted?: boolean }> {
|
||||
// Default params
|
||||
const syncParam = options.syncParam || { likes: true, dislikes: true, shares: true, comments: true, thumbnail: true, refreshVideo: false }
|
||||
const fetchType = options.fetchType || 'all'
|
||||
@@ -263,7 +263,7 @@ async function getOrCreateVideoAndAccountAndChannel (options: {
|
||||
}
|
||||
|
||||
async function updateVideoFromAP (options: {
|
||||
video: MVideoAccountAllFiles,
|
||||
video: MVideoAccountLightBlacklistAllFiles,
|
||||
videoObject: VideoTorrentObject,
|
||||
account: MAccountActor,
|
||||
channel: MChannelDefault,
|
||||
@@ -420,7 +420,7 @@ async function refreshVideoIfNeeded (options: {
|
||||
|
||||
// We need more attributes if the argument video was fetched with not enough joints
|
||||
const video = options.fetchedType === 'all'
|
||||
? options.video as MVideoAccountAllFiles
|
||||
? options.video as MVideoAccountLightBlacklistAllFiles
|
||||
: await VideoModel.loadByUrlAndPopulateAccount(options.video.url)
|
||||
|
||||
try {
|
||||
|
||||
@@ -11,11 +11,11 @@ import { sequelizeTypescript } from '../initializers/database'
|
||||
import * as LRUCache from 'lru-cache'
|
||||
import { queue } from 'async'
|
||||
import { downloadImage } from '../helpers/requests'
|
||||
import { MAccountActorDefault, MChannelActorDefault } from '../typings/models'
|
||||
import { MAccountDefault, MChannelDefault } from '../typings/models'
|
||||
|
||||
async function updateActorAvatarFile (
|
||||
avatarPhysicalFile: Express.Multer.File,
|
||||
accountOrChannel: MAccountActorDefault | MChannelActorDefault
|
||||
accountOrChannel: MAccountDefault | MChannelDefault
|
||||
) {
|
||||
const extension = extname(avatarPhysicalFile.filename)
|
||||
const avatarName = uuidv4() + extension
|
||||
|
||||
@@ -2,14 +2,12 @@ import { createTransport, Transporter } from 'nodemailer'
|
||||
import { isTestInstance } from '../helpers/core-utils'
|
||||
import { bunyanLogger, logger } from '../helpers/logger'
|
||||
import { CONFIG } from '../initializers/config'
|
||||
import { UserModel } from '../models/account/user'
|
||||
import { JobQueue } from './job-queue'
|
||||
import { EmailPayload } from './job-queue/handlers/email'
|
||||
import { readFileSync } from 'fs-extra'
|
||||
import { VideoBlacklistModel } from '../models/video/video-blacklist'
|
||||
import { WEBSERVER } from '../initializers/constants'
|
||||
import { MCommentOwnerVideo, MVideo, MVideoAbuseVideo, MVideoAccountLight, MVideoBlacklistVideo } from '../typings/models/video'
|
||||
import { MActorFollowActors, MActorFollowFull, MUser } from '../typings/models'
|
||||
import { MActorFollowActors, MActorFollowFollowingFullFollowerAccount, MUser } from '../typings/models'
|
||||
import { MVideoImport, MVideoImportVideo } from '@server/typings/models/video/video-import'
|
||||
|
||||
type SendEmailOptions = {
|
||||
@@ -109,7 +107,7 @@ class Emailer {
|
||||
return JobQueue.Instance.createJob({ type: 'email', payload: emailPayload })
|
||||
}
|
||||
|
||||
addNewFollowNotification (to: string[], actorFollow: MActorFollowFull, followType: 'account' | 'channel') {
|
||||
addNewFollowNotification (to: string[], actorFollow: MActorFollowFollowingFullFollowerAccount, followType: 'account' | 'channel') {
|
||||
const followerName = actorFollow.ActorFollower.Account.getDisplayName()
|
||||
const followingName = (actorFollow.ActorFollowing.VideoChannel || actorFollow.ActorFollowing.Account).getDisplayName()
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
|
||||
import { ActorModel } from '../../../models/activitypub/actor'
|
||||
import { Notifier } from '../../notifier'
|
||||
import { sequelizeTypescript } from '../../../initializers/database'
|
||||
import { MActorFollowFull, MActorFull } from '../../../typings/models'
|
||||
import { MAccount, MActor, MActorFollowActors, MActorFollowFull, MActorFull } from '../../../typings/models'
|
||||
|
||||
export type ActivitypubFollowPayload = {
|
||||
followerActorId: number
|
||||
@@ -45,7 +45,7 @@ export {
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function follow (fromActor: MActorFull, targetActor: MActorFull) {
|
||||
async function follow (fromActor: MActor, targetActor: MActorFull) {
|
||||
if (fromActor.id === targetActor.id) {
|
||||
throw new Error('Follower is the same than target actor.')
|
||||
}
|
||||
@@ -54,7 +54,7 @@ async function follow (fromActor: MActorFull, targetActor: MActorFull) {
|
||||
const state = !fromActor.serverId && !targetActor.serverId ? 'accepted' : 'pending'
|
||||
|
||||
const actorFollow = await sequelizeTypescript.transaction(async t => {
|
||||
const [ actorFollow ] = await ActorFollowModel.findOrCreate<MActorFollowFull>({
|
||||
const [ actorFollow ] = await ActorFollowModel.findOrCreate<MActorFollowActors>({
|
||||
where: {
|
||||
actorId: fromActor.id,
|
||||
targetActorId: targetActor.id
|
||||
@@ -75,5 +75,14 @@ async function follow (fromActor: MActorFull, targetActor: MActorFull) {
|
||||
return actorFollow
|
||||
})
|
||||
|
||||
if (actorFollow.state === 'accepted') Notifier.Instance.notifyOfNewUserFollow(actorFollow)
|
||||
if (actorFollow.state === 'accepted') {
|
||||
const followerFull = Object.assign(fromActor, { Account: await actorFollow.ActorFollower.$get('Account') as MAccount })
|
||||
|
||||
const actorFollowFull = Object.assign(actorFollow, {
|
||||
ActorFollowing: targetActor,
|
||||
ActorFollower: followerFull
|
||||
})
|
||||
|
||||
Notifier.Instance.notifyOfNewUserFollow(actorFollowFull)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,13 +111,11 @@ type ProcessFileOptions = {
|
||||
generateThumbnail: boolean
|
||||
generatePreview: boolean
|
||||
}
|
||||
async function processFile (downloader: () => Promise<string>, videoImportArg: MVideoImportDefault, options: ProcessFileOptions) {
|
||||
async function processFile (downloader: () => Promise<string>, videoImport: MVideoImportDefault, options: ProcessFileOptions) {
|
||||
let tempVideoPath: string
|
||||
let videoDestFile: string
|
||||
let videoFile: VideoFileModel
|
||||
|
||||
const videoImport = videoImportArg as MVideoImportDefaultFiles
|
||||
|
||||
try {
|
||||
// Download video from youtubeDL
|
||||
tempVideoPath = await downloader()
|
||||
@@ -142,35 +140,37 @@ async function processFile (downloader: () => Promise<string>, videoImportArg: M
|
||||
videoId: videoImport.videoId
|
||||
}
|
||||
videoFile = new VideoFileModel(videoFileData)
|
||||
|
||||
const videoWithFiles = Object.assign(videoImport.Video, { VideoFiles: [ videoFile ] })
|
||||
// To clean files if the import fails
|
||||
videoImport.Video.VideoFiles = [ videoFile ]
|
||||
const videoImportWithFiles: MVideoImportDefaultFiles = Object.assign(videoImport, { Video: videoWithFiles })
|
||||
|
||||
// Move file
|
||||
videoDestFile = join(CONFIG.STORAGE.VIDEOS_DIR, videoImport.Video.getVideoFilename(videoFile))
|
||||
videoDestFile = join(CONFIG.STORAGE.VIDEOS_DIR, videoImportWithFiles.Video.getVideoFilename(videoFile))
|
||||
await move(tempVideoPath, videoDestFile)
|
||||
tempVideoPath = null // This path is not used anymore
|
||||
|
||||
// Process thumbnail
|
||||
let thumbnailModel: MThumbnail
|
||||
if (options.downloadThumbnail && options.thumbnailUrl) {
|
||||
thumbnailModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImport.Video, ThumbnailType.MINIATURE)
|
||||
thumbnailModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImportWithFiles.Video, ThumbnailType.MINIATURE)
|
||||
} else if (options.generateThumbnail || options.downloadThumbnail) {
|
||||
thumbnailModel = await generateVideoMiniature(videoImport.Video, videoFile, ThumbnailType.MINIATURE)
|
||||
thumbnailModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.MINIATURE)
|
||||
}
|
||||
|
||||
// Process preview
|
||||
let previewModel: MThumbnail
|
||||
if (options.downloadPreview && options.thumbnailUrl) {
|
||||
previewModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImport.Video, ThumbnailType.PREVIEW)
|
||||
previewModel = await createVideoMiniatureFromUrl(options.thumbnailUrl, videoImportWithFiles.Video, ThumbnailType.PREVIEW)
|
||||
} else if (options.generatePreview || options.downloadPreview) {
|
||||
previewModel = await generateVideoMiniature(videoImport.Video, videoFile, ThumbnailType.PREVIEW)
|
||||
previewModel = await generateVideoMiniature(videoImportWithFiles.Video, videoFile, ThumbnailType.PREVIEW)
|
||||
}
|
||||
|
||||
// Create torrent
|
||||
await videoImport.Video.createTorrentAndSetInfoHash(videoFile)
|
||||
await videoImportWithFiles.Video.createTorrentAndSetInfoHash(videoFile)
|
||||
|
||||
const { videoImportUpdated, video } = await sequelizeTypescript.transaction(async t => {
|
||||
const videoImportToUpdate = videoImport as MVideoImportVideo
|
||||
const videoImportToUpdate = videoImportWithFiles as MVideoImportVideo
|
||||
|
||||
// Refresh video
|
||||
const video = await VideoModel.load(videoImportToUpdate.videoId, t)
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
MVideoFullLight
|
||||
} from '../typings/models/video'
|
||||
import { MUser, MUserAccount, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/typings/models/user'
|
||||
import { MActorFollowActors, MActorFollowFull } from '../typings/models'
|
||||
import { MActorFollowActors, MActorFollowFull, MActorFollowFollowingFullFollowerAccount } from '../typings/models'
|
||||
import { ActorFollowModel } from '../models/activitypub/actor-follow'
|
||||
import { MVideoImportVideo } from '@server/typings/models/video/video-import'
|
||||
import { AccountModel } from '@server/models/account/account'
|
||||
@@ -102,7 +102,7 @@ class Notifier {
|
||||
.catch(err => logger.error('Cannot notify moderators of new user registration (%s).', user.username, { err }))
|
||||
}
|
||||
|
||||
notifyOfNewUserFollow (actorFollow: MActorFollowFull): void {
|
||||
notifyOfNewUserFollow (actorFollow: MActorFollowFollowingFullFollowerAccount): void {
|
||||
this.notifyUserOfNewActorFollow(actorFollow)
|
||||
.catch(err => {
|
||||
logger.error(
|
||||
@@ -231,7 +231,7 @@ class Notifier {
|
||||
return this.notify({ users, settingGetter, notificationCreator, emailSender })
|
||||
}
|
||||
|
||||
private async notifyUserOfNewActorFollow (actorFollow: MActorFollowFull) {
|
||||
private async notifyUserOfNewActorFollow (actorFollow: MActorFollowFollowingFullFollowerAccount) {
|
||||
if (actorFollow.ActorFollowing.isOwned() === false) return
|
||||
|
||||
// Account follows one of our account?
|
||||
|
||||
@@ -32,7 +32,9 @@ type CandidateToDuplicate = {
|
||||
streamingPlaylists: MStreamingPlaylist[]
|
||||
}
|
||||
|
||||
function isMVideoRedundancyFileVideo (o: MVideoRedundancyVideo): o is MVideoRedundancyFileVideo {
|
||||
function isMVideoRedundancyFileVideo (
|
||||
o: MVideoRedundancyFileVideo | MVideoRedundancyStreamingPlaylistVideo
|
||||
): o is MVideoRedundancyFileVideo {
|
||||
return !!(o as MVideoRedundancyFileVideo).VideoFile
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user