Type toFormattedJSON
authorChocobozzz <me@florianbigard.com>
Tue, 20 Aug 2019 17:05:31 +0000 (19:05 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 20 Aug 2019 17:23:10 +0000 (19:23 +0200)
54 files changed:
server/controllers/api/users/index.ts
server/controllers/api/users/me.ts
server/controllers/api/video-channel.ts
server/controllers/api/videos/import.ts
server/helpers/captions-utils.ts
server/lib/activitypub/actor.ts
server/lib/user.ts
server/lib/video-channel.ts
server/models/account/account-blocklist.ts
server/models/account/account-video-rate.ts
server/models/account/account.ts
server/models/account/user-notification-setting.ts
server/models/account/user.ts
server/models/activitypub/actor-follow.ts
server/models/activitypub/actor.ts
server/models/avatar/avatar.ts
server/models/server/plugin.ts
server/models/server/server-blocklist.ts
server/models/server/server.ts
server/models/video/schedule-video-update.ts
server/models/video/video-abuse.ts
server/models/video/video-blacklist.ts
server/models/video/video-caption.ts
server/models/video/video-change-ownership.ts
server/models/video/video-channel.ts
server/models/video/video-comment.ts
server/models/video/video-format-utils.ts
server/models/video/video-import.ts
server/models/video/video-playlist-element.ts
server/models/video/video-playlist.ts
server/models/video/video.ts
server/typings/models/account/account-blocklist.ts
server/typings/models/account/account.ts
server/typings/models/account/actor-follow.ts
server/typings/models/account/actor.ts
server/typings/models/account/avatar.ts
server/typings/models/server/plugin.ts
server/typings/models/server/server-blocklist.ts
server/typings/models/server/server.ts
server/typings/models/user/user-notification-setting.ts
server/typings/models/user/user.ts
server/typings/models/video/schedule-video-update.ts
server/typings/models/video/video-abuse.ts
server/typings/models/video/video-blacklist.ts
server/typings/models/video/video-caption.ts
server/typings/models/video/video-change-ownership.ts
server/typings/models/video/video-channels.ts
server/typings/models/video/video-comment.ts
server/typings/models/video/video-import.ts
server/typings/models/video/video-playlist-element.ts
server/typings/models/video/video-playlist.ts
server/typings/models/video/video-rate.ts
server/typings/models/video/video.ts
server/typings/utils.ts

index e6b678f3a6a13076b29e0cba1e369ba8ad27e5d1..27351c1a954b8d68ed648fac005e5462bacc0962 100644 (file)
@@ -196,7 +196,7 @@ async function createUser (req: express.Request, res: express.Response) {
     videoQuota: body.videoQuota,
     videoQuotaDaily: body.videoQuotaDaily,
     adminFlags: body.adminFlags || UserAdminFlag.NONE
-  })
+  }) as MUser
 
   const { user, account } = await createUserAccountAndChannelAndPlaylist({ userToCreate: userToCreate })
 
index af054f6206d90f46c6ee976462d60010d41eb521..78e1e7fa3f4bcfbdea31a00c3cddca567c6ca238 100644 (file)
@@ -23,15 +23,12 @@ import { createReqFiles } from '../../../helpers/express-utils'
 import { UserVideoQuota } from '../../../../shared/models/users/user-video-quota.model'
 import { updateAvatarValidator } from '../../../middlewares/validators/avatar'
 import { updateActorAvatarFile } from '../../../lib/avatar'
-import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger'
 import { VideoImportModel } from '../../../models/video/video-import'
 import { AccountModel } from '../../../models/account/account'
 import { CONFIG } from '../../../initializers/config'
 import { sequelizeTypescript } from '../../../initializers/database'
 import { sendVerifyUserEmail } from '../../../lib/user'
 
-const auditLogger = auditLoggerFactory('users-me')
-
 const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR })
 
 const meRouter = express.Router()
@@ -165,8 +162,6 @@ async function deleteMe (req: express.Request, res: express.Response) {
 
   await user.destroy()
 
-  auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})))
-
   return res.sendStatus(204)
 }
 
@@ -175,7 +170,6 @@ async function updateMe (req: express.Request, res: express.Response) {
   let sendVerificationEmail = false
 
   const user = res.locals.oauth.token.user
-  const oldUserAuditView = new UserAuditView(user.toFormattedJSON({}))
 
   if (body.password !== undefined) user.password = body.password
   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 sendUpdateActor(userAccount, t)
-
-    auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView)
   })
 
   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) {
   const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ]
   const user = res.locals.oauth.token.user
-  const oldUserAuditView = new UserAuditView(user.toFormattedJSON({}))
 
   const userAccount = await AccountModel.load(user.Account.id)
 
   const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount)
 
-  auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView)
-
   return res.json({ avatar: avatar.toFormattedJSON() })
 }
index 2b6184a8319ec8c3403082642dc6fe679459154f..d4ca7a0afd9ca67bf8dd64e112831d9301369451 100644 (file)
@@ -19,7 +19,7 @@ import { VideoChannelModel } from '../../models/video/video-channel'
 import { videoChannelsNameWithHostValidator, videosSortValidator } from '../../middlewares/validators'
 import { sendUpdateActor } from '../../lib/activitypub/send'
 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 { setAsyncActorKeys } from '../../lib/activitypub'
 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 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)
index e7adcc35a2597ebaa1adafb875202135e8ee9827..8879f3442e92d0246602c77206542b8f872f70ca 100644 (file)
@@ -1,6 +1,5 @@
 import * as express from 'express'
 import * as magnetUtil from 'magnet-uri'
-import 'multer'
 import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger'
 import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares'
 import { MIMETYPES } from '../../../initializers/constants'
@@ -28,11 +27,12 @@ import {
   MChannelAccountDefault,
   MThumbnail,
   MUser,
+  MVideoAccountDefault,
   MVideoTag,
   MVideoThumbnailAccountDefault,
   MVideoWithBlacklistLight
 } 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 videoImportsRouter = express.Router()
@@ -238,14 +238,14 @@ function insertIntoDB (parameters: {
   tags: string[],
   videoImportAttributes: Partial<MVideoImport>,
   user: MUser
-}): Bluebird<MVideoImportVideo> {
+}): Bluebird<MVideoImportFormattable> {
   const { video, thumbnailModel, previewModel, videoChannel, tags, videoImportAttributes, user } = parameters
 
   return sequelizeTypescript.transaction(async t => {
     const sequelizeOptions = { transaction: t }
 
     // 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
 
     if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t)
@@ -274,7 +274,7 @@ function insertIntoDB (parameters: {
     const videoImport = await VideoImportModel.create(
       Object.assign({ videoId: videoCreated.id }, videoImportAttributes),
       sequelizeOptions
-    ) as MVideoImportVideo
+    ) as MVideoImportFormattable
     videoImport.Video = videoCreated
 
     return videoImport
index 4f29058e54b5b68f07d8f466c60ee32323202096..2830ae01776a3cef82883f302d2510a32ea26f9e 100644 (file)
@@ -2,9 +2,9 @@ import { join } from 'path'
 import { CONFIG } from '../initializers/config'
 import * as srt2vtt from 'srt-to-vtt'
 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 destination = join(videoCaptionsDir, videoCaption.getCaptionName())
 
index 5201bdeef392a2ed0c948495b56749f2a5f92877..13b73077e8ca6d6e757f09d92ac264fb3f5d97ec 100644 (file)
@@ -38,7 +38,7 @@ import {
 } from '../../typings/models'
 
 // 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()
     .then(({ publicKey, privateKey }) => {
       actor.publicKey = publicKey
@@ -148,7 +148,7 @@ function buildActorInstance (type: ActivityPubActorType, url: string, preferredU
     sharedInboxUrl: WEBSERVER.URL + '/inbox',
     followersUrl: url + '/followers',
     followingUrl: url + '/following'
-  })
+  }) as MActor
 }
 
 async function updateActorInstance (actorInstance: ActorModel, attributes: ActivityPubActor) {
index 266974cacecfd9767b4cb29e1e73708d7b3c1e3b..d84aff464b268684bb63620d13292c2ac1963fa9 100644 (file)
@@ -2,9 +2,8 @@ import * as uuidv4 from 'uuid/v4'
 import { ActivityPubActorType } from '../../shared/models/activitypub'
 import { SERVER_ACTOR_NAME, WEBSERVER } from '../initializers/constants'
 import { AccountModel } from '../models/account/account'
-import { UserModel } from '../models/account/user'
 import { buildActorInstance, getAccountActivityPubUrl, setAsyncActorKeys } from './activitypub'
-import { createVideoChannel } from './video-channel'
+import { createLocalVideoChannel } from './video-channel'
 import { ActorModel } from '../models/activitypub/actor'
 import { UserNotificationSettingModel } from '../models/account/user-notification-setting'
 import { UserNotificationSetting, UserNotificationSettingValue } from '../../shared/models/users'
@@ -13,17 +12,17 @@ import { sequelizeTypescript } from '../initializers/database'
 import { Transaction } from 'sequelize/types'
 import { Redis } from './redis'
 import { Emailer } from './emailer'
-import { MAccountActor, MActor, MChannelActor } from '../typings/models'
-import { MUser, MUserId, MUserNotifSettingAccount } from '../typings/models/user'
+import { MAccountDefault, MActorDefault, MChannelActor } from '../typings/models'
+import { MUser, MUserDefault, MUserId } from '../typings/models/user'
 
 type ChannelNames = { name: string, displayName: string }
 
 async function createUserAccountAndChannelAndPlaylist (parameters: {
-  userToCreate: UserModel,
+  userToCreate: MUser,
   userDisplayName?: string,
   channelNames?: ChannelNames,
   validateUser?: boolean
-}): Promise<{ user: MUserNotifSettingAccount, account: MAccountActor, videoChannel: MChannelActor }> {
+}): Promise<{ user: MUserDefault, account: MAccountDefault, videoChannel: MChannelActor }> {
   const { userToCreate, userDisplayName, channelNames, validateUser = true } = parameters
 
   const { user, account, videoChannel } = await sequelizeTypescript.transaction(async t => {
@@ -32,7 +31,7 @@ async function createUserAccountAndChannelAndPlaylist (parameters: {
       validate: validateUser
     }
 
-    const userCreated: MUserNotifSettingAccount = await userToCreate.save(userOptions)
+    const userCreated: MUserDefault = await userToCreate.save(userOptions)
     userCreated.NotificationSetting = await createDefaultUserNotificationSettings(userCreated, t)
 
     const accountCreated = await createLocalAccountWithoutKeys({
@@ -45,7 +44,7 @@ async function createUserAccountAndChannelAndPlaylist (parameters: {
     userCreated.Account = accountCreated
 
     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)
 
@@ -75,7 +74,7 @@ async function createLocalAccountWithoutKeys (parameters: {
   const url = getAccountActivityPubUrl(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({
     name: displayName || name,
@@ -84,7 +83,7 @@ async function createLocalAccountWithoutKeys (parameters: {
     actorId: actorInstanceCreated.id
   })
 
-  const accountInstanceCreated: MAccountActor = await accountInstance.save({ transaction: t })
+  const accountInstanceCreated: MAccountDefault = await accountInstance.save({ transaction: t })
   accountInstanceCreated.Actor = actorInstanceCreated
 
   return accountInstanceCreated
index ee8eb656825850ae136f125122fd645575e2012b..41eab456bb7491e560c25297be3d443978516ead 100644 (file)
@@ -4,12 +4,12 @@ import { VideoChannelCreate } from '../../shared/models'
 import { VideoChannelModel } from '../models/video/video-channel'
 import { buildActorInstance, federateVideoIfNeeded, getVideoChannelActivityPubUrl } from './activitypub'
 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 }
 
-async function createVideoChannel <T extends MAccountId> (
+async function createLocalVideoChannel <T extends MAccountId> (
   videoChannelInfo: VideoChannelCreate,
   account: T,
   t: Sequelize.Transaction
@@ -31,7 +31,7 @@ async function createVideoChannel <T extends MAccountId> (
   const videoChannel = new VideoChannelModel(videoChannelData)
 
   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
   videoChannelCreated.Account = account
@@ -54,6 +54,6 @@ async function federateAllVideosOfChannel (videoChannel: MChannelId) {
 // ---------------------------------------------------------------------------
 
 export {
-  createVideoChannel,
+  createLocalVideoChannel,
   federateAllVideosOfChannel
 }
index bb537139515c0eeb7727c75436f7d14af9d9df5e..8bcaca8280162c39f51015506c8fd79a37078e6e 100644 (file)
@@ -4,7 +4,7 @@ import { getSort } from '../utils'
 import { AccountBlock } from '../../../shared/models/blocklist'
 import { Op } from 'sequelize'
 import * as Bluebird from 'bluebird'
-import { MAccountBlocklist, MAccountBlocklistAccounts } from '@server/typings/models'
+import { MAccountBlocklist, MAccountBlocklistAccounts, MAccountBlocklistFormattable } from '@server/typings/models'
 
 enum ScopeNames {
   WITH_ACCOUNTS = 'WITH_ACCOUNTS'
@@ -134,7 +134,7 @@ export class AccountBlocklistModel extends Model<AccountBlocklistModel> {
       })
   }
 
-  toFormattedJSON (): AccountBlock {
+  toFormattedJSON (this: MAccountBlocklistFormattable): AccountBlock {
     return {
       byAccount: this.ByAccount.toFormattedJSON(),
       blockedAccount: this.BlockedAccount.toFormattedJSON(),
index 8b62dd05ff9b833a4f0c94ba48853a46564fa670..a6edbeee8b2b8ac8a2d9e48077f9a7de468166fe 100644 (file)
@@ -11,7 +11,12 @@ import { isActivityPubUrlValid } from '../../helpers/custom-validators/activityp
 import { AccountVideoRate } from '../../../shared'
 import { ScopeNames as VideoChannelScopeNames, SummaryOptions, VideoChannelModel } from '../video/video-channel'
 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.
@@ -248,7 +253,7 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
     })
   }
 
-  toFormattedJSON (): AccountVideoRate {
+  toFormattedJSON (this: MAccountVideoRateFormattable): AccountVideoRate {
     return {
       video: this.Video.toFormattedJSON(),
       rating: this.type
index 4cc731075dcb9730c1b968ebc3d88a08a6b8e1ce..8369738b9c87620aef2049820bcec416c32f5ac1 100644 (file)
@@ -32,7 +32,7 @@ import { FindOptions, IncludeOptions, Op, Transaction, WhereOptions } from 'sequ
 import { AccountBlocklistModel } from './account-blocklist'
 import { ServerBlocklistModel } from '../server/server-blocklist'
 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'
 
 export enum ScopeNames {
@@ -353,7 +353,7 @@ export class AccountModel extends Model<AccountModel> {
       .findAll(query)
   }
 
-  toFormattedJSON (): Account {
+  toFormattedJSON (this: MAccountFormattable): Account {
     const actor = this.Actor.toFormattedJSON()
     const account = {
       id: this.id,
@@ -367,8 +367,8 @@ export class AccountModel extends Model<AccountModel> {
     return Object.assign(actor, account)
   }
 
-  toFormattedSummaryJSON (): AccountSummary {
-    const actor = this.Actor.toFormattedJSON()
+  toFormattedSummaryJSON (this: MAccountSummaryFormattable): AccountSummary {
+    const actor = this.Actor.toFormattedSummaryJSON()
 
     return {
       id: this.id,
index c2fbc6d23cc150b673bd9d02d524ef345718529f..1506295cf7f7183ad9e6b2c29fac9bb32e86fd9d 100644 (file)
@@ -17,6 +17,7 @@ import { UserModel } from './user'
 import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
 import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model'
 import { clearCacheByUserId } from '../../lib/oauth-model'
+import { MNotificationSettingFormattable } from '@server/typings/models'
 
 @Table({
   tableName: 'userNotificationSetting',
@@ -152,7 +153,7 @@ export class UserNotificationSettingModel extends Model<UserNotificationSettingM
     return clearCacheByUserId(instance.userId)
   }
 
-  toFormattedJSON (): UserNotificationSetting {
+  toFormattedJSON (this: MNotificationSettingFormattable): UserNotificationSetting {
     return {
       newCommentOnMyVideo: this.newCommentOnMyVideo,
       newVideoFromSubscription: this.newVideoFromSubscription,
index cb54d79af35dd1547f3ff72277887695c66da0d4..616dd603ce8358e7faa04502f6ac1f79642a8e3b 100644 (file)
@@ -55,7 +55,13 @@ import { UserAdminFlag } from '../../../shared/models/users/user-flag.model'
 import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
 import { getThemeOrDefault } from '../../lib/plugins/theme-utils'
 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 {
   WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL'
@@ -554,7 +560,9 @@ export class UserModel extends Model<UserModel> {
     return comparePassword(password, this.password)
   }
 
-  toFormattedJSON (parameters: { withAdminFlags?: boolean } = {}): User {
+  toSummaryJSON
+
+  toFormattedJSON (this: MUserFormattable, parameters: { withAdminFlags?: boolean } = {}): User {
     const videoQuotaUsed = this.get('videoQuotaUsed')
     const videoQuotaUsedDaily = this.get('videoQuotaUsedDaily')
 
index 8ef770cd4933d92eb7b11d8a7d6c313a2cbf982d..c8b3aae9f2d559c2653d4a20f0a6fb95f193b127 100644 (file)
@@ -32,6 +32,7 @@ import {
   MActorFollowActorsDefault,
   MActorFollowActorsDefaultSubscription,
   MActorFollowFollowingHost,
+  MActorFollowFormattable,
   MActorFollowSubscriptions
 } from '@server/typings/models'
 
@@ -580,7 +581,7 @@ export class ActorFollowModel extends Model<ActorFollowModel> {
     return ActorFollowModel.findAll(query)
   }
 
-  toFormattedJSON (): ActorFollow {
+  toFormattedJSON (this: MActorFollowFormattable): ActorFollow {
     const follower = this.ActorFollower.toFormattedJSON()
     const following = this.ActorFollowing.toFormattedJSON()
 
index 2312127b42108985d52c5441bb8406f7a8a19488..e2213afa17401c224b9d8bcc0405b4517c1cc259 100644 (file)
@@ -36,7 +36,16 @@ import { isOutdated, throwIfNotValid } from '../utils'
 import { VideoChannelModel } from '../video/video-channel'
 import { ActorFollowModel } from './actor-follow'
 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'
 
 enum ScopeNames {
@@ -393,24 +402,31 @@ export class ActorModel extends Model<ActorModel> {
     })
   }
 
-  toFormattedJSON () {
+  toFormattedSummaryJSON (this: MActorSummaryFormattable) {
     let avatar: Avatar = null
     if (this.Avatar) {
       avatar = this.Avatar.toFormattedJSON()
     }
 
     return {
-      id: this.id,
       url: this.url,
       name: this.preferredUsername,
       host: this.getHost(),
+      avatar
+    }
+  }
+
+  toFormattedJSON (this: MActorFormattable) {
+    const base = this.toFormattedSummaryJSON()
+
+    return Object.assign(base, {
+      id: this.id,
       hostRedundancyAllowed: this.getRedundancyAllowed(),
       followingCount: this.followingCount,
       followersCount: this.followersCount,
-      avatar,
       createdAt: this.createdAt,
       updatedAt: this.updatedAt
-    }
+    })
   }
 
   toActivityPubObject (name: string, type: 'Account' | 'Application' | 'VideoChannel') {
@@ -500,7 +516,7 @@ export class ActorModel extends Model<ActorModel> {
     return this.serverId === null
   }
 
-  getWebfingerUrl () {
+  getWebfingerUrl (this: MActorServer) {
     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
   }
 
-  getHost () {
+  getHost (this: MActorHost) {
     return this.Server ? this.Server.host : WEBSERVER.HOST
   }
 
-  getRedundancyAllowed () {
+  getRedundancyAllowed (this: MActorRedundancyAllowed) {
     return this.Server ? this.Server.redundancyAllowed : false
   }
 
index b4014459297fdffff140c7116b19cfcdd3b6fc5a..950e4b181464626a68b8058e8b4f28a9d7db94ee 100644 (file)
@@ -7,6 +7,7 @@ import { remove } from 'fs-extra'
 import { CONFIG } from '../../initializers/config'
 import { throwIfNotValid } from '../utils'
 import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
+import { MAvatarFormattable } from '@server/typings/models'
 
 @Table({
   tableName: 'avatar',
@@ -57,7 +58,7 @@ export class AvatarModel extends Model<AvatarModel> {
     return AvatarModel.findOne(query)
   }
 
-  toFormattedJSON (): Avatar {
+  toFormattedJSON (this: MAvatarFormattable): Avatar {
     return {
       path: this.getStaticPath(),
       createdAt: this.createdAt,
index debd25ea199d276793e84da7835729f7158e74fb..d094da1f560084b9d51d39e93364941d92a0e823 100644 (file)
@@ -12,7 +12,7 @@ import { PeerTubePlugin } from '../../../shared/models/plugins/peertube-plugin.m
 import { FindAndCountOptions, json } from 'sequelize'
 import { RegisterServerSettingOptions } from '../../../shared/models/plugins/register-server-setting.model'
 import * as Bluebird from 'bluebird'
-import { MPlugin } from '@server/typings/models'
+import { MPlugin, MPluginFormattable } from '@server/typings/models'
 
 @DefaultScope(() => ({
   attributes: {
@@ -253,7 +253,7 @@ export class PluginModel extends Model<PluginModel> {
     return result
   }
 
-  toFormattedJSON (): PeerTubePlugin {
+  toFormattedJSON (this: MPluginFormattable): PeerTubePlugin {
     return {
       name: this.name,
       type: this.type,
index e4db93dfc53d71016cd21c1796424d44b15cf0e7..3e96871911f6215b9f613d776056811e58d45a9e 100644 (file)
@@ -4,7 +4,7 @@ import { ServerModel } from './server'
 import { ServerBlock } from '../../../shared/models/blocklist'
 import { getSort } from '../utils'
 import * as Bluebird from 'bluebird'
-import { MServerBlocklist, MServerBlocklistAccountServer } from '@server/typings/models'
+import { MServerBlocklist, MServerBlocklistAccountServer, MServerBlocklistFormattable } from '@server/typings/models'
 
 enum ScopeNames {
   WITH_ACCOUNT = 'WITH_ACCOUNT',
@@ -112,7 +112,7 @@ export class ServerBlocklistModel extends Model<ServerBlocklistModel> {
       })
   }
 
-  toFormattedJSON (): ServerBlock {
+  toFormattedJSON (this: MServerBlocklistFormattable): ServerBlock {
     return {
       byAccount: this.ByAccount.toFormattedJSON(),
       blockedServer: this.BlockedServer.toFormattedJSON(),
index b0bdd2b0bcb4316e38b08d8fca33175b35ad80a1..3b6759b5c44609e5b65b3413db46f789058e0242 100644 (file)
@@ -4,7 +4,7 @@ import { ActorModel } from '../activitypub/actor'
 import { throwIfNotValid } from '../utils'
 import { ServerBlocklistModel } from './server-blocklist'
 import * as Bluebird from 'bluebird'
-import { MServer } from '@server/typings/models/server'
+import { MServer, MServerFormattable } from '@server/typings/models/server'
 
 @Table({
   tableName: 'server',
@@ -65,7 +65,7 @@ export class ServerModel extends Model<ServerModel> {
     return this.BlockedByAccounts && this.BlockedByAccounts.length !== 0
   }
 
-  toFormattedJSON () {
+  toFormattedJSON (this: MServerFormattable) {
     return {
       host: this.host
     }
index 603d556924c7e4f59845963175b4662288758502..fc2a424aaaa56f3c5ab0c0120d462a4bf3078ef4 100644 (file)
@@ -2,6 +2,7 @@ import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Model, Ta
 import { ScopeNames as VideoScopeNames, VideoModel } from './video'
 import { VideoPrivacy } from '../../../shared/models/videos'
 import { Op, Transaction } from 'sequelize'
+import { MScheduleVideoUpdateFormattable } from '@server/typings/models'
 
 @Table({
   tableName: 'scheduleVideoUpdate',
@@ -96,7 +97,7 @@ export class ScheduleVideoUpdateModel extends Model<ScheduleVideoUpdateModel> {
     return ScheduleVideoUpdateModel.destroy(query)
   }
 
-  toFormattedJSON () {
+  toFormattedJSON (this: MScheduleVideoUpdateFormattable) {
     return {
       updateAt: this.updateAt,
       privacy: this.privacy || undefined
index af7b40d11f9ed215390b1654561ccb97d064314c..6ef1a915d85c9a4b5d5649949e8c3e1dd2f57200 100644 (file)
@@ -11,7 +11,7 @@ import { getSort, throwIfNotValid } from '../utils'
 import { VideoModel } from './video'
 import { VideoAbuseState } from '../../../shared'
 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'
 
 @Table({
@@ -108,7 +108,7 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> {
       })
   }
 
-  toFormattedJSON (this: MVideoAbuseAccountVideo): VideoAbuse {
+  toFormattedJSON (this: MVideoAbuseFormattable): VideoAbuse {
     return {
       id: this.id,
       reason: this.reason,
index 5a0cac94a663a667654044a13b198e5baec85ae3..b4df6cd6a3707d15bc026bc962cd82c6e68f3441 100644 (file)
@@ -8,7 +8,7 @@ import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
 import { FindOptions } from 'sequelize'
 import { ThumbnailModel } from './thumbnail'
 import * as Bluebird from 'bluebird'
-import { MVideoBlacklist } from '@server/typings/models'
+import { MVideoBlacklist, MVideoBlacklistFormattable } from '@server/typings/models'
 
 @Table({
   tableName: 'videoBlacklist',
@@ -111,7 +111,7 @@ export class VideoBlacklistModel extends Model<VideoBlacklistModel> {
     return VideoBlacklistModel.findOne(query)
   }
 
-  toFormattedJSON (): VideoBlacklist {
+  toFormattedJSON (this: MVideoBlacklistFormattable): VideoBlacklist {
     return {
       id: this.id,
       createdAt: this.createdAt,
index 9ce350d1280c4799062abd44b87ecfae6b0179ae..ad580176857b3727a0f1a00c0f81fe6a1db89d2c 100644 (file)
@@ -22,7 +22,7 @@ import { logger } from '../../helpers/logger'
 import { remove } from 'fs-extra'
 import { CONFIG } from '../../initializers/config'
 import * as Bluebird from 'bluebird'
-import { MVideoCaptionVideo } from '@server/typings/models'
+import { MVideoCaptionFormattable, MVideoCaptionVideo } from '@server/typings/models'
 
 export enum ScopeNames {
   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
   }
 
-  toFormattedJSON (): VideoCaption {
+  toFormattedJSON (this: MVideoCaptionFormattable): VideoCaption {
     return {
       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())
   }
 
-  getCaptionName () {
+  getCaptionName (this: MVideoCaptionFormattable) {
     return `${this.Video.uuid}-${this.language}.vtt`
   }
 
-  removeCaptionFile () {
+  removeCaptionFile (this: MVideoCaptionFormattable) {
     return remove(CONFIG.STORAGE.CAPTIONS_DIR + this.getCaptionName())
   }
 }
index 2d0ff48fb212e608fac91f4e729dd17b084e4794..f7a351329bc7ab7999be91260e2ce713a2703b10 100644 (file)
@@ -3,7 +3,7 @@ import { AccountModel } from '../account/account'
 import { ScopeNames as VideoScopeNames, VideoModel } from './video'
 import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos'
 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'
 
 enum ScopeNames {
@@ -119,7 +119,7 @@ export class VideoChangeOwnershipModel extends Model<VideoChangeOwnershipModel>
                                     .findByPk(id)
   }
 
-  toFormattedJSON (): VideoChangeOwnership {
+  toFormattedJSON (this: MVideoChangeOwnershipFormattable): VideoChangeOwnership {
     return {
       id: this.id,
       status: this.status,
index b6a60827fa115c204b34f19754e1dde01f4f08aa..7a4df516aa55b388e5b9a610431e9475a7c41451 100644 (file)
@@ -37,7 +37,7 @@ import * as Bluebird from 'bluebird'
 import {
   MChannelAccountDefault,
   MChannelActor,
-  MChannelActorAccountDefaultVideos
+  MChannelActorAccountDefaultVideos, MChannelSummaryFormattable, MChannelFormattable
 } from '../../typings/models/video'
 
 // 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)
   }
 
-  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 videoChannel = {
       id: this.id,
@@ -500,19 +513,6 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
     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 {
     const obj = this.Actor.toActivityPubObject(this.name, 'VideoChannel')
 
index c88dac1c19bb393a69e35b1012f873ec59ee10af..84d71c553db89cd9aae7d1b57f057348eb771fc6 100644 (file)
@@ -17,6 +17,7 @@ import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'se
 import * as Bluebird from 'bluebird'
 import {
   MComment,
+  MCommentFormattable,
   MCommentId,
   MCommentOwner,
   MCommentOwnerReplyVideoLight,
@@ -475,7 +476,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
     return uniq(result)
   }
 
-  toFormattedJSON () {
+  toFormattedJSON (this: MCommentFormattable) {
     return {
       id: this.id,
       url: this.url,
index 4e7eb5f0c7cbb8225ab0f92dd9ed9afcf029b5a2..6aa7c1e3ea0728c17ffee8ad4f659b727100190c 100644 (file)
@@ -16,7 +16,7 @@ import {
 } from '../../lib/activitypub'
 import { isArray } from '../../helpers/custom-validators/misc'
 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 { MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file'
 
@@ -29,7 +29,7 @@ export type VideoFormattingJSONOptions = {
     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 videoObject: Video = {
@@ -103,7 +103,7 @@ function videoModelToFormattedJSON (video: VideoModel, options?: VideoFormatting
   return videoObject
 }
 
-function videoModelToFormattedDetailsJSON (video: MVideoDetails): VideoDetails {
+function videoModelToFormattedDetailsJSON (video: MVideoFormattableDetails): VideoDetails {
   const formattedJson = video.toFormattedJSON({
     additionalAttributes: {
       scheduledUpdate: true,
index f596eea9d259f1a256b6c1d9d14f81fb543df0d2..af5314ce9be806fb7be7bbfbbf50f2224189b898 100644 (file)
@@ -21,7 +21,7 @@ import { VideoImport, VideoImportState } from '../../../shared'
 import { isVideoMagnetUriValid } from '../../helpers/custom-validators/videos'
 import { UserModel } from '../account/user'
 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(() => ({
   include: [
@@ -154,7 +154,7 @@ export class VideoImportModel extends Model<VideoImportModel> {
     return this.targetUrl || this.magnetUri || this.torrentName
   }
 
-  toFormattedJSON (): VideoImport {
+  toFormattedJSON (this: MVideoImportFormattable): VideoImport {
     const videoFormatOptions = {
       completeDescription: true,
       additionalAttributes: { state: true, waitTranscoding: true, scheduledUpdate: true }
index 90111316199fa103a32654f18b211dd7659c8dca..80ca22a18fdaad77abefb5a4ed1da0b51c3f3f6a 100644 (file)
@@ -21,12 +21,16 @@ import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
 import { PlaylistElementObject } from '../../../shared/models/activitypub/objects/playlist-element-object'
 import * as validator from 'validator'
 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 { AccountModel } from '../account/account'
 import { VideoPrivacy } from '../../../shared/models/videos'
 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'
 
 @Table({
@@ -180,7 +184,7 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel>
     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 videoWhere = validator.isUUID('' + videoId) ? { uuid: videoId } : { id: videoId }
 
@@ -293,7 +297,7 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel>
     return VideoPlaylistElementModel.increment({ position: by }, query)
   }
 
-  getType (displayNSFW?: boolean, accountId?: number) {
+  getType (this: MVideoPlaylistElementFormattable, displayNSFW?: boolean, accountId?: number) {
     const video = this.Video
 
     if (!video) return VideoPlaylistElementType.DELETED
@@ -309,14 +313,17 @@ export class VideoPlaylistElementModel extends Model<VideoPlaylistElementModel>
     return VideoPlaylistElementType.REGULAR
   }
 
-  getVideoElement (displayNSFW?: boolean, accountId?: number) {
+  getVideoElement (this: MVideoPlaylistElementFormattable, displayNSFW?: boolean, accountId?: number) {
     if (!this.Video) return null
     if (this.getType(displayNSFW, accountId) !== VideoPlaylistElementType.REGULAR) return null
 
     return this.Video.toFormattedJSON()
   }
 
-  toFormattedJSON (options: { displayNSFW?: boolean, accountId?: number } = {}): VideoPlaylistElement {
+  toFormattedJSON (
+    this: MVideoPlaylistElementFormattable,
+    options: { displayNSFW?: boolean, accountId?: number } = {}
+  ): VideoPlaylistElement {
     return {
       id: this.id,
       position: this.position,
index 9f1d03ac5e7f8f8744433db9cbf5d7c0f7e32499..80dd653229069a148a9ab836389bb88ec253c56e 100644 (file)
@@ -46,6 +46,7 @@ import { FindOptions, literal, Op, ScopeOptions, Transaction, WhereOptions } fro
 import * as Bluebird from 'bluebird'
 import {
   MVideoPlaylistAccountThumbnail,
+  MVideoPlaylistFormattable,
   MVideoPlaylistFull,
   MVideoPlaylistFullSummary,
   MVideoPlaylistIdWithElements
@@ -479,7 +480,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
     return isOutdated(this, ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL)
   }
 
-  toFormattedJSON (): VideoPlaylist {
+  toFormattedJSON (this: MVideoPlaylistFormattable): VideoPlaylist {
     return {
       id: this.id,
       uuid: this.uuid,
index e62bde344f15182a884641d6c188711265e3bc24..9c24d1ba8804dfb7437f88d2554f550858d30eec 100644 (file)
@@ -132,8 +132,9 @@ import {
   MVideoFullLight,
   MVideoIdThumbnail,
   MVideoThumbnail,
-  MVideoWithAllFiles,
-  MVideoWithRights
+  MVideoWithAllFiles, MVideoWithFile,
+  MVideoWithRights,
+  MVideoFormattable
 } from '../../typings/models'
 import { MVideoFile, MVideoFileRedundanciesOpt } from '../../typings/models/video/video-file'
 import { MThumbnail } from '../../typings/models/video/thumbnail'
@@ -1765,14 +1766,14 @@ export class VideoModel extends Model<VideoModel> {
       this.VideoChannel.Account.isBlocked()
   }
 
-  getOriginalFile () {
+  getOriginalFile <T extends MVideoWithFile> (this: T) {
     if (Array.isArray(this.VideoFiles) === false) return undefined
 
     // The original file is the file that have the higher 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
 
     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)
   }
 
-  toFormattedJSON (options?: VideoFormattingJSONOptions): Video {
+  toFormattedJSON <T extends MVideoFormattable> (this: T, options?: VideoFormattingJSONOptions): Video {
     return videoModelToFormattedJSON(this, options)
   }
 
index d20d97aa8f774e07a497414ffa759a3073ca36ab..c9cb553325ceb063f03fb0d2db6928b588b3805e 100644 (file)
@@ -1,6 +1,6 @@
 import { AccountBlocklistModel } from '../../../models/account/account-blocklist'
 import { PickWith } from '../../utils'
-import { MAccountDefault } from './account'
+import { MAccountDefault, MAccountFormattable } from './account'
 
 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 &
   Use<'ByAccount', MAccountDefault> &
   Use<'BlockedAccount', MAccountDefault>
+
+// ############################################################################
+
+// Format for API or AP object
+
+export type MAccountBlocklistFormattable = Pick<MAccountBlocklist, 'createdAt'> &
+  Use<'ByAccount', MAccountFormattable> &
+  Use<'BlockedAccount', MAccountFormattable>
index 9a8784e6bcd56b233d8ad61ead208c1bd0624d49..33940517eafb54ad6afc81be04da29c837c3c39a 100644 (file)
@@ -9,9 +9,11 @@ import {
   MActorId,
   MActorServer,
   MActorSummary,
-  MActorUrl
+  MActorSummaryFormattable,
+  MActorUrl,
+  MActorFormattable
 } from './actor'
-import { PickWith } from '../../utils'
+import { FunctionProperties, PickWith } from '../../utils'
 import { MAccountBlocklistId } from './account-blocklist'
 import { MChannelDefault } from '@server/typings/models'
 
@@ -67,7 +69,8 @@ export type MAccountServer = MAccount &
 
 // For API
 
-export type MAccountSummary = Pick<MAccount, 'id' | 'name'> &
+export type MAccountSummary = FunctionProperties<MAccount> &
+  Pick<MAccount, 'id' | 'name'> &
   Use<'Actor', MActorSummary>
 
 export type MAccountSummaryBlocks = MAccountSummary &
@@ -75,3 +78,15 @@ export type MAccountSummaryBlocks = MAccountSummary &
 
 export type MAccountAPI = MAccount &
   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>
index 87050ac63ff7d7d148bf2425cd35d2ebc8d99427..17a47b8df781246c9c8d35af95e6981dacf33d47 100644 (file)
@@ -3,14 +3,15 @@ import {
   MActor,
   MActorAccount,
   MActorAccountChannel,
-  MActorChannel,
   MActorChannelAccountActor,
   MActorDefault,
+  MActorFormattable,
   MActorHost,
   MActorUsername
 } from './actor'
 import { PickWith } from '../../utils'
 import { ActorModel } from '@server/models/activitypub/actor'
+import { MChannelDefault } from '@server/typings/models'
 
 type Use<K extends keyof ActorFollowModel, M> = PickWith<ActorFollowModel, K, M>
 
@@ -43,9 +44,12 @@ export type MActorFollowFull = MActorFollow &
 
 // For subscriptions
 
+type SubscriptionFollowing = MActorDefault &
+  PickWith<ActorModel, 'VideoChannel', MChannelDefault>
+
 export type MActorFollowActorsDefaultSubscription = MActorFollow &
   Use<'ActorFollower', MActorDefault> &
-  Use<'ActorFollowing', MActorDefault & MActorChannel>
+  Use<'ActorFollowing', SubscriptionFollowing>
 
 export type MActorFollowFollowingFullFollowerAccount = MActorFollow &
   Use<'ActorFollower', MActorAccount> &
@@ -53,3 +57,11 @@ export type MActorFollowFollowingFullFollowerAccount = MActorFollow &
 
 export type MActorFollowSubscriptions = MActorFollow &
   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>
index 7d99a433b34ed26751571fbd4033329dbceefbec..14ab2cd5b13ce9897ea0c69d053004a7f5dcd9b0 100644 (file)
@@ -1,8 +1,8 @@
 import { ActorModel } from '../../../models/activitypub/actor'
-import { PickWith } from '../../utils'
+import { FunctionProperties, PickWith } from '../../utils'
 import { MAccount, MAccountDefault, MAccountId, MAccountIdActor } from './account'
-import { MServer, MServerHost, MServerHostBlocks } from '../server'
-import { MAvatar } from './avatar'
+import { MServer, MServerHost, MServerHostBlocks, MServerRedundancyAllowed } from '../server'
+import { MAvatar, MAvatarFormattable } from './avatar'
 import { MChannel, MChannelAccountActor, MChannelAccountDefault, MChannelId, MChannelIdActor } from '../video'
 
 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
 
 export type MActorHost = Use<'Server', MServerHost>
+export type MActorRedundancyAllowed = Use<'Server', MServerRedundancyAllowed>
 
 export type MActorDefaultLight = MActorLight &
   Use<'Server', MServerHost> &
@@ -92,7 +93,8 @@ export type MActorFullActor = MActor &
 
 // 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<'Avatar', MAvatar>
 
@@ -101,3 +103,16 @@ export type MActorSummaryBlocks = MActorSummary &
 
 export type MActorAPI = Omit<MActorDefault, 'publicKey' | 'privateKey' | 'inboxUrl' | 'outboxUrl' | 'sharedInboxUrl' |
   '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>
index 257c48bfc68f7020155b7a21f0579501fc47b054..8af6cc787768b170d1dfa047c4ceaa7fdb3b2cff 100644 (file)
@@ -1,3 +1,11 @@
 import { AvatarModel } from '../../../models/avatar/avatar'
+import { FunctionProperties } from '@server/typings/utils'
 
 export type MAvatar = AvatarModel
+
+// ############################################################################
+
+// Format for API or AP object
+
+export type MAvatarFormattable = FunctionProperties<MAvatar> &
+  Pick<MAvatar, 'filename' | 'createdAt' | 'updatedAt'>
index b1e2e149d33eef9de53e709a8bc657a43e240a13..94674c318b78e023da6de437c235eb4ec7d6d3e1 100644 (file)
@@ -1,3 +1,10 @@
 import { PluginModel } from '@server/models/server/plugin'
 
 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'>
index 0ca00b5c2d69bfd30a89bbab75edc28146f9b608..c81f604f5be00d1eb93d9c14107e7edcb816f6db 100644 (file)
@@ -1,6 +1,6 @@
 import { ServerBlocklistModel } from '@server/models/server/server-blocklist'
 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>
 
@@ -13,3 +13,11 @@ export type MServerBlocklist = Omit<ServerBlocklistModel, 'ByAccount' | 'Blocked
 export type MServerBlocklistAccountServer = MServerBlocklist &
   Use<'ByAccount', MAccountDefault> &
   Use<'BlockedServer', MServer>
+
+// ############################################################################
+
+// Format for API or AP object
+
+export type MServerBlocklistFormattable = Pick<MServerBlocklist, 'createdAt'> &
+  Use<'ByAccount', MAccountFormattable> &
+  Use<'BlockedServer', MServerFormattable>
index c059cff792e154b46c413dda0ab75979b9c60e9d..190cc0c289082cec5b76a33033c928b1a9b39151 100644 (file)
@@ -1,5 +1,5 @@
 import { ServerModel } from '../../../models/server/server'
-import { PickWith } from '../../utils'
+import { FunctionProperties, PickWith } from '../../utils'
 import { MAccountBlocklistId } from '../account'
 
 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 MServerRedundancyAllowed = Pick<MServer, 'redundancyAllowed'>
 
 export type MServerHostBlocks = MServerHost &
   Use<'BlockedByAccounts', MAccountBlocklistId[]>
+
+// ############################################################################
+
+// Format for API or AP object
+
+export type MServerFormattable = FunctionProperties<MServer> &
+  Pick<MServer, 'host'>
index 585d30a66887b4fe638d055d17df134b6df63822..c674add1b72a604d27d23f6c72aed11ec74be113 100644 (file)
@@ -1,3 +1,9 @@
 import { UserNotificationSettingModel } from '@server/models/account/user-notification-setting'
 
 export type MNotificationSetting = Omit<UserNotificationSettingModel, 'User'>
+
+// ############################################################################
+
+// Format for API or AP object
+
+export type MNotificationSettingFormattable = MNotificationSetting
index 466cde33b890bf41525eeffe67190bf3fe37f4f1..52d6d4a057f191ffde59366cb95c2fbc6813c0ec 100644 (file)
@@ -1,7 +1,17 @@
 import { UserModel } from '../../../models/account/user'
-import { PickWith } from '../../utils'
-import { MAccount, MAccountDefault, MAccountDefaultChannelDefault, MAccountId, MAccountIdActorId, MAccountUrl } from '../account'
-import { MNotificationSetting } from './user-notification-setting'
+import { PickWith, PickWithOpt } from '../../utils'
+import {
+  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>
 
@@ -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'>
 
 // ############################################################################
@@ -49,3 +60,11 @@ export type MUserNotifSettingAccount = MUser &
 export type MUserDefault = MUser &
   Use<'NotificationSetting', MNotificationSetting> &
   Use<'Account', MAccountDefault>
+
+// ############################################################################
+
+// Format for API or AP object
+
+export type MUserFormattable = MUserQuotaUsed &
+  Use<'Account', MAccountFormattable & PickWithOpt<AccountModel, 'VideoChannels', MChannelFormattable[]>> &
+  PickWithOpt<UserModel, 'NotificationSetting', MNotificationSettingFormattable>
index 069705536b266f6e95a7dc31383c3ea266ac6001..ada9af06e8569462e5d693e7708b830c8d3df055 100644 (file)
@@ -1,3 +1,9 @@
 import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update'
 
 export type MScheduleVideoUpdate = Omit<ScheduleVideoUpdateModel, 'Video'>
+
+// ############################################################################
+
+// Format for API or AP object
+
+export type MScheduleVideoUpdateFormattable = Pick<MScheduleVideoUpdate, 'updateAt' | 'privacy'>
index 0474cac5b46d6bb69d75d88659b244630a27180c..e38c3f58600585e7af33d7a363d42101e313e6e4 100644 (file)
@@ -1,7 +1,7 @@
 import { VideoAbuseModel } from '../../../models/video/video-abuse'
 import { PickWith } from '../../utils'
 import { MVideo } from './video'
-import { MAccountDefault } from '../account'
+import { MAccountDefault, MAccountFormattable } from '../account'
 
 type Use<K extends keyof VideoAbuseModel, M> = PickWith<VideoAbuseModel, K, M>
 
@@ -21,3 +21,11 @@ export type MVideoAbuseAccountVideo = MVideoAbuse &
   Pick<VideoAbuseModel, 'toActivityPubObject'> &
   Use<'Video', MVideo> &
   Use<'Account', MAccountDefault>
+
+// ############################################################################
+
+// Format for API or AP object
+
+export type MVideoAbuseFormattable = MVideoAbuse &
+  Use<'Account', MAccountFormattable> &
+  Use<'Video', Pick<MVideo, 'id' | 'uuid' | 'name'>>
index cc539f95cff4b21007f084aa4ff8af826aa9623b..1dedfa37f79e787d5f9fe89b41942576aa10b202 100644 (file)
@@ -1,6 +1,6 @@
 import { VideoBlacklistModel } from '../../../models/video/video-blacklist'
 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>
 
@@ -15,3 +15,10 @@ export type MVideoBlacklistUnfederated = Pick<MVideoBlacklist, 'unfederated'>
 
 export type MVideoBlacklistVideo = MVideoBlacklist &
   Use<'Video', MVideo>
+
+// ############################################################################
+
+// Format for API or AP object
+
+export type MVideoBlacklistFormattable = MVideoBlacklist &
+  Use<'Video', MVideoFormattable>
index fe0e664c2a7ea2247cb60210f50e2b37c12c4d7e..7cb2a2ad32abfad899337f90ce0056174b72b484 100644 (file)
@@ -1,6 +1,6 @@
 import { VideoCaptionModel } from '../../../models/video/video-caption'
-import { PickWith } from '@server/typings/utils'
-import { VideoModel } from '@server/models/video/video'
+import { FunctionProperties, PickWith } from '@server/typings/utils'
+import { MVideo, MVideoUUID } from '@server/typings/models'
 
 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 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>
index 0410115c6b22189c630964fece6f930bbfab76a2..72634cdb2a38ac579e7646c87b708317262a67ef 100644 (file)
@@ -1,6 +1,6 @@
 import { VideoChangeOwnershipModel } from '@server/models/video/video-change-ownership'
 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>
 
@@ -12,3 +12,12 @@ export type MVideoChangeOwnershipFull = MVideoChangeOwnership &
   Use<'Initiator', MAccountDefault> &
   Use<'NextOwner', MAccountDefault> &
   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'>>
index b6506ed9f6bf83c438332c178a7701f377964e42..2be7dd7ed01cbfbbf610a9aeeecba05de0583f3c 100644 (file)
@@ -1,19 +1,23 @@
-import { PickWith } from '../../utils'
+import { FunctionProperties, PickWith, PickWithOpt } from '../../utils'
 import { VideoChannelModel } from '../../../models/video/video-channel'
 import {
   MAccountActor,
   MAccountAPI,
   MAccountDefault,
+  MAccountFormattable,
   MAccountLight,
   MAccountSummaryBlocks,
+  MAccountSummaryFormattable,
   MAccountUserId,
   MActor,
   MActorAccountChannelId,
   MActorAPI,
   MActorDefault,
   MActorDefaultLight,
+  MActorFormattable,
   MActorLight,
-  MActorSummary
+  MActorSummary,
+  MActorSummaryFormattable
 } from '../account'
 import { MVideo } from './video'
 
@@ -86,7 +90,8 @@ export type MChannelActorAccountDefaultVideos = MChannel &
 
 // 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>
 
 export type MChannelSummaryAccount = MChannelSummary &
@@ -95,3 +100,19 @@ export type MChannelSummaryAccount = MChannelSummary &
 export type MChannelAPI = MChannel &
   Use<'Actor', MActorAPI> &
   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>
index 187461213e7d7fd0cdbdedfa65ab74a25a961afe..e8bccba0f097a89cbe6f8af9174456a5d8c1d965 100644 (file)
@@ -1,6 +1,6 @@
 import { VideoCommentModel } from '../../../models/video/video-comment'
 import { PickWith } from '../../utils'
-import { MAccountDefault } from '../account'
+import { MAccountDefault, MAccountFormattable } from '../account'
 import { MVideoAccountLight, MVideoFeed, MVideoIdUrl } from './video'
 
 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 MCommentTotalReplies = MComment & { totalReplies?: number }
 export type MCommentId = Pick<MComment, 'id'>
 
 // ############################################################################
@@ -41,3 +42,10 @@ export type MCommentOwnerVideoFeed = MCommentOwner &
 // ############################################################################
 
 export type MCommentAPI = MComment & { totalReplies: number }
+
+// ############################################################################
+
+// Format for API or AP object
+
+export type MCommentFormattable = MCommentTotalReplies &
+  Use<'Account', MAccountFormattable>
index ada7237134c14502f149ac56660ea7f2f58043a4..c6a1c5b66723229b5c514213c4558b078d936323 100644 (file)
@@ -1,6 +1,6 @@
 import { VideoImportModel } from '@server/models/video/video-import'
-import { PickWith } from '@server/typings/utils'
-import { MUser, MVideo, MVideoAccountLight, MVideoTag, MVideoThumbnail, MVideoWithFile } from '@server/typings/models'
+import { PickWith, PickWithOpt } from '@server/typings/utils'
+import { MUser, MVideo, MVideoAccountLight, MVideoFormattable, MVideoTag, MVideoThumbnail, MVideoWithFile } from '@server/typings/models'
 
 type Use<K extends keyof VideoImportModel, M> = PickWith<VideoImportModel, K, M>
 
@@ -22,3 +22,10 @@ export type MVideoImportDefault = MVideoImport &
 export type MVideoImportDefaultFiles = MVideoImport &
   Use<'User', MUser> &
   Use<'Video', VideoAssociation & MVideoWithFile>
+
+// ############################################################################
+
+// Format for API or AP object
+
+export type MVideoImportFormattable = MVideoImport &
+  PickWithOpt<VideoImportModel, 'Video', MVideoFormattable & MVideoTag>
index 5a039d7b191a6889d2c03c9bd4b2463e588ca73a..1c256fd25c26f4800f2663d6e81daa90605510a6 100644 (file)
@@ -1,6 +1,6 @@
 import { VideoPlaylistElementModel } from '@server/models/video/video-playlist-element'
 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>
 
@@ -23,6 +23,13 @@ export type MVideoPlaylistVideoThumbnail = MVideoPlaylistElement &
 
 // For API
 
-export type MVideoPlaylistAP = MVideoPlaylistElement &
+export type MVideoPlaylistElementAP = MVideoPlaylistElement &
   Use<'Video', MVideoUrl> &
   Use<'VideoPlaylist', MVideoPlaylistPrivacy>
+
+// ############################################################################
+
+// Format for API or AP object
+
+export type MVideoPlaylistElementFormattable = MVideoPlaylistElement &
+  Use<'Video', MVideoFormattable>
index 6338184057da8f19039337d0d5259050679d55d2..a926106c5b1f2dc84d9be732c1f7e012ad99594b 100644 (file)
@@ -1,8 +1,8 @@
 import { VideoPlaylistModel } from '../../../models/video/video-playlist'
 import { PickWith } from '../../utils'
-import { MAccount, MAccountDefault, MAccountSummary } from '../account'
+import { MAccount, MAccountDefault, MAccountSummary, MAccountSummaryFormattable } from '../account'
 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'
 
 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 MVideoPlaylistPrivacy = Pick<MVideoPlaylist, 'privacy'>
 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<'OwnerAccount', MAccountSummary> &
   Use<'VideoChannel', MChannelSummary>
+
+// ############################################################################
+
+// Format for API or AP object
+
+export type MVideoPlaylistFormattable = MVideoPlaylistVideosLength &
+  Use<'OwnerAccount', MAccountSummaryFormattable> &
+  Use<'VideoChannel', MChannelSummaryFormattable>
index fc932999354c06385dcaabbb369e212c14628538..2ff8a625b9598f8412cb86ac6963c78a2141921f 100644 (file)
@@ -1,6 +1,6 @@
 import { AccountVideoRateModel } from '@server/models/account/account-video-rate'
 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>
 
@@ -14,3 +14,10 @@ export type MAccountVideoRateAccountUrl = MAccountVideoRate &
 export type MAccountVideoRateAccountVideo = MAccountVideoRate &
   Use<'Account', MAccountAudience> &
   Use<'Video', MVideo>
+
+// ############################################################################
+
+// Format for API or AP object
+
+export type MAccountVideoRateFormattable = Pick<MAccountVideoRate, 'type'> &
+  Use<'Video', MVideoFormattable>
index 914eb7f577d011440cc7d33b18a090da7b34b8ba..bc6d56607ea56e025974f4fe880b11be70bd1026 100644 (file)
@@ -1,12 +1,19 @@
 import { VideoModel } from '../../../models/video/video'
 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 { MVideoCaptionLanguage } from './video-caption'
 import { MStreamingPlaylist, MStreamingPlaylistRedundancies } from './video-streaming-playlist'
 import { MVideoFile, MVideoFileRedundanciesOpt } from './video-file'
 import { MThumbnail } from './thumbnail'
-import { MVideoBlacklistLight, MVideoBlacklistUnfederated } from './video-blacklist'
+import { MVideoBlacklist, MVideoBlacklistLight, MVideoBlacklistUnfederated } from './video-blacklist'
 import { MScheduleVideoUpdate } from './schedule-video-update'
 import { MUserVideoHistoryTime } from '../user/user-video-history'
 
@@ -144,3 +151,19 @@ export type MVideoForUser = MVideo &
   Use<'ScheduleVideoUpdate', MScheduleVideoUpdate> &
   Use<'VideoBlacklist', MVideoBlacklistLight> &
   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[]>
index ed0fca3d156179acdea9d1c108e698680885094f..4b5cf4d7e14d37b88fcb1706bc8845da3419ad75 100644 (file)
@@ -4,8 +4,6 @@ export type 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> = {
   [P in KT]: T[P] extends V ? V : never
 }