1
0
Fork 0

Type toFormattedJSON

This commit is contained in:
Chocobozzz 2019-08-20 19:05:31 +02:00
parent 0283eaac2a
commit 1ca9f7c3f7
No known key found for this signature in database
GPG key ID: 583A612D890159BE
54 changed files with 401 additions and 147 deletions

View file

@ -196,7 +196,7 @@ async function createUser (req: express.Request, res: express.Response) {
videoQuota: body.videoQuota, videoQuota: body.videoQuota,
videoQuotaDaily: body.videoQuotaDaily, videoQuotaDaily: body.videoQuotaDaily,
adminFlags: body.adminFlags || UserAdminFlag.NONE adminFlags: body.adminFlags || UserAdminFlag.NONE
}) }) as MUser
const { user, account } = await createUserAccountAndChannelAndPlaylist({ userToCreate: userToCreate }) const { user, account } = await createUserAccountAndChannelAndPlaylist({ userToCreate: userToCreate })

View file

@ -23,15 +23,12 @@ import { createReqFiles } from '../../../helpers/express-utils'
import { UserVideoQuota } from '../../../../shared/models/users/user-video-quota.model' import { UserVideoQuota } from '../../../../shared/models/users/user-video-quota.model'
import { updateAvatarValidator } from '../../../middlewares/validators/avatar' import { updateAvatarValidator } from '../../../middlewares/validators/avatar'
import { updateActorAvatarFile } from '../../../lib/avatar' import { updateActorAvatarFile } from '../../../lib/avatar'
import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger'
import { VideoImportModel } from '../../../models/video/video-import' import { VideoImportModel } from '../../../models/video/video-import'
import { AccountModel } from '../../../models/account/account' import { AccountModel } from '../../../models/account/account'
import { CONFIG } from '../../../initializers/config' import { CONFIG } from '../../../initializers/config'
import { sequelizeTypescript } from '../../../initializers/database' import { sequelizeTypescript } from '../../../initializers/database'
import { sendVerifyUserEmail } from '../../../lib/user' import { sendVerifyUserEmail } from '../../../lib/user'
const auditLogger = auditLoggerFactory('users-me')
const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR }) const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR })
const meRouter = express.Router() const meRouter = express.Router()
@ -165,8 +162,6 @@ async function deleteMe (req: express.Request, res: express.Response) {
await user.destroy() await user.destroy()
auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})))
return res.sendStatus(204) return res.sendStatus(204)
} }
@ -175,7 +170,6 @@ async function updateMe (req: express.Request, res: express.Response) {
let sendVerificationEmail = false let sendVerificationEmail = false
const user = res.locals.oauth.token.user const user = res.locals.oauth.token.user
const oldUserAuditView = new UserAuditView(user.toFormattedJSON({}))
if (body.password !== undefined) user.password = body.password if (body.password !== undefined) user.password = body.password
if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy
@ -204,8 +198,6 @@ async function updateMe (req: express.Request, res: express.Response) {
await userAccount.save({ transaction: t }) await userAccount.save({ transaction: t })
await sendUpdateActor(userAccount, t) await sendUpdateActor(userAccount, t)
auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView)
}) })
if (sendVerificationEmail === true) { if (sendVerificationEmail === true) {
@ -218,13 +210,10 @@ async function updateMe (req: express.Request, res: express.Response) {
async function updateMyAvatar (req: express.Request, res: express.Response) { async function updateMyAvatar (req: express.Request, res: express.Response) {
const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ] const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ]
const user = res.locals.oauth.token.user const user = res.locals.oauth.token.user
const oldUserAuditView = new UserAuditView(user.toFormattedJSON({}))
const userAccount = await AccountModel.load(user.Account.id) const userAccount = await AccountModel.load(user.Account.id)
const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount) const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount)
auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView)
return res.json({ avatar: avatar.toFormattedJSON() }) return res.json({ avatar: avatar.toFormattedJSON() })
} }

View file

@ -19,7 +19,7 @@ import { VideoChannelModel } from '../../models/video/video-channel'
import { videoChannelsNameWithHostValidator, videosSortValidator } from '../../middlewares/validators' import { videoChannelsNameWithHostValidator, videosSortValidator } from '../../middlewares/validators'
import { sendUpdateActor } from '../../lib/activitypub/send' import { sendUpdateActor } from '../../lib/activitypub/send'
import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared' import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared'
import { createVideoChannel, federateAllVideosOfChannel } from '../../lib/video-channel' import { createLocalVideoChannel, federateAllVideosOfChannel } from '../../lib/video-channel'
import { buildNSFWFilter, createReqFiles, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' import { buildNSFWFilter, createReqFiles, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
import { setAsyncActorKeys } from '../../lib/activitypub' import { setAsyncActorKeys } from '../../lib/activitypub'
import { AccountModel } from '../../models/account/account' import { AccountModel } from '../../models/account/account'
@ -139,7 +139,7 @@ async function addVideoChannel (req: express.Request, res: express.Response) {
const videoChannelCreated = await sequelizeTypescript.transaction(async t => { const videoChannelCreated = await sequelizeTypescript.transaction(async t => {
const account = await AccountModel.load(res.locals.oauth.token.User.Account.id, t) const account = await AccountModel.load(res.locals.oauth.token.User.Account.id, t)
return createVideoChannel(videoChannelInfo, account, t) return createLocalVideoChannel(videoChannelInfo, account, t)
}) })
setAsyncActorKeys(videoChannelCreated.Actor) setAsyncActorKeys(videoChannelCreated.Actor)

View file

@ -1,6 +1,5 @@
import * as express from 'express' import * as express from 'express'
import * as magnetUtil from 'magnet-uri' import * as magnetUtil from 'magnet-uri'
import 'multer'
import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger'
import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares' import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares'
import { MIMETYPES } from '../../../initializers/constants' import { MIMETYPES } from '../../../initializers/constants'
@ -28,11 +27,12 @@ import {
MChannelAccountDefault, MChannelAccountDefault,
MThumbnail, MThumbnail,
MUser, MUser,
MVideoAccountDefault,
MVideoTag, MVideoTag,
MVideoThumbnailAccountDefault, MVideoThumbnailAccountDefault,
MVideoWithBlacklistLight MVideoWithBlacklistLight
} from '@server/typings/models' } from '@server/typings/models'
import { MVideoImport, MVideoImportVideo } from '@server/typings/models/video/video-import' import { MVideoImport, MVideoImportFormattable } from '@server/typings/models/video/video-import'
const auditLogger = auditLoggerFactory('video-imports') const auditLogger = auditLoggerFactory('video-imports')
const videoImportsRouter = express.Router() const videoImportsRouter = express.Router()
@ -238,14 +238,14 @@ function insertIntoDB (parameters: {
tags: string[], tags: string[],
videoImportAttributes: Partial<MVideoImport>, videoImportAttributes: Partial<MVideoImport>,
user: MUser user: MUser
}): Bluebird<MVideoImportVideo> { }): Bluebird<MVideoImportFormattable> {
const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters
return sequelizeTypescript.transaction(async t => { return sequelizeTypescript.transaction(async t => {
const sequelizeOptions = { transaction: t } const sequelizeOptions = { transaction: t }
// Save video object in database // Save video object in database
const videoCreated = await video.save(sequelizeOptions) as (MVideoThumbnailAccountDefault & MVideoWithBlacklistLight & MVideoTag) const videoCreated = await video.save(sequelizeOptions) as (MVideoAccountDefault & MVideoWithBlacklistLight & MVideoTag)
videoCreated.VideoChannel = videoChannel videoCreated.VideoChannel = videoChannel
if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
@ -274,7 +274,7 @@ function insertIntoDB (parameters: {
const videoImport = await VideoImportModel.create( const videoImport = await VideoImportModel.create(
Object.assign({ videoId: videoCreated.id }, videoImportAttributes), Object.assign({ videoId: videoCreated.id }, videoImportAttributes),
sequelizeOptions sequelizeOptions
) as MVideoImportVideo ) as MVideoImportFormattable
videoImport.Video = videoCreated videoImport.Video = videoCreated
return videoImport return videoImport

View file

@ -2,9 +2,9 @@ import { join } from 'path'
import { CONFIG } from '../initializers/config' import { CONFIG } from '../initializers/config'
import * as srt2vtt from 'srt-to-vtt' import * as srt2vtt from 'srt-to-vtt'
import { createReadStream, createWriteStream, move, remove } from 'fs-extra' import { createReadStream, createWriteStream, move, remove } from 'fs-extra'
import { MVideoCaption } from '@server/typings/models' import { MVideoCaptionFormattable } from '@server/typings/models'
async function moveAndProcessCaptionFile (physicalFile: { filename: string, path: string }, videoCaption: MVideoCaption) { async function moveAndProcessCaptionFile (physicalFile: { filename: string, path: string }, videoCaption: MVideoCaptionFormattable) {
const videoCaptionsDir = CONFIG.STORAGE.CAPTIONS_DIR const videoCaptionsDir = CONFIG.STORAGE.CAPTIONS_DIR
const destination = join(videoCaptionsDir, videoCaption.getCaptionName()) const destination = join(videoCaptionsDir, videoCaption.getCaptionName())

View file

@ -38,7 +38,7 @@ import {
} from '../../typings/models' } from '../../typings/models'
// Set account keys, this could be long so process after the account creation and do not block the client // Set account keys, this could be long so process after the account creation and do not block the client
function setAsyncActorKeys (actor: MActor) { function setAsyncActorKeys <T extends MActor> (actor: T) {
return createPrivateAndPublicKeys() return createPrivateAndPublicKeys()
.then(({ publicKey, privateKey }) => { .then(({ publicKey, privateKey }) => {
actor.publicKey = publicKey actor.publicKey = publicKey
@ -148,7 +148,7 @@ function buildActorInstance (type: ActivityPubActorType, url: string, preferredU
sharedInboxUrl: WEBSERVER.URL + '/inbox', sharedInboxUrl: WEBSERVER.URL + '/inbox',
followersUrl: url + '/followers', followersUrl: url + '/followers',
followingUrl: url + '/following' followingUrl: url + '/following'
}) }) as MActor
} }
async function updateActorInstance (actorInstance: ActorModel, attributes: ActivityPubActor) { async function updateActorInstance (actorInstance: ActorModel, attributes: ActivityPubActor) {

View file

@ -2,9 +2,8 @@ import * as uuidv4 from 'uuid/v4'
import { ActivityPubActorType } from '../../shared/models/activitypub' import { ActivityPubActorType } from '../../shared/models/activitypub'
import { SERVER_ACTOR_NAME, WEBSERVER } from '../initializers/constants' import { SERVER_ACTOR_NAME, WEBSERVER } from '../initializers/constants'
import { AccountModel } from '../models/account/account' import { AccountModel } from '../models/account/account'
import { UserModel } from '../models/account/user'
import { buildActorInstance, getAccountActivityPubUrl, setAsyncActorKeys } from './activitypub' import { buildActorInstance, getAccountActivityPubUrl, setAsyncActorKeys } from './activitypub'
import { createVideoChannel } from './video-channel' import { createLocalVideoChannel } from './video-channel'
import { ActorModel } from '../models/activitypub/actor' import { ActorModel } from '../models/activitypub/actor'
import { UserNotificationSettingModel } from '../models/account/user-notification-setting' import { UserNotificationSettingModel } from '../models/account/user-notification-setting'
import { UserNotificationSetting, UserNotificationSettingValue } from '../../shared/models/users' import { UserNotificationSetting, UserNotificationSettingValue } from '../../shared/models/users'
@ -13,17 +12,17 @@ import { sequelizeTypescript } from '../initializers/database'
import { Transaction } from 'sequelize/types' import { Transaction } from 'sequelize/types'
import { Redis } from './redis' import { Redis } from './redis'
import { Emailer } from './emailer' import { Emailer } from './emailer'
import { MAccountActor, MActor, MChannelActor } from '../typings/models' import { MAccountDefault, MActorDefault, MChannelActor } from '../typings/models'
import { MUser, MUserId, MUserNotifSettingAccount } from '../typings/models/user' import { MUser, MUserDefault, MUserId } from '../typings/models/user'
type ChannelNames = { name: string, displayName: string } type ChannelNames = { name: string, displayName: string }
async function createUserAccountAndChannelAndPlaylist (parameters: { async function createUserAccountAndChannelAndPlaylist (parameters: {
userToCreate: UserModel, userToCreate: MUser,
userDisplayName?: string, userDisplayName?: string,
channelNames?: ChannelNames, channelNames?: ChannelNames,
validateUser?: boolean validateUser?: boolean
}): Promise<{ user: MUserNotifSettingAccount, account: MAccountActor, videoChannel: MChannelActor }> { }): Promise<{ user: MUserDefault, account: MAccountDefault, videoChannel: MChannelActor }> {
const { userToCreate, userDisplayName, channelNames, validateUser = true } = parameters const { userToCreate, userDisplayName, channelNames, validateUser = true } = parameters
const { user, account, videoChannel } = await sequelizeTypescript.transaction(async t => { const { user, account, videoChannel } = await sequelizeTypescript.transaction(async t => {
@ -32,7 +31,7 @@ async function createUserAccountAndChannelAndPlaylist (parameters: {
validate: validateUser validate: validateUser
} }
const userCreated: MUserNotifSettingAccount = await userToCreate.save(userOptions) const userCreated: MUserDefault = await userToCreate.save(userOptions)
userCreated.NotificationSetting = await createDefaultUserNotificationSettings(userCreated, t) userCreated.NotificationSetting = await createDefaultUserNotificationSettings(userCreated, t)
const accountCreated = await createLocalAccountWithoutKeys({ const accountCreated = await createLocalAccountWithoutKeys({
@ -45,7 +44,7 @@ async function createUserAccountAndChannelAndPlaylist (parameters: {
userCreated.Account = accountCreated userCreated.Account = accountCreated
const channelAttributes = await buildChannelAttributes(userCreated, channelNames) const channelAttributes = await buildChannelAttributes(userCreated, channelNames)
const videoChannel = await createVideoChannel(channelAttributes, accountCreated, t) const videoChannel = await createLocalVideoChannel(channelAttributes, accountCreated, t)
const videoPlaylist = await createWatchLaterPlaylist(accountCreated, t) const videoPlaylist = await createWatchLaterPlaylist(accountCreated, t)
@ -75,7 +74,7 @@ async function createLocalAccountWithoutKeys (parameters: {
const url = getAccountActivityPubUrl(name) const url = getAccountActivityPubUrl(name)
const actorInstance = buildActorInstance(type, url, name) const actorInstance = buildActorInstance(type, url, name)
const actorInstanceCreated: MActor = await actorInstance.save({ transaction: t }) const actorInstanceCreated: MActorDefault = await actorInstance.save({ transaction: t })
const accountInstance = new AccountModel({ const accountInstance = new AccountModel({
name: displayName || name, name: displayName || name,
@ -84,7 +83,7 @@ async function createLocalAccountWithoutKeys (parameters: {
actorId: actorInstanceCreated.id actorId: actorInstanceCreated.id
}) })
const accountInstanceCreated: MAccountActor = await accountInstance.save({ transaction: t }) const accountInstanceCreated: MAccountDefault = await accountInstance.save({ transaction: t })
accountInstanceCreated.Actor = actorInstanceCreated accountInstanceCreated.Actor = actorInstanceCreated
return accountInstanceCreated return accountInstanceCreated

View file

@ -4,12 +4,12 @@ import { VideoChannelCreate } from '../../shared/models'
import { VideoChannelModel } from '../models/video/video-channel' import { VideoChannelModel } from '../models/video/video-channel'
import { buildActorInstance, federateVideoIfNeeded, getVideoChannelActivityPubUrl } from './activitypub' import { buildActorInstance, federateVideoIfNeeded, getVideoChannelActivityPubUrl } from './activitypub'
import { VideoModel } from '../models/video/video' import { VideoModel } from '../models/video/video'
import { MAccountId, MChannelActor, MChannelId } from '../typings/models' import { MAccountId, MChannelDefault, MChannelId } from '../typings/models'
type CustomVideoChannelModelAccount <T extends MAccountId> = MChannelActor & type CustomVideoChannelModelAccount <T extends MAccountId> = MChannelDefault &
{ Account?: T } { Account?: T }
async function createVideoChannel <T extends MAccountId> ( async function createLocalVideoChannel <T extends MAccountId> (
videoChannelInfo: VideoChannelCreate, videoChannelInfo: VideoChannelCreate,
account: T, account: T,
t: Sequelize.Transaction t: Sequelize.Transaction
@ -31,7 +31,7 @@ async function createVideoChannel <T extends MAccountId> (
const videoChannel = new VideoChannelModel(videoChannelData) const videoChannel = new VideoChannelModel(videoChannelData)
const options = { transaction: t } const options = { transaction: t }
const videoChannelCreated: CustomVideoChannelModelAccount<T> = await videoChannel.save(options) as MChannelActor const videoChannelCreated: CustomVideoChannelModelAccount<T> = await videoChannel.save(options) as MChannelDefault
// Do not forget to add Account/Actor information to the created video channel // Do not forget to add Account/Actor information to the created video channel
videoChannelCreated.Account = account videoChannelCreated.Account = account
@ -54,6 +54,6 @@ async function federateAllVideosOfChannel (videoChannel: MChannelId) {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
export { export {
createVideoChannel, createLocalVideoChannel,
federateAllVideosOfChannel federateAllVideosOfChannel
} }

View file

@ -4,7 +4,7 @@ import { getSort } from '../utils'
import { AccountBlock } from '../../../shared/models/blocklist' import { AccountBlock } from '../../../shared/models/blocklist'
import { Op } from 'sequelize' import { Op } from 'sequelize'
import * as Bluebird from 'bluebird' import * as Bluebird from 'bluebird'
import { MAccountBlocklist, MAccountBlocklistAccounts } from '@server/typings/models' import { MAccountBlocklist, MAccountBlocklistAccounts, MAccountBlocklistFormattable } from '@server/typings/models'
enum ScopeNames { enum ScopeNames {
WITH_ACCOUNTS = 'WITH_ACCOUNTS' WITH_ACCOUNTS = 'WITH_ACCOUNTS'
@ -134,7 +134,7 @@ export class AccountBlocklistModel extends Model<AccountBlocklistModel> {
}) })
} }
toFormattedJSON (): AccountBlock { toFormattedJSON (this: MAccountBlocklistFormattable): AccountBlock {
return { return {
byAccount: this.ByAccount.toFormattedJSON(), byAccount: this.ByAccount.toFormattedJSON(),
blockedAccount: this.BlockedAccount.toFormattedJSON(), blockedAccount: this.BlockedAccount.toFormattedJSON(),

View file

@ -11,7 +11,12 @@ import { isActivityPubUrlValid } from '../../helpers/custom-validators/activityp
import { AccountVideoRate } from '../../../shared' import { AccountVideoRate } from '../../../shared'
import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from '../video/video-channel' import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from '../video/video-channel'
import * as Bluebird from 'bluebird' import * as Bluebird from 'bluebird'
import { MAccountVideoRate, MAccountVideoRateAccountUrl, MAccountVideoRateAccountVideo } from '@server/typings/models/video/video-rate' import {
MAccountVideoRate,
MAccountVideoRateAccountUrl,
MAccountVideoRateAccountVideo,
MAccountVideoRateFormattable
} from '@server/typings/models/video/video-rate'
/* /*
Account rates per video. Account rates per video.
@ -248,7 +253,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
}) })
} }
toFormattedJSON (): AccountVideoRate { toFormattedJSON (this: MAccountVideoRateFormattable): AccountVideoRate {
return { return {
video: this.Video.toFormattedJSON(), video: this.Video.toFormattedJSON(),
rating: this.type rating: this.type

View file

@ -32,7 +32,7 @@ import { FindOptions, IncludeOptions, Op, Transaction, WhereOptions } from 'sequ
import { AccountBlocklistModel } from './account-blocklist' import { AccountBlocklistModel } from './account-blocklist'
import { ServerBlocklistModel } from '../server/server-blocklist' import { ServerBlocklistModel } from '../server/server-blocklist'
import { ActorFollowModel } from '../activitypub/actor-follow' import { ActorFollowModel } from '../activitypub/actor-follow'
import { MAccountActor, MAccountDefault } from '../../typings/models' import { MAccountActor, MAccountDefault, MAccountSummaryFormattable, MAccountFormattable } from '../../typings/models'
import * as Bluebird from 'bluebird' import * as Bluebird from 'bluebird'
export enum ScopeNames { export enum ScopeNames {
@ -353,7 +353,7 @@ export class AccountModel extends Model<AccountModel> {
.findAll(query) .findAll(query)
} }
toFormattedJSON (): Account { toFormattedJSON (this: MAccountFormattable): Account {
const actor = this.Actor.toFormattedJSON() const actor = this.Actor.toFormattedJSON()
const account = { const account = {
id: this.id, id: this.id,
@ -367,8 +367,8 @@ export class AccountModel extends Model<AccountModel> {
return Object.assign(actor, account) return Object.assign(actor, account)
} }
toFormattedSummaryJSON (): AccountSummary { toFormattedSummaryJSON (this: MAccountSummaryFormattable): AccountSummary {
const actor = this.Actor.toFormattedJSON() const actor = this.Actor.toFormattedSummaryJSON()
return { return {
id: this.id, id: this.id,

View file

@ -17,6 +17,7 @@ import { UserModel } from './user'
import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model' import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model'
import { clearCacheByUserId } from '../../lib/oauth-model' import { clearCacheByUserId } from '../../lib/oauth-model'
import { MNotificationSettingFormattable } from '@server/typings/models'
@Table({ @Table({
tableName: 'userNotificationSetting', tableName: 'userNotificationSetting',
@ -152,7 +153,7 @@ export class UserNotificationSettingModel extends Model<UserNotificationSettingM
return clearCacheByUserId(instance.userId) return clearCacheByUserId(instance.userId)
} }
toFormattedJSON (): UserNotificationSetting { toFormattedJSON (this: MNotificationSettingFormattable): UserNotificationSetting {
return { return {
newCommentOnMyVideo: this.newCommentOnMyVideo, newCommentOnMyVideo: this.newCommentOnMyVideo,
newVideoFromSubscription: this.newVideoFromSubscription, newVideoFromSubscription: this.newVideoFromSubscription,

View file

@ -55,7 +55,13 @@ import { UserAdminFlag } from '../../../shared/models/users/user-flag.model'
import { isThemeNameValid } from '../../helpers/custom-validators/plugins' import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
import { getThemeOrDefault } from '../../lib/plugins/theme-utils' import { getThemeOrDefault } from '../../lib/plugins/theme-utils'
import * as Bluebird from 'bluebird' import * as Bluebird from 'bluebird'
import { MUserNotifSettingChannelDefault, MUserDefault, MUserId, MUserWithNotificationSetting } from '@server/typings/models' import {
MUserDefault,
MUserFormattable,
MUserId,
MUserNotifSettingChannelDefault,
MUserWithNotificationSetting
} from '@server/typings/models'
enum ScopeNames { enum ScopeNames {
WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL' WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL'
@ -554,7 +560,9 @@ export class UserModel extends Model<UserModel> {
return comparePassword(password, this.password) return comparePassword(password, this.password)
} }
toFormattedJSON (parameters: { withAdminFlags?: boolean } = {}): User { toSummaryJSON
toFormattedJSON (this: MUserFormattable, parameters: { withAdminFlags?: boolean } = {}): User {
const videoQuotaUsed = this.get('videoQuotaUsed') const videoQuotaUsed = this.get('videoQuotaUsed')
const videoQuotaUsedDaily = this.get('videoQuotaUsedDaily') const videoQuotaUsedDaily = this.get('videoQuotaUsedDaily')

View file

@ -32,6 +32,7 @@ import {
MActorFollowActorsDefault, MActorFollowActorsDefault,
MActorFollowActorsDefaultSubscription, MActorFollowActorsDefaultSubscription,
MActorFollowFollowingHost, MActorFollowFollowingHost,
MActorFollowFormattable,
MActorFollowSubscriptions MActorFollowSubscriptions
} from '@server/typings/models' } from '@server/typings/models'
@ -580,7 +581,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
return ActorFollowModel.findAll(query) return ActorFollowModel.findAll(query)
} }
toFormattedJSON (): ActorFollow { toFormattedJSON (this: MActorFollowFormattable): ActorFollow {
const follower = this.ActorFollower.toFormattedJSON() const follower = this.ActorFollower.toFormattedJSON()
const following = this.ActorFollowing.toFormattedJSON() const following = this.ActorFollowing.toFormattedJSON()

View file

@ -36,7 +36,16 @@ import { isOutdated, throwIfNotValid } from '../utils'
import { VideoChannelModel } from '../video/video-channel' import { VideoChannelModel } from '../video/video-channel'
import { ActorFollowModel } from './actor-follow' import { ActorFollowModel } from './actor-follow'
import { VideoModel } from '../video/video' import { VideoModel } from '../video/video'
import { MActor, MActorAccountChannelId, MActorFull } from '../../typings/models' import {
MActor,
MActorAccountChannelId,
MActorFormattable,
MActorFull, MActorHost,
MActorServer,
MActorSummaryFormattable,
MServerHost,
MActorRedundancyAllowed
} from '../../typings/models'
import * as Bluebird from 'bluebird' import * as Bluebird from 'bluebird'
enum ScopeNames { enum ScopeNames {
@ -393,24 +402,31 @@ export class ActorModel extends Model<ActorModel> {
}) })
} }
toFormattedJSON () { toFormattedSummaryJSON (this: MActorSummaryFormattable) {
let avatar: Avatar = null let avatar: Avatar = null
if (this.Avatar) { if (this.Avatar) {
avatar = this.Avatar.toFormattedJSON() avatar = this.Avatar.toFormattedJSON()
} }
return { return {
id: this.id,
url: this.url, url: this.url,
name: this.preferredUsername, name: this.preferredUsername,
host: this.getHost(), host: this.getHost(),
avatar
}
}
toFormattedJSON (this: MActorFormattable) {
const base = this.toFormattedSummaryJSON()
return Object.assign(base, {
id: this.id,
hostRedundancyAllowed: this.getRedundancyAllowed(), hostRedundancyAllowed: this.getRedundancyAllowed(),
followingCount: this.followingCount, followingCount: this.followingCount,
followersCount: this.followersCount, followersCount: this.followersCount,
avatar,
createdAt: this.createdAt, createdAt: this.createdAt,
updatedAt: this.updatedAt updatedAt: this.updatedAt
} })
} }
toActivityPubObject (name: string, type: 'Account' | 'Application' | 'VideoChannel') { toActivityPubObject (name: string, type: 'Account' | 'Application' | 'VideoChannel') {
@ -500,7 +516,7 @@ export class ActorModel extends Model<ActorModel> {
return this.serverId === null return this.serverId === null
} }
getWebfingerUrl () { getWebfingerUrl (this: MActorServer) {
return 'acct:' + this.preferredUsername + '@' + this.getHost() return 'acct:' + this.preferredUsername + '@' + this.getHost()
} }
@ -508,11 +524,11 @@ export class ActorModel extends Model<ActorModel> {
return this.Server ? `${this.preferredUsername}@${this.Server.host}` : this.preferredUsername return this.Server ? `${this.preferredUsername}@${this.Server.host}` : this.preferredUsername
} }
getHost () { getHost (this: MActorHost) {
return this.Server ? this.Server.host : WEBSERVER.HOST return this.Server ? this.Server.host : WEBSERVER.HOST
} }
getRedundancyAllowed () { getRedundancyAllowed (this: MActorRedundancyAllowed) {
return this.Server ? this.Server.redundancyAllowed : false return this.Server ? this.Server.redundancyAllowed : false
} }

View file

@ -7,6 +7,7 @@ import { remove } from 'fs-extra'
import { CONFIG } from '../../initializers/config' import { CONFIG } from '../../initializers/config'
import { throwIfNotValid } from '../utils' import { throwIfNotValid } from '../utils'
import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
import { MAvatarFormattable } from '@server/typings/models'
@Table({ @Table({
tableName: 'avatar', tableName: 'avatar',
@ -57,7 +58,7 @@ export class AvatarModel extends Model<AvatarModel> {
return AvatarModel.findOne(query) return AvatarModel.findOne(query)
} }
toFormattedJSON (): Avatar { toFormattedJSON (this: MAvatarFormattable): Avatar {
return { return {
path: this.getStaticPath(), path: this.getStaticPath(),
createdAt: this.createdAt, createdAt: this.createdAt,

View file

@ -12,7 +12,7 @@ import { PeerTubePlugin } from '../../../shared/models/plugins/peertube-plugin.m
import { FindAndCountOptions, json } from 'sequelize' import { FindAndCountOptions, json } from 'sequelize'
import { RegisterServerSettingOptions } from '../../../shared/models/plugins/register-server-setting.model' import { RegisterServerSettingOptions } from '../../../shared/models/plugins/register-server-setting.model'
import * as Bluebird from 'bluebird' import * as Bluebird from 'bluebird'
import { MPlugin } from '@server/typings/models' import { MPlugin, MPluginFormattable } from '@server/typings/models'
@DefaultScope(() => ({ @DefaultScope(() => ({
attributes: { attributes: {
@ -253,7 +253,7 @@ export class PluginModel extends Model<PluginModel> {
return result return result
} }
toFormattedJSON (): PeerTubePlugin { toFormattedJSON (this: MPluginFormattable): PeerTubePlugin {
return { return {
name: this.name, name: this.name,
type: this.type, type: this.type,

View file

@ -4,7 +4,7 @@ import { ServerModel } from './server'
import { ServerBlock } from '../../../shared/models/blocklist' import { ServerBlock } from '../../../shared/models/blocklist'
import { getSort } from '../utils' import { getSort } from '../utils'
import * as Bluebird from 'bluebird' import * as Bluebird from 'bluebird'
import { MServerBlocklist, MServerBlocklistAccountServer } from '@server/typings/models' import { MServerBlocklist, MServerBlocklistAccountServer, MServerBlocklistFormattable } from '@server/typings/models'
enum ScopeNames { enum ScopeNames {
WITH_ACCOUNT = 'WITH_ACCOUNT', WITH_ACCOUNT = 'WITH_ACCOUNT',
@ -112,7 +112,7 @@ export class ServerBlocklistModel extends Model<ServerBlocklistModel> {
}) })
} }
toFormattedJSON (): ServerBlock { toFormattedJSON (this: MServerBlocklistFormattable): ServerBlock {
return { return {
byAccount: this.ByAccount.toFormattedJSON(), byAccount: this.ByAccount.toFormattedJSON(),
blockedServer: this.BlockedServer.toFormattedJSON(), blockedServer: this.BlockedServer.toFormattedJSON(),

View file

@ -4,7 +4,7 @@ import { ActorModel } from '../activitypub/actor'
import { throwIfNotValid } from '../utils' import { throwIfNotValid } from '../utils'
import { ServerBlocklistModel } from './server-blocklist' import { ServerBlocklistModel } from './server-blocklist'
import * as Bluebird from 'bluebird' import * as Bluebird from 'bluebird'
import { MServer } from '@server/typings/models/server' import { MServer, MServerFormattable } from '@server/typings/models/server'
@Table({ @Table({
tableName: 'server', tableName: 'server',
@ -65,7 +65,7 @@ export class ServerModel extends Model<ServerModel> {
return this.BlockedByAccounts && this.BlockedByAccounts.length !== 0 return this.BlockedByAccounts && this.BlockedByAccounts.length !== 0
} }
toFormattedJSON () { toFormattedJSON (this: MServerFormattable) {
return { return {
host: this.host host: this.host
} }

View file

@ -2,6 +2,7 @@ import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Model, Ta
import { ScopeNames as VideoScopeNames, VideoModel } from './video' import { ScopeNames as VideoScopeNames, VideoModel } from './video'
import { VideoPrivacy } from '../../../shared/models/videos' import { VideoPrivacy } from '../../../shared/models/videos'
import { Op, Transaction } from 'sequelize' import { Op, Transaction } from 'sequelize'
import { MScheduleVideoUpdateFormattable } from '@server/typings/models'
@Table({ @Table({
tableName: 'scheduleVideoUpdate', tableName: 'scheduleVideoUpdate',
@ -96,7 +97,7 @@ export class ScheduleVideoUpdateModel extends Model<ScheduleVideoUpdateModel> {
return ScheduleVideoUpdateModel.destroy(query) return ScheduleVideoUpdateModel.destroy(query)
} }
toFormattedJSON () { toFormattedJSON (this: MScheduleVideoUpdateFormattable) {
return { return {
updateAt: this.updateAt, updateAt: this.updateAt,
privacy: this.privacy || undefined privacy: this.privacy || undefined

View file

@ -11,7 +11,7 @@ import { getSort, throwIfNotValid } from '../utils'
import { VideoModel } from './video' import { VideoModel } from './video'
import { VideoAbuseState } from '../../../shared' import { VideoAbuseState } from '../../../shared'
import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants' import { CONSTRAINTS_FIELDS, VIDEO_ABUSE_STATES } from '../../initializers/constants'
import { MVideoAbuse, MVideoAbuseAccountVideo, MVideoAbuseVideo } from '../../typings/models' import { MVideoAbuse, MVideoAbuseFormattable, MVideoAbuseVideo } from '../../typings/models'
import * as Bluebird from 'bluebird' import * as Bluebird from 'bluebird'
@Table({ @Table({
@ -108,7 +108,7 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
}) })
} }
toFormattedJSON (this: MVideoAbuseAccountVideo): VideoAbuse { toFormattedJSON (this: MVideoAbuseFormattable): VideoAbuse {
return { return {
id: this.id, id: this.id,
reason: this.reason, reason: this.reason,

View file

@ -8,7 +8,7 @@ import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
import { FindOptions } from 'sequelize' import { FindOptions } from 'sequelize'
import { ThumbnailModel } from './thumbnail' import { ThumbnailModel } from './thumbnail'
import * as Bluebird from 'bluebird' import * as Bluebird from 'bluebird'
import { MVideoBlacklist } from '@server/typings/models' import { MVideoBlacklist, MVideoBlacklistFormattable } from '@server/typings/models'
@Table({ @Table({
tableName: 'videoBlacklist', tableName: 'videoBlacklist',
@ -111,7 +111,7 @@ export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
return VideoBlacklistModel.findOne(query) return VideoBlacklistModel.findOne(query)
} }
toFormattedJSON (): VideoBlacklist { toFormattedJSON (this: MVideoBlacklistFormattable): VideoBlacklist {
return { return {
id: this.id, id: this.id,
createdAt: this.createdAt, createdAt: this.createdAt,

View file

@ -22,7 +22,7 @@ import { logger } from '../../helpers/logger'
import { remove } from 'fs-extra' import { remove } from 'fs-extra'
import { CONFIG } from '../../initializers/config' import { CONFIG } from '../../initializers/config'
import * as Bluebird from 'bluebird' import * as Bluebird from 'bluebird'
import { MVideoCaptionVideo } from '@server/typings/models' import { MVideoCaptionFormattable, MVideoCaptionVideo } from '@server/typings/models'
export enum ScopeNames { export enum ScopeNames {
WITH_VIDEO_UUID_AND_REMOTE = 'WITH_VIDEO_UUID_AND_REMOTE' WITH_VIDEO_UUID_AND_REMOTE = 'WITH_VIDEO_UUID_AND_REMOTE'
@ -154,7 +154,7 @@ export class VideoCaptionModel extends Model<VideoCaptionModel> {
return this.Video.remote === false return this.Video.remote === false
} }
toFormattedJSON (): VideoCaption { toFormattedJSON (this: MVideoCaptionFormattable): VideoCaption {
return { return {
language: { language: {
id: this.language, id: this.language,
@ -164,15 +164,15 @@ export class VideoCaptionModel extends Model<VideoCaptionModel> {
} }
} }
getCaptionStaticPath () { getCaptionStaticPath (this: MVideoCaptionFormattable) {
return join(LAZY_STATIC_PATHS.VIDEO_CAPTIONS, this.getCaptionName()) return join(LAZY_STATIC_PATHS.VIDEO_CAPTIONS, this.getCaptionName())
} }
getCaptionName () { getCaptionName (this: MVideoCaptionFormattable) {
return `${this.Video.uuid}-${this.language}.vtt` return `${this.Video.uuid}-${this.language}.vtt`
} }
removeCaptionFile () { removeCaptionFile (this: MVideoCaptionFormattable) {
return remove(CONFIG.STORAGE.CAPTIONS_DIR + this.getCaptionName()) return remove(CONFIG.STORAGE.CAPTIONS_DIR + this.getCaptionName())
} }
} }

View file

@ -3,7 +3,7 @@ import { AccountModel } from '../account/account'
import { ScopeNames as VideoScopeNames, VideoModel } from './video' import { ScopeNames as VideoScopeNames, VideoModel } from './video'
import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos' import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos'
import { getSort } from '../utils' import { getSort } from '../utils'
import { MVideoChangeOwnershipFull } from '@server/typings/models/video/video-change-ownership' import { MVideoChangeOwnershipFormattable, MVideoChangeOwnershipFull } from '@server/typings/models/video/video-change-ownership'
import * as Bluebird from 'bluebird' import * as Bluebird from 'bluebird'
enum ScopeNames { enum ScopeNames {
@ -119,7 +119,7 @@ export class VideoChangeOwnershipModel extends Model<VideoChangeOwnershipModel>
.findByPk(id) .findByPk(id)
} }
toFormattedJSON (): VideoChangeOwnership { toFormattedJSON (this: MVideoChangeOwnershipFormattable): VideoChangeOwnership {
return { return {
id: this.id, id: this.id,
status: this.status, status: this.status,

View file

@ -37,7 +37,7 @@ import * as Bluebird from 'bluebird'
import { import {
MChannelAccountDefault, MChannelAccountDefault,
MChannelActor, MChannelActor,
MChannelActorAccountDefaultVideos MChannelActorAccountDefaultVideos, MChannelSummaryFormattable, MChannelFormattable
} from '../../typings/models/video' } from '../../typings/models/video'
// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
@ -482,7 +482,20 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
.findByPk(id, options) .findByPk(id, options)
} }
toFormattedJSON (): VideoChannel { toFormattedSummaryJSON (this: MChannelSummaryFormattable): VideoChannelSummary {
const actor = this.Actor.toFormattedSummaryJSON()
return {
id: this.id,
name: actor.name,
displayName: this.getDisplayName(),
url: actor.url,
host: actor.host,
avatar: actor.avatar
}
}
toFormattedJSON (this: MChannelFormattable): VideoChannel {
const actor = this.Actor.toFormattedJSON() const actor = this.Actor.toFormattedJSON()
const videoChannel = { const videoChannel = {
id: this.id, id: this.id,
@ -500,19 +513,6 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
return Object.assign(actor, videoChannel) return Object.assign(actor, videoChannel)
} }
toFormattedSummaryJSON (): VideoChannelSummary {
const actor = this.Actor.toFormattedJSON()
return {
id: this.id,
name: actor.name,
displayName: this.getDisplayName(),
url: actor.url,
host: actor.host,
avatar: actor.avatar
}
}
toActivityPubObject (): ActivityPubActor { toActivityPubObject (): ActivityPubActor {
const obj = this.Actor.toActivityPubObject(this.name, 'VideoChannel') const obj = this.Actor.toActivityPubObject(this.name, 'VideoChannel')

View file

@ -17,6 +17,7 @@ import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'se
import * as Bluebird from 'bluebird' import * as Bluebird from 'bluebird'
import { import {
MComment, MComment,
MCommentFormattable,
MCommentId, MCommentId,
MCommentOwner, MCommentOwner,
MCommentOwnerReplyVideoLight, MCommentOwnerReplyVideoLight,
@ -475,7 +476,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
return uniq(result) return uniq(result)
} }
toFormattedJSON () { toFormattedJSON (this: MCommentFormattable) {
return { return {
id: this.id, id: this.id,
url: this.url, url: this.url,

View file

@ -16,7 +16,7 @@ import {
} from '../../lib/activitypub' } from '../../lib/activitypub'
import { isArray } from '../../helpers/custom-validators/misc' import { isArray } from '../../helpers/custom-validators/misc'
import { VideoStreamingPlaylist } from '../../../shared/models/videos/video-streaming-playlist.model' import { VideoStreamingPlaylist } from '../../../shared/models/videos/video-streaming-playlist.model'
import { MVideo, MVideoAP, MVideoDetails } from '../../typings/models' import { MVideo, MVideoAP, MVideoFormattable, MVideoFormattableDetails } from '../../typings/models'
import { MStreamingPlaylistRedundancies } from '../../typings/models/video/video-streaming-playlist' import { MStreamingPlaylistRedundancies } from '../../typings/models/video/video-streaming-playlist'
import { MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file' import { MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file'
@ -29,7 +29,7 @@ export type VideoFormattingJSONOptions = {
blacklistInfo?: boolean blacklistInfo?: boolean
} }
} }
function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormattingJSONOptions): Video { function videoModelToFormattedJSON (video: MVideoFormattable, options?: VideoFormattingJSONOptions): Video {
const userHistory = isArray(video.UserVideoHistories) ? video.UserVideoHistories[0] : undefined const userHistory = isArray(video.UserVideoHistories) ? video.UserVideoHistories[0] : undefined
const videoObject: Video = { const videoObject: Video = {
@ -103,7 +103,7 @@ function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormatting
return videoObject return videoObject
} }
function videoModelToFormattedDetailsJSON (video: MVideoDetails): VideoDetails { function videoModelToFormattedDetailsJSON (video: MVideoFormattableDetails): VideoDetails {
const formattedJson = video.toFormattedJSON({ const formattedJson = video.toFormattedJSON({
additionalAttributes: { additionalAttributes: {
scheduledUpdate: true, scheduledUpdate: true,

View file

@ -21,7 +21,7 @@ import { VideoImport, VideoImportState } from '../../../shared'
import { isVideoMagnetUriValid } from '../../helpers/custom-validators/videos' import { isVideoMagnetUriValid } from '../../helpers/custom-validators/videos'
import { UserModel } from '../account/user' import { UserModel } from '../account/user'
import * as Bluebird from 'bluebird' import * as Bluebird from 'bluebird'
import { MVideoImportDefault } from '@server/typings/models/video/video-import' import { MVideoImportDefault, MVideoImportFormattable } from '@server/typings/models/video/video-import'
@DefaultScope(() => ({ @DefaultScope(() => ({
include: [ include: [
@ -154,7 +154,7 @@ export class VideoImportModel extends Model<VideoImportModel> {
return this.targetUrl || this.magnetUri || this.torrentName return this.targetUrl || this.magnetUri || this.torrentName
} }
toFormattedJSON (): VideoImport { toFormattedJSON (this: MVideoImportFormattable): VideoImport {
const videoFormatOptions = { const videoFormatOptions = {
completeDescription: true, completeDescription: true,
additionalAttributes: { state: true, waitTranscoding: true, scheduledUpdate: true } additionalAttributes: { state: true, waitTranscoding: true, scheduledUpdate: true }

View file

@ -21,12 +21,16 @@ import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object' import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object'
import * as validator from 'validator' import * as validator from 'validator'
import { AggregateOptions, Op, ScopeOptions, Sequelize, Transaction } from 'sequelize' import { AggregateOptions, Op, ScopeOptions, Sequelize, Transaction } from 'sequelize'
import { UserModel } from '../account/user'
import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../shared/models/videos/playlist/video-playlist-element.model' import { VideoPlaylistElement, VideoPlaylistElementType } from '../../../shared/models/videos/playlist/video-playlist-element.model'
import { AccountModel } from '../account/account' import { AccountModel } from '../account/account'
import { VideoPrivacy } from '../../../shared/models/videos' import { VideoPrivacy } from '../../../shared/models/videos'
import * as Bluebird from 'bluebird' import * as Bluebird from 'bluebird'
import { MVideoPlaylistAP, MVideoPlaylistElement, MVideoPlaylistVideoThumbnail } from '@server/typings/models/video/video-playlist-element' import {
MVideoPlaylistElement,
MVideoPlaylistElementAP,
MVideoPlaylistElementFormattable,
MVideoPlaylistVideoThumbnail
} from '@server/typings/models/video/video-playlist-element'
import { MUserAccountId } from '@server/typings/models' import { MUserAccountId } from '@server/typings/models'
@Table({ @Table({
@ -180,7 +184,7 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel>
return VideoPlaylistElementModel.findByPk(playlistElementId) return VideoPlaylistElementModel.findByPk(playlistElementId)
} }
static loadByPlaylistAndVideoForAP (playlistId: number | string, videoId: number | string): Bluebird<MVideoPlaylistAP> { static loadByPlaylistAndVideoForAP (playlistId: number | string, videoId: number | string): Bluebird<MVideoPlaylistElementAP> {
const playlistWhere = validator.isUUID('' + playlistId) ? { uuid: playlistId } : { id: playlistId } const playlistWhere = validator.isUUID('' + playlistId) ? { uuid: playlistId } : { id: playlistId }
const videoWhere = validator.isUUID('' + videoId) ? { uuid: videoId } : { id: videoId } const videoWhere = validator.isUUID('' + videoId) ? { uuid: videoId } : { id: videoId }
@ -293,7 +297,7 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel>
return VideoPlaylistElementModel.increment({ position: by }, query) return VideoPlaylistElementModel.increment({ position: by }, query)
} }
getType (displayNSFW?: boolean, accountId?: number) { getType (this: MVideoPlaylistElementFormattable, displayNSFW?: boolean, accountId?: number) {
const video = this.Video const video = this.Video
if (!video) return VideoPlaylistElementType.DELETED if (!video) return VideoPlaylistElementType.DELETED
@ -309,14 +313,17 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel>
return VideoPlaylistElementType.REGULAR return VideoPlaylistElementType.REGULAR
} }
getVideoElement (displayNSFW?: boolean, accountId?: number) { getVideoElement (this: MVideoPlaylistElementFormattable, displayNSFW?: boolean, accountId?: number) {
if (!this.Video) return null if (!this.Video) return null
if (this.getType(displayNSFW, accountId) !== VideoPlaylistElementType.REGULAR) return null if (this.getType(displayNSFW, accountId) !== VideoPlaylistElementType.REGULAR) return null
return this.Video.toFormattedJSON() return this.Video.toFormattedJSON()
} }
toFormattedJSON (options: { displayNSFW?: boolean, accountId?: number } = {}): VideoPlaylistElement { toFormattedJSON (
this: MVideoPlaylistElementFormattable,
options: { displayNSFW?: boolean, accountId?: number } = {}
): VideoPlaylistElement {
return { return {
id: this.id, id: this.id,
position: this.position, position: this.position,

View file

@ -46,6 +46,7 @@ import { FindOptions, literal, Op, ScopeOptions, Transaction, WhereOptions } fro
import * as Bluebird from 'bluebird' import * as Bluebird from 'bluebird'
import { import {
MVideoPlaylistAccountThumbnail, MVideoPlaylistAccountThumbnail,
MVideoPlaylistFormattable,
MVideoPlaylistFull, MVideoPlaylistFull,
MVideoPlaylistFullSummary, MVideoPlaylistFullSummary,
MVideoPlaylistIdWithElements MVideoPlaylistIdWithElements
@ -479,7 +480,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
return isOutdated(this, ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL) return isOutdated(this, ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL)
} }
toFormattedJSON (): VideoPlaylist { toFormattedJSON (this: MVideoPlaylistFormattable): VideoPlaylist {
return { return {
id: this.id, id: this.id,
uuid: this.uuid, uuid: this.uuid,

View file

@ -132,8 +132,9 @@ import {
MVideoFullLight, MVideoFullLight,
MVideoIdThumbnail, MVideoIdThumbnail,
MVideoThumbnail, MVideoThumbnail,
MVideoWithAllFiles, MVideoWithAllFiles, MVideoWithFile,
MVideoWithRights MVideoWithRights,
MVideoFormattable
} from '../../typings/models' } from '../../typings/models'
import { MVideoFile, MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file' import { MVideoFile, MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file'
import { MThumbnail } from '../../typings/models/video/thumbnail' import { MThumbnail } from '../../typings/models/video/thumbnail'
@ -1765,14 +1766,14 @@ export class VideoModel extends Model<VideoModel> {
this.VideoChannel.Account.isBlocked() this.VideoChannel.Account.isBlocked()
} }
getOriginalFile () { getOriginalFile <T extends MVideoWithFile> (this: T) {
if (Array.isArray(this.VideoFiles) === false) return undefined if (Array.isArray(this.VideoFiles) === false) return undefined
// The original file is the file that have the higher resolution // The original file is the file that have the higher resolution
return maxBy(this.VideoFiles, file => file.resolution) return maxBy(this.VideoFiles, file => file.resolution)
} }
getFile (resolution: number) { getFile <T extends MVideoWithFile> (this: T, resolution: number) {
if (Array.isArray(this.VideoFiles) === false) return undefined if (Array.isArray(this.VideoFiles) === false) return undefined
return this.VideoFiles.find(f => f.resolution === resolution) return this.VideoFiles.find(f => f.resolution === resolution)
@ -1878,7 +1879,7 @@ export class VideoModel extends Model<VideoModel> {
return join(LAZY_STATIC_PATHS.PREVIEWS, preview.filename) return join(LAZY_STATIC_PATHS.PREVIEWS, preview.filename)
} }
toFormattedJSON (options?: VideoFormattingJSONOptions): Video { toFormattedJSON <T extends MVideoFormattable> (this: T, options?: VideoFormattingJSONOptions): Video {
return videoModelToFormattedJSON(this, options) return videoModelToFormattedJSON(this, options)
} }

View file

@ -1,6 +1,6 @@
import { AccountBlocklistModel } from '../../../models/account/account-blocklist' import { AccountBlocklistModel } from '../../../models/account/account-blocklist'
import { PickWith } from '../../utils' import { PickWith } from '../../utils'
import { MAccountDefault } from './account' import { MAccountDefault, MAccountFormattable } from './account'
type Use<K extends keyof AccountBlocklistModel, M> = PickWith<AccountBlocklistModel, K, M> type Use<K extends keyof AccountBlocklistModel, M> = PickWith<AccountBlocklistModel, K, M>
@ -15,3 +15,11 @@ export type MAccountBlocklistId = Pick<AccountBlocklistModel, 'id'>
export type MAccountBlocklistAccounts = MAccountBlocklist & export type MAccountBlocklistAccounts = MAccountBlocklist &
Use<'ByAccount', MAccountDefault> & Use<'ByAccount', MAccountDefault> &
Use<'BlockedAccount', MAccountDefault> Use<'BlockedAccount', MAccountDefault>
// ############################################################################
// Format for API or AP object
export type MAccountBlocklistFormattable = Pick<MAccountBlocklist, 'createdAt'> &
Use<'ByAccount', MAccountFormattable> &
Use<'BlockedAccount', MAccountFormattable>

View file

@ -9,9 +9,11 @@ import {
MActorId, MActorId,
MActorServer, MActorServer,
MActorSummary, MActorSummary,
MActorUrl MActorSummaryFormattable,
MActorUrl,
MActorFormattable
} from './actor' } from './actor'
import { PickWith } from '../../utils' import { FunctionProperties, PickWith } from '../../utils'
import { MAccountBlocklistId } from './account-blocklist' import { MAccountBlocklistId } from './account-blocklist'
import { MChannelDefault } from '@server/typings/models' import { MChannelDefault } from '@server/typings/models'
@ -67,7 +69,8 @@ export type MAccountServer = MAccount &
// For API // For API
export type MAccountSummary = Pick<MAccount, 'id' | 'name'> & export type MAccountSummary = FunctionProperties<MAccount> &
Pick<MAccount, 'id' | 'name'> &
Use<'Actor', MActorSummary> Use<'Actor', MActorSummary>
export type MAccountSummaryBlocks = MAccountSummary & export type MAccountSummaryBlocks = MAccountSummary &
@ -75,3 +78,15 @@ export type MAccountSummaryBlocks = MAccountSummary &
export type MAccountAPI = MAccount & export type MAccountAPI = MAccount &
Use<'Actor', MActorAPI> Use<'Actor', MActorAPI>
// ############################################################################
// Format for API or AP object
export type MAccountSummaryFormattable = FunctionProperties<MAccount> &
Pick<MAccount, 'id' | 'name'> &
Use<'Actor', MActorSummaryFormattable>
export type MAccountFormattable = FunctionProperties<MAccount> &
Pick<MAccount, 'id' | 'name' | 'description' | 'createdAt' | 'updatedAt' | 'userId'> &
Use<'Actor', MActorFormattable>

View file

@ -3,14 +3,15 @@ import {
MActor, MActor,
MActorAccount, MActorAccount,
MActorAccountChannel, MActorAccountChannel,
MActorChannel,
MActorChannelAccountActor, MActorChannelAccountActor,
MActorDefault, MActorDefault,
MActorFormattable,
MActorHost, MActorHost,
MActorUsername MActorUsername
} from './actor' } from './actor'
import { PickWith } from '../../utils' import { PickWith } from '../../utils'
import { ActorModel } from '@server/models/activitypub/actor' import { ActorModel } from '@server/models/activitypub/actor'
import { MChannelDefault } from '@server/typings/models'
type Use<K extends keyof ActorFollowModel, M> = PickWith<ActorFollowModel, K, M> type Use<K extends keyof ActorFollowModel, M> = PickWith<ActorFollowModel, K, M>
@ -43,9 +44,12 @@ export type MActorFollowFull = MActorFollow &
// For subscriptions // For subscriptions
type SubscriptionFollowing = MActorDefault &
PickWith<ActorModel, 'VideoChannel', MChannelDefault>
export type MActorFollowActorsDefaultSubscription = MActorFollow & export type MActorFollowActorsDefaultSubscription = MActorFollow &
Use<'ActorFollower', MActorDefault> & Use<'ActorFollower', MActorDefault> &
Use<'ActorFollowing', MActorDefault & MActorChannel> Use<'ActorFollowing', SubscriptionFollowing>
export type MActorFollowFollowingFullFollowerAccount = MActorFollow & export type MActorFollowFollowingFullFollowerAccount = MActorFollow &
Use<'ActorFollower', MActorAccount> & Use<'ActorFollower', MActorAccount> &
@ -53,3 +57,11 @@ export type MActorFollowFollowingFullFollowerAccount = MActorFollow &
export type MActorFollowSubscriptions = MActorFollow & export type MActorFollowSubscriptions = MActorFollow &
Use<'ActorFollowing', MActorChannelAccountActor> Use<'ActorFollowing', MActorChannelAccountActor>
// ############################################################################
// Format for API or AP object
export type MActorFollowFormattable = Pick<MActorFollow, 'id' | 'score' | 'state' | 'createdAt' | 'updatedAt'> &
Use<'ActorFollower', MActorFormattable> &
Use<'ActorFollowing', MActorFormattable>

View file

@ -1,8 +1,8 @@
import { ActorModel } from '../../../models/activitypub/actor' import { ActorModel } from '../../../models/activitypub/actor'
import { PickWith } from '../../utils' import { FunctionProperties, PickWith } from '../../utils'
import { MAccount, MAccountDefault, MAccountId, MAccountIdActor } from './account' import { MAccount, MAccountDefault, MAccountId, MAccountIdActor } from './account'
import { MServer, MServerHost, MServerHostBlocks } from '../server' import { MServer, MServerHost, MServerHostBlocks, MServerRedundancyAllowed } from '../server'
import { MAvatar } from './avatar' import { MAvatar, MAvatarFormattable } from './avatar'
import { MChannel, MChannelAccountActor, MChannelAccountDefault, MChannelId, MChannelIdActor } from '../video' import { MChannel, MChannelAccountActor, MChannelAccountDefault, MChannelId, MChannelIdActor } from '../video'
type Use<K extends keyof ActorModel, M> = PickWith<ActorModel, K, M> type Use<K extends keyof ActorModel, M> = PickWith<ActorModel, K, M>
@ -29,6 +29,7 @@ export type MActorLight = Omit<MActor, 'privateKey' | 'privateKey'>
// Some association attributes // Some association attributes
export type MActorHost = Use<'Server', MServerHost> export type MActorHost = Use<'Server', MServerHost>
export type MActorRedundancyAllowed = Use<'Server', MServerRedundancyAllowed>
export type MActorDefaultLight = MActorLight & export type MActorDefaultLight = MActorLight &
Use<'Server', MServerHost> & Use<'Server', MServerHost> &
@ -92,7 +93,8 @@ export type MActorFullActor = MActor &
// API // API
export type MActorSummary = Pick<MActor, 'id' | 'preferredUsername' | 'url' | 'serverId' | 'avatarId'> & export type MActorSummary = FunctionProperties<MActor> &
Pick<MActor, 'id' | 'preferredUsername' | 'url' | 'serverId' | 'avatarId'> &
Use<'Server', MServerHost> & Use<'Server', MServerHost> &
Use<'Avatar', MAvatar> Use<'Avatar', MAvatar>
@ -101,3 +103,16 @@ export type MActorSummaryBlocks = MActorSummary &
export type MActorAPI = Omit<MActorDefault, 'publicKey' | 'privateKey' | 'inboxUrl' | 'outboxUrl' | 'sharedInboxUrl' | export type MActorAPI = Omit<MActorDefault, 'publicKey' | 'privateKey' | 'inboxUrl' | 'outboxUrl' | 'sharedInboxUrl' |
'followersUrl' | 'followingUrl' | 'url' | 'createdAt' | 'updatedAt'> 'followersUrl' | 'followingUrl' | 'url' | 'createdAt' | 'updatedAt'>
// ############################################################################
// Format for API or AP object
export type MActorSummaryFormattable = FunctionProperties<MActor> &
Pick<MActor, 'url' | 'preferredUsername'> &
Use<'Server', MServerHost> &
Use<'Avatar', MAvatarFormattable>
export type MActorFormattable = MActorSummaryFormattable &
Pick<MActor, 'id' | 'followingCount' | 'followersCount' | 'createdAt' | 'updatedAt'> &
Use<'Server', MServer>

View file

@ -1,3 +1,11 @@
import { AvatarModel } from '../../../models/avatar/avatar' import { AvatarModel } from '../../../models/avatar/avatar'
import { FunctionProperties } from '@server/typings/utils'
export type MAvatar = AvatarModel export type MAvatar = AvatarModel
// ############################################################################
// Format for API or AP object
export type MAvatarFormattable = FunctionProperties<MAvatar> &
Pick<MAvatar, 'filename' | 'createdAt' | 'updatedAt'>

View file

@ -1,3 +1,10 @@
import { PluginModel } from '@server/models/server/plugin' import { PluginModel } from '@server/models/server/plugin'
export type MPlugin = PluginModel export type MPlugin = PluginModel
// ############################################################################
// Format for API or AP object
export type MPluginFormattable = Pick<MPlugin, 'name' | 'type' | 'version' | 'latestVersion' | 'enabled' | 'uninstalled'
| 'peertubeEngine' | 'description' | 'homepage' | 'settings' | 'createdAt' | 'updatedAt'>

View file

@ -1,6 +1,6 @@
import { ServerBlocklistModel } from '@server/models/server/server-blocklist' import { ServerBlocklistModel } from '@server/models/server/server-blocklist'
import { PickWith } from '@server/typings/utils' import { PickWith } from '@server/typings/utils'
import { MAccountDefault, MServer } from '@server/typings/models' import { MAccountDefault, MAccountFormattable, MServer, MServerFormattable } from '@server/typings/models'
type Use<K extends keyof ServerBlocklistModel, M> = PickWith<ServerBlocklistModel, K, M> type Use<K extends keyof ServerBlocklistModel, M> = PickWith<ServerBlocklistModel, K, M>
@ -13,3 +13,11 @@ export type MServerBlocklist = Omit<ServerBlocklistModel, 'ByAccount' | 'Blocked
export type MServerBlocklistAccountServer = MServerBlocklist & export type MServerBlocklistAccountServer = MServerBlocklist &
Use<'ByAccount', MAccountDefault> & Use<'ByAccount', MAccountDefault> &
Use<'BlockedServer', MServer> Use<'BlockedServer', MServer>
// ############################################################################
// Format for API or AP object
export type MServerBlocklistFormattable = Pick<MServerBlocklist, 'createdAt'> &
Use<'ByAccount', MAccountFormattable> &
Use<'BlockedServer', MServerFormattable>

View file

@ -1,5 +1,5 @@
import { ServerModel } from '../../../models/server/server' import { ServerModel } from '../../../models/server/server'
import { PickWith } from '../../utils' import { FunctionProperties, PickWith } from '../../utils'
import { MAccountBlocklistId } from '../account' import { MAccountBlocklistId } from '../account'
type Use<K extends keyof ServerModel, M> = PickWith<ServerModel, K, M> type Use<K extends keyof ServerModel, M> = PickWith<ServerModel, K, M>
@ -11,6 +11,14 @@ export type MServer = Omit<ServerModel, 'Actors' | 'BlockedByAccounts'>
// ############################################################################ // ############################################################################
export type MServerHost = Pick<MServer, 'host'> export type MServerHost = Pick<MServer, 'host'>
export type MServerRedundancyAllowed = Pick<MServer, 'redundancyAllowed'>
export type MServerHostBlocks = MServerHost & export type MServerHostBlocks = MServerHost &
Use<'BlockedByAccounts', MAccountBlocklistId[]> Use<'BlockedByAccounts', MAccountBlocklistId[]>
// ############################################################################
// Format for API or AP object
export type MServerFormattable = FunctionProperties<MServer> &
Pick<MServer, 'host'>

View file

@ -1,3 +1,9 @@
import { UserNotificationSettingModel } from '@server/models/account/user-notification-setting' import { UserNotificationSettingModel } from '@server/models/account/user-notification-setting'
export type MNotificationSetting = Omit<UserNotificationSettingModel, 'User'> export type MNotificationSetting = Omit<UserNotificationSettingModel, 'User'>
// ############################################################################
// Format for API or AP object
export type MNotificationSettingFormattable = MNotificationSetting

View file

@ -1,7 +1,17 @@
import { UserModel } from '../../../models/account/user' import { UserModel } from '../../../models/account/user'
import { PickWith } from '../../utils' import { PickWith, PickWithOpt } from '../../utils'
import { MAccount, MAccountDefault, MAccountDefaultChannelDefault, MAccountId, MAccountIdActorId, MAccountUrl } from '../account' import {
import { MNotificationSetting } from './user-notification-setting' MAccount,
MAccountDefault,
MAccountDefaultChannelDefault,
MAccountFormattable,
MAccountId,
MAccountIdActorId,
MAccountUrl
} from '../account'
import { MNotificationSetting, MNotificationSettingFormattable } from './user-notification-setting'
import { AccountModel } from '@server/models/account/account'
import { MChannelFormattable } from '@server/typings/models'
type Use<K extends keyof UserModel, M> = PickWith<UserModel, K, M> type Use<K extends keyof UserModel, M> = PickWith<UserModel, K, M>
@ -11,6 +21,7 @@ export type MUser = Omit<UserModel, 'Account' | 'NotificationSetting' | 'VideoIm
// ############################################################################ // ############################################################################
export type MUserQuotaUsed = MUser & { videoQuotaUsed?: number, videoQuotaUsedDaily?: number }
export type MUserId = Pick<UserModel, 'id'> export type MUserId = Pick<UserModel, 'id'>
// ############################################################################ // ############################################################################
@ -49,3 +60,11 @@ export type MUserNotifSettingAccount = MUser &
export type MUserDefault = MUser & export type MUserDefault = MUser &
Use<'NotificationSetting', MNotificationSetting> & Use<'NotificationSetting', MNotificationSetting> &
Use<'Account', MAccountDefault> Use<'Account', MAccountDefault>
// ############################################################################
// Format for API or AP object
export type MUserFormattable = MUserQuotaUsed &
Use<'Account', MAccountFormattable & PickWithOpt<AccountModel, 'VideoChannels', MChannelFormattable[]>> &
PickWithOpt<UserModel, 'NotificationSetting', MNotificationSettingFormattable>

View file

@ -1,3 +1,9 @@
import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update'
export type MScheduleVideoUpdate = Omit<ScheduleVideoUpdateModel, 'Video'> export type MScheduleVideoUpdate = Omit<ScheduleVideoUpdateModel, 'Video'>
// ############################################################################
// Format for API or AP object
export type MScheduleVideoUpdateFormattable = Pick<MScheduleVideoUpdate, 'updateAt' | 'privacy'>

View file

@ -1,7 +1,7 @@
import { VideoAbuseModel } from '../../../models/video/video-abuse' import { VideoAbuseModel } from '../../../models/video/video-abuse'
import { PickWith } from '../../utils' import { PickWith } from '../../utils'
import { MVideo } from './video' import { MVideo } from './video'
import { MAccountDefault } from '../account' import { MAccountDefault, MAccountFormattable } from '../account'
type Use<K extends keyof VideoAbuseModel, M> = PickWith<VideoAbuseModel, K, M> type Use<K extends keyof VideoAbuseModel, M> = PickWith<VideoAbuseModel, K, M>
@ -21,3 +21,11 @@ export type MVideoAbuseAccountVideo = MVideoAbuse &
Pick<VideoAbuseModel, 'toActivityPubObject'> & Pick<VideoAbuseModel, 'toActivityPubObject'> &
Use<'Video', MVideo> & Use<'Video', MVideo> &
Use<'Account', MAccountDefault> Use<'Account', MAccountDefault>
// ############################################################################
// Format for API or AP object
export type MVideoAbuseFormattable = MVideoAbuse &
Use<'Account', MAccountFormattable> &
Use<'Video', Pick<MVideo, 'id' | 'uuid' | 'name'>>

View file

@ -1,6 +1,6 @@
import { VideoBlacklistModel } from '../../../models/video/video-blacklist' import { VideoBlacklistModel } from '../../../models/video/video-blacklist'
import { PickWith } from '@server/typings/utils' import { PickWith } from '@server/typings/utils'
import { MVideo } from '@server/typings/models' import { MVideo, MVideoFormattable } from '@server/typings/models'
type Use<K extends keyof VideoBlacklistModel, M> = PickWith<VideoBlacklistModel, K, M> type Use<K extends keyof VideoBlacklistModel, M> = PickWith<VideoBlacklistModel, K, M>
@ -15,3 +15,10 @@ export type MVideoBlacklistUnfederated = Pick<MVideoBlacklist, 'unfederated'>
export type MVideoBlacklistVideo = MVideoBlacklist & export type MVideoBlacklistVideo = MVideoBlacklist &
Use<'Video', MVideo> Use<'Video', MVideo>
// ############################################################################
// Format for API or AP object
export type MVideoBlacklistFormattable = MVideoBlacklist &
Use<'Video', MVideoFormattable>

View file

@ -1,6 +1,6 @@
import { VideoCaptionModel } from '../../../models/video/video-caption' import { VideoCaptionModel } from '../../../models/video/video-caption'
import { PickWith } from '@server/typings/utils' import { FunctionProperties, PickWith } from '@server/typings/utils'
import { VideoModel } from '@server/models/video/video' import { MVideo, MVideoUUID } from '@server/typings/models'
type Use<K extends keyof VideoCaptionModel, M> = PickWith<VideoCaptionModel, K, M> type Use<K extends keyof VideoCaptionModel, M> = PickWith<VideoCaptionModel, K, M>
@ -13,4 +13,12 @@ export type MVideoCaption = Omit<VideoCaptionModel, 'Video'>
export type MVideoCaptionLanguage = Pick<MVideoCaption, 'language'> export type MVideoCaptionLanguage = Pick<MVideoCaption, 'language'>
export type MVideoCaptionVideo = MVideoCaption & export type MVideoCaptionVideo = MVideoCaption &
Use<'Video', Pick<VideoModel, 'id' | 'remote' | 'uuid'>> Use<'Video', Pick<MVideo, 'id' | 'remote' | 'uuid'>>
// ############################################################################
// Format for API or AP object
export type MVideoCaptionFormattable = FunctionProperties<MVideoCaption> &
Pick<MVideoCaption, 'language'> &
Use<'Video', MVideoUUID>

View file

@ -1,6 +1,6 @@
import { VideoChangeOwnershipModel } from '@server/models/video/video-change-ownership' import { VideoChangeOwnershipModel } from '@server/models/video/video-change-ownership'
import { PickWith } from '@server/typings/utils' import { PickWith } from '@server/typings/utils'
import { MAccountDefault, MVideoWithFileThumbnail } from '@server/typings/models' import { MAccountDefault, MAccountFormattable, MVideo, MVideoWithFileThumbnail } from '@server/typings/models'
type Use<K extends keyof VideoChangeOwnershipModel, M> = PickWith<VideoChangeOwnershipModel, K, M> type Use<K extends keyof VideoChangeOwnershipModel, M> = PickWith<VideoChangeOwnershipModel, K, M>
@ -12,3 +12,12 @@ export type MVideoChangeOwnershipFull = MVideoChangeOwnership &
Use<'Initiator', MAccountDefault> & Use<'Initiator', MAccountDefault> &
Use<'NextOwner', MAccountDefault> & Use<'NextOwner', MAccountDefault> &
Use<'Video', MVideoWithFileThumbnail> Use<'Video', MVideoWithFileThumbnail>
// ############################################################################
// Format for API or AP object
export type MVideoChangeOwnershipFormattable = Pick<MVideoChangeOwnership, 'id' | 'status' | 'createdAt'> &
Use<'Initiator', MAccountFormattable> &
Use<'NextOwner', MAccountFormattable> &
Use<'Video', Pick<MVideo, 'id' | 'uuid' | 'url' | 'name'>>

View file

@ -1,19 +1,23 @@
import { PickWith } from '../../utils' import { FunctionProperties, PickWith, PickWithOpt } from '../../utils'
import { VideoChannelModel } from '../../../models/video/video-channel' import { VideoChannelModel } from '../../../models/video/video-channel'
import { import {
MAccountActor, MAccountActor,
MAccountAPI, MAccountAPI,
MAccountDefault, MAccountDefault,
MAccountFormattable,
MAccountLight, MAccountLight,
MAccountSummaryBlocks, MAccountSummaryBlocks,
MAccountSummaryFormattable,
MAccountUserId, MAccountUserId,
MActor, MActor,
MActorAccountChannelId, MActorAccountChannelId,
MActorAPI, MActorAPI,
MActorDefault, MActorDefault,
MActorDefaultLight, MActorDefaultLight,
MActorFormattable,
MActorLight, MActorLight,
MActorSummary MActorSummary,
MActorSummaryFormattable
} from '../account' } from '../account'
import { MVideo } from './video' import { MVideo } from './video'
@ -86,7 +90,8 @@ export type MChannelActorAccountDefaultVideos = MChannel &
// For API // For API
export type MChannelSummary = Pick<MChannel, 'id' | 'name' | 'description' | 'actorId'> & export type MChannelSummary = FunctionProperties<MChannel> &
Pick<MChannel, 'id' | 'name' | 'description' | 'actorId'> &
Use<'Actor', MActorSummary> Use<'Actor', MActorSummary>
export type MChannelSummaryAccount = MChannelSummary & export type MChannelSummaryAccount = MChannelSummary &
@ -95,3 +100,19 @@ export type MChannelSummaryAccount = MChannelSummary &
export type MChannelAPI = MChannel & export type MChannelAPI = MChannel &
Use<'Actor', MActorAPI> & Use<'Actor', MActorAPI> &
Use<'Account', MAccountAPI> Use<'Account', MAccountAPI>
// ############################################################################
// Format for API or AP object
export type MChannelSummaryFormattable = FunctionProperties<MChannel> &
Pick<MChannel, 'id' | 'name'> &
Use<'Actor', MActorSummaryFormattable>
export type MChannelAccountSummaryFormattable = MChannelSummaryFormattable &
Use<'Account', MAccountSummaryFormattable>
export type MChannelFormattable = FunctionProperties<MChannel> &
Pick<MChannel, 'id' | 'name' | 'description' | 'createdAt' | 'updatedAt' | 'support'> &
Use<'Actor', MActorFormattable> &
PickWithOpt<VideoChannelModel, 'Account', MAccountFormattable>

View file

@ -1,6 +1,6 @@
import { VideoCommentModel } from '../../../models/video/video-comment' import { VideoCommentModel } from '../../../models/video/video-comment'
import { PickWith } from '../../utils' import { PickWith } from '../../utils'
import { MAccountDefault } from '../account' import { MAccountDefault, MAccountFormattable } from '../account'
import { MVideoAccountLight, MVideoFeed, MVideoIdUrl } from './video' import { MVideoAccountLight, MVideoFeed, MVideoIdUrl } from './video'
type Use<K extends keyof VideoCommentModel, M> = PickWith<VideoCommentModel, K, M> type Use<K extends keyof VideoCommentModel, M> = PickWith<VideoCommentModel, K, M>
@ -8,6 +8,7 @@ type Use<K extends keyof VideoCommentModel, M> = PickWith<VideoCommentModel, K,
// ############################################################################ // ############################################################################
export type MComment = Omit<VideoCommentModel, 'OriginVideoComment' | 'InReplyToVideoComment' | 'Video' | 'Account'> export type MComment = Omit<VideoCommentModel, 'OriginVideoComment' | 'InReplyToVideoComment' | 'Video' | 'Account'>
export type MCommentTotalReplies = MComment & { totalReplies?: number }
export type MCommentId = Pick<MComment, 'id'> export type MCommentId = Pick<MComment, 'id'>
// ############################################################################ // ############################################################################
@ -41,3 +42,10 @@ export type MCommentOwnerVideoFeed = MCommentOwner &
// ############################################################################ // ############################################################################
export type MCommentAPI = MComment & { totalReplies: number } export type MCommentAPI = MComment & { totalReplies: number }
// ############################################################################
// Format for API or AP object
export type MCommentFormattable = MCommentTotalReplies &
Use<'Account', MAccountFormattable>

View file

@ -1,6 +1,6 @@
import { VideoImportModel } from '@server/models/video/video-import' import { VideoImportModel } from '@server/models/video/video-import'
import { PickWith } from '@server/typings/utils' import { PickWith, PickWithOpt } from '@server/typings/utils'
import { MUser, MVideo, MVideoAccountLight, MVideoTag, MVideoThumbnail, MVideoWithFile } from '@server/typings/models' import { MUser, MVideo, MVideoAccountLight, MVideoFormattable, MVideoTag, MVideoThumbnail, MVideoWithFile } from '@server/typings/models'
type Use<K extends keyof VideoImportModel, M> = PickWith<VideoImportModel, K, M> type Use<K extends keyof VideoImportModel, M> = PickWith<VideoImportModel, K, M>
@ -22,3 +22,10 @@ export type MVideoImportDefault = MVideoImport &
export type MVideoImportDefaultFiles = MVideoImport & export type MVideoImportDefaultFiles = MVideoImport &
Use<'User', MUser> & Use<'User', MUser> &
Use<'Video', VideoAssociation & MVideoWithFile> Use<'Video', VideoAssociation & MVideoWithFile>
// ############################################################################
// Format for API or AP object
export type MVideoImportFormattable = MVideoImport &
PickWithOpt<VideoImportModel, 'Video', MVideoFormattable & MVideoTag>

View file

@ -1,6 +1,6 @@
import { VideoPlaylistElementModel } from '@server/models/video/video-playlist-element' import { VideoPlaylistElementModel } from '@server/models/video/video-playlist-element'
import { PickWith } from '@server/typings/utils' import { PickWith } from '@server/typings/utils'
import { MVideoPlaylistPrivacy, MVideoThumbnail, MVideoUrl } from '@server/typings/models' import { MVideoFormattable, MVideoPlaylistPrivacy, MVideoThumbnail, MVideoUrl } from '@server/typings/models'
type Use<K extends keyof VideoPlaylistElementModel, M> = PickWith<VideoPlaylistElementModel, K, M> type Use<K extends keyof VideoPlaylistElementModel, M> = PickWith<VideoPlaylistElementModel, K, M>
@ -23,6 +23,13 @@ export type MVideoPlaylistVideoThumbnail = MVideoPlaylistElement &
// For API // For API
export type MVideoPlaylistAP = MVideoPlaylistElement & export type MVideoPlaylistElementAP = MVideoPlaylistElement &
Use<'Video', MVideoUrl> & Use<'Video', MVideoUrl> &
Use<'VideoPlaylist', MVideoPlaylistPrivacy> Use<'VideoPlaylist', MVideoPlaylistPrivacy>
// ############################################################################
// Format for API or AP object
export type MVideoPlaylistElementFormattable = MVideoPlaylistElement &
Use<'Video', MVideoFormattable>

View file

@ -1,8 +1,8 @@
import { VideoPlaylistModel } from '../../../models/video/video-playlist' import { VideoPlaylistModel } from '../../../models/video/video-playlist'
import { PickWith } from '../../utils' import { PickWith } from '../../utils'
import { MAccount, MAccountDefault, MAccountSummary } from '../account' import { MAccount, MAccountDefault, MAccountSummary, MAccountSummaryFormattable } from '../account'
import { MThumbnail } from './thumbnail' import { MThumbnail } from './thumbnail'
import { MChannelDefault, MChannelSummary } from './video-channels' import { MChannelDefault, MChannelSummary, MChannelSummaryFormattable } from './video-channels'
import { MVideoPlaylistElementLight } from '@server/typings/models/video/video-playlist-element' import { MVideoPlaylistElementLight } from '@server/typings/models/video/video-playlist-element'
type Use<K extends keyof VideoPlaylistModel, M> = PickWith<VideoPlaylistModel, K, M> type Use<K extends keyof VideoPlaylistModel, M> = PickWith<VideoPlaylistModel, K, M>
@ -16,7 +16,7 @@ export type MVideoPlaylist = Omit<VideoPlaylistModel, 'OwnerAccount' | 'VideoCha
export type MVideoPlaylistId = Pick<MVideoPlaylist, 'id'> export type MVideoPlaylistId = Pick<MVideoPlaylist, 'id'>
export type MVideoPlaylistPrivacy = Pick<MVideoPlaylist, 'privacy'> export type MVideoPlaylistPrivacy = Pick<MVideoPlaylist, 'privacy'>
export type MVideoPlaylistUUID = Pick<MVideoPlaylist, 'uuid'> export type MVideoPlaylistUUID = Pick<MVideoPlaylist, 'uuid'>
export type MVideoPlaylistVideosLength = MVideoPlaylist & { videosLength: number } export type MVideoPlaylistVideosLength = MVideoPlaylist & { videosLength?: number }
// ############################################################################ // ############################################################################
@ -78,3 +78,11 @@ export type MVideoPlaylistFullSummary = MVideoPlaylist &
Use<'Thumbnail', MThumbnail> & Use<'Thumbnail', MThumbnail> &
Use<'OwnerAccount', MAccountSummary> & Use<'OwnerAccount', MAccountSummary> &
Use<'VideoChannel', MChannelSummary> Use<'VideoChannel', MChannelSummary>
// ############################################################################
// Format for API or AP object
export type MVideoPlaylistFormattable = MVideoPlaylistVideosLength &
Use<'OwnerAccount', MAccountSummaryFormattable> &
Use<'VideoChannel', MChannelSummaryFormattable>

View file

@ -1,6 +1,6 @@
import { AccountVideoRateModel } from '@server/models/account/account-video-rate' import { AccountVideoRateModel } from '@server/models/account/account-video-rate'
import { PickWith } from '@server/typings/utils' import { PickWith } from '@server/typings/utils'
import { MAccountAudience, MAccountUrl, MVideo } from '..' import { MAccountAudience, MAccountUrl, MVideo, MVideoFormattable } from '..'
type Use<K extends keyof AccountVideoRateModel, M> = PickWith<AccountVideoRateModel, K, M> type Use<K extends keyof AccountVideoRateModel, M> = PickWith<AccountVideoRateModel, K, M>
@ -14,3 +14,10 @@ export type MAccountVideoRateAccountUrl = MAccountVideoRate &
export type MAccountVideoRateAccountVideo = MAccountVideoRate & export type MAccountVideoRateAccountVideo = MAccountVideoRate &
Use<'Account', MAccountAudience> & Use<'Account', MAccountAudience> &
Use<'Video', MVideo> Use<'Video', MVideo>
// ############################################################################
// Format for API or AP object
export type MAccountVideoRateFormattable = Pick<MAccountVideoRate, 'type'> &
Use<'Video', MVideoFormattable>

View file

@ -1,12 +1,19 @@
import { VideoModel } from '../../../models/video/video' import { VideoModel } from '../../../models/video/video'
import { PickWith, PickWithOpt } from '../../utils' import { PickWith, PickWithOpt } from '../../utils'
import { MChannelAccountDefault, MChannelAccountLight, MChannelActor, MChannelUserId } from './video-channels' import {
MChannelAccountDefault,
MChannelAccountLight,
MChannelAccountSummaryFormattable,
MChannelActor,
MChannelFormattable,
MChannelUserId
} from './video-channels'
import { MTag } from './tag' import { MTag } from './tag'
import { MVideoCaptionLanguage } from './video-caption' import { MVideoCaptionLanguage } from './video-caption'
import { MStreamingPlaylist, MStreamingPlaylistRedundancies } from './video-streaming-playlist' import { MStreamingPlaylist, MStreamingPlaylistRedundancies } from './video-streaming-playlist'
import { MVideoFile, MVideoFileRedundanciesOpt } from './video-file' import { MVideoFile, MVideoFileRedundanciesOpt } from './video-file'
import { MThumbnail } from './thumbnail' import { MThumbnail } from './thumbnail'
import { MVideoBlacklistLight, MVideoBlacklistUnfederated } from './video-blacklist' import { MVideoBlacklist, MVideoBlacklistLight, MVideoBlacklistUnfederated } from './video-blacklist'
import { MScheduleVideoUpdate } from './schedule-video-update' import { MScheduleVideoUpdate } from './schedule-video-update'
import { MUserVideoHistoryTime } from '../user/user-video-history' import { MUserVideoHistoryTime } from '../user/user-video-history'
@ -144,3 +151,19 @@ export type MVideoForUser = MVideo &
Use<'ScheduleVideoUpdate', MScheduleVideoUpdate> & Use<'ScheduleVideoUpdate', MScheduleVideoUpdate> &
Use<'VideoBlacklist', MVideoBlacklistLight> & Use<'VideoBlacklist', MVideoBlacklistLight> &
Use<'Thumbnails', MThumbnail[]> Use<'Thumbnails', MThumbnail[]>
// ############################################################################
// Format for API or AP object
export type MVideoFormattable = MVideo &
PickWithOpt<VideoModel, 'UserVideoHistories', MUserVideoHistoryTime[]> &
Use<'VideoChannel', MChannelAccountSummaryFormattable> &
PickWithOpt<VideoModel, 'ScheduleVideoUpdate', Pick<MScheduleVideoUpdate, 'updateAt' | 'privacy'>> &
PickWithOpt<VideoModel, 'VideoBlacklist', Pick<MVideoBlacklist, 'reason'>>
export type MVideoFormattableDetails = MVideoFormattable &
Use<'VideoChannel', MChannelFormattable> &
Use<'Tags', MTag[]> &
Use<'VideoStreamingPlaylists', MStreamingPlaylistRedundancies[]> &
Use<'VideoFiles', MVideoFileRedundanciesOpt[]>

View file

@ -4,8 +4,6 @@ export type FunctionPropertyNames<T> = {
export type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>> export type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>
export type ValueOf <T, KT extends keyof T> = T[KT]
export type PickWith<T, KT extends keyof T, V> = { export type PickWith<T, KT extends keyof T, V> = {
[P in KT]: T[P] extends V ? V : never [P in KT]: T[P] extends V ? V : never
} }