From 571389d43b8fc8aaf27e77c06f19b320b08dbbc9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Nov 2017 17:27:49 +0100 Subject: Make it compile at least --- server/models/account/account-interface.ts | 4 +- server/models/account/account.ts | 17 ++++--- server/models/job/job-interface.ts | 2 +- server/models/video/video-channel.ts | 14 +++--- server/models/video/video.ts | 72 ++++++++++++++---------------- 5 files changed, 53 insertions(+), 56 deletions(-) (limited to 'server/models') diff --git a/server/models/account/account-interface.ts b/server/models/account/account-interface.ts index 2ef3e2246..a662eb992 100644 --- a/server/models/account/account-interface.ts +++ b/server/models/account/account-interface.ts @@ -13,8 +13,8 @@ export namespace AccountMethods { export type LoadAccountByPodAndUUID = (uuid: string, podId: number, transaction: Sequelize.Transaction) => Bluebird export type LoadLocalAccountByName = (name: string) => Bluebird export type ListOwned = () => Bluebird - export type ListFollowerUrlsForApi = (name: string, start: number, count: number) => Promise< ResultList > - export type ListFollowingUrlsForApi = (name: string, start: number, count: number) => Promise< ResultList > + export type ListFollowerUrlsForApi = (name: string, start: number, count?: number) => Promise< ResultList > + export type ListFollowingUrlsForApi = (name: string, start: number, count?: number) => Promise< ResultList > export type ToActivityPubObject = (this: AccountInstance) => ActivityPubActor export type IsOwned = (this: AccountInstance) => boolean diff --git a/server/models/account/account.ts b/server/models/account/account.ts index 00c0aefd4..a79e13880 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -268,14 +268,15 @@ function afterDestroy (account: AccountInstance) { uuid: account.uuid } - return removeVideoAccountToFriends(removeVideoAccountToFriendsParams) + // FIXME: remove account in followers + // return removeVideoAccountToFriends(removeVideoAccountToFriendsParams) } return undefined } toActivityPubObject = function (this: AccountInstance) { - const type = this.podId ? 'Application' : 'Person' + const type = this.podId ? 'Application' as 'Application' : 'Person' as 'Person' const json = { type, @@ -346,11 +347,11 @@ listOwned = function () { return Account.findAll(query) } -listFollowerUrlsForApi = function (name: string, start: number, count: number) { +listFollowerUrlsForApi = function (name: string, start: number, count?: number) { return createListFollowForApiQuery('followers', name, start, count) } -listFollowingUrlsForApi = function (name: string, start: number, count: number) { +listFollowingUrlsForApi = function (name: string, start: number, count?: number) { return createListFollowForApiQuery('following', name, start, count) } @@ -405,7 +406,7 @@ loadAccountByPodAndUUID = function (uuid: string, podId: number, transaction: Se // ------------------------------ UTILS ------------------------------ -async function createListFollowForApiQuery (type: 'followers' | 'following', name: string, start: number, count: number) { +async function createListFollowForApiQuery (type: 'followers' | 'following', name: string, start: number, count?: number) { let firstJoin: string let secondJoin: string @@ -421,11 +422,13 @@ async function createListFollowForApiQuery (type: 'followers' | 'following', nam const tasks: Promise[] = [] for (const selection of selections) { - const query = 'SELECT ' + selection + ' FROM "Account" ' + + let query = 'SELECT ' + selection + ' FROM "Account" ' + 'INNER JOIN "AccountFollower" ON "AccountFollower"."' + firstJoin + '" = "Account"."id" ' + 'INNER JOIN "Account" AS "Followers" ON "Followers"."id" = "AccountFollower"."' + secondJoin + '" ' + 'WHERE "Account"."name" = \'$name\' ' + - 'LIMIT ' + start + ', ' + count + 'LIMIT ' + start + + if (count !== undefined) query += ', ' + count const options = { bind: { name }, diff --git a/server/models/job/job-interface.ts b/server/models/job/job-interface.ts index 163930a4f..411a05029 100644 --- a/server/models/job/job-interface.ts +++ b/server/models/job/job-interface.ts @@ -14,7 +14,7 @@ export interface JobClass { export interface JobAttributes { state: JobState handlerName: string - handlerInputData: object + handlerInputData: any } export interface JobInstance extends JobClass, JobAttributes, Sequelize.Instance { diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 93a611fa0..183ff3436 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -1,7 +1,6 @@ import * as Sequelize from 'sequelize' import { isVideoChannelNameValid, isVideoChannelDescriptionValid } from '../../helpers' -import { removeVideoChannelToFriends } from '../../lib' import { addMethodsToModel, getSort } from '../utils' import { @@ -143,12 +142,13 @@ toFormattedJSON = function (this: VideoChannelInstance) { toActivityPubObject = function (this: VideoChannelInstance) { const json = { + type: 'VideoChannel' as 'VideoChannel', + id: this.url, uuid: this.uuid, + content: this.description, name: this.name, - description: this.description, - createdAt: this.createdAt, - updatedAt: this.updatedAt, - ownerUUID: this.Account.uuid + published: this.createdAt, + updated: this.updatedAt } return json @@ -180,7 +180,7 @@ function afterDestroy (videoChannel: VideoChannelInstance) { uuid: videoChannel.uuid } - return removeVideoChannelToFriends(removeVideoChannelToFriendsParams) + // FIXME: send remove event to followers } return undefined @@ -277,7 +277,7 @@ loadByUUIDOrUrl = function (uuid: string, url: string, t?: Sequelize.Transaction { uuid }, { url } ] - }, + } } if (t !== undefined) query.transaction = t diff --git a/server/models/video/video.ts b/server/models/video/video.ts index b5d333347..10ae5097c 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -1,58 +1,52 @@ -import * as safeBuffer from 'safe-buffer' -const Buffer = safeBuffer.Buffer -import * as magnetUtil from 'magnet-uri' import { map, maxBy, truncate } from 'lodash' +import * as magnetUtil from 'magnet-uri' import * as parseTorrent from 'parse-torrent' import { join } from 'path' +import * as safeBuffer from 'safe-buffer' import * as Sequelize from 'sequelize' - -import { TagInstance } from './tag-interface' +import { VideoPrivacy, VideoResolution } from '../../../shared' +import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object' import { - logger, - isVideoNameValid, + createTorrentPromise, + generateImageFromVideoFile, + getActivityPubUrl, + getVideoFileHeight, isVideoCategoryValid, - isVideoLicenceValid, - isVideoLanguageValid, - isVideoNSFWValid, isVideoDescriptionValid, isVideoDurationValid, + isVideoLanguageValid, + isVideoLicenceValid, + isVideoNameValid, + isVideoNSFWValid, isVideoPrivacyValid, - readFileBufferPromise, - unlinkPromise, + logger, renamePromise, - writeFilePromise, - createTorrentPromise, statPromise, - generateImageFromVideoFile, transcode, - getVideoFileHeight, - getActivityPubUrl + unlinkPromise, + writeFilePromise } from '../../helpers' import { + API_VERSION, CONFIG, + CONSTRAINTS_FIELDS, + PREVIEWS_SIZE, REMOTE_SCHEME, STATIC_PATHS, + THUMBNAILS_SIZE, VIDEO_CATEGORIES, - VIDEO_LICENCES, VIDEO_LANGUAGES, - THUMBNAILS_SIZE, - PREVIEWS_SIZE, - CONSTRAINTS_FIELDS, - API_VERSION, + VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../initializers' -import { removeVideoToFriends } from '../../lib' -import { VideoResolution, VideoPrivacy } from '../../../shared' -import { VideoFileInstance, VideoFileModel } from './video-file-interface' import { addMethodsToModel, getSort } from '../utils' -import { - VideoInstance, - VideoAttributes, - VideoMethods -} from './video-interface' -import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object' +import { TagInstance } from './tag-interface' +import { VideoFileInstance, VideoFileModel } from './video-file-interface' +import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface' + +const Buffer = safeBuffer.Buffer let Video: Sequelize.Model let getOriginalFile: VideoMethods.GetOriginalFile @@ -374,8 +368,8 @@ function afterDestroy (video: VideoInstance) { } tasks.push( - video.removePreview(), - removeVideoToFriends(removeVideoToFriendsParams) + video.removePreview() + // FIXME: remove video for followers ) // Remove physical files and torrents @@ -566,7 +560,7 @@ toActivityPubObject = function (this: VideoInstance) { const { baseUrlHttp, baseUrlWs } = getBaseUrls(this) const tag = this.Tags.map(t => ({ - type: 'Hashtag', + type: 'Hashtag' as 'Hashtag', name: t.name })) @@ -596,7 +590,7 @@ toActivityPubObject = function (this: VideoInstance) { } const videoObject: VideoTorrentObject = { - type: 'Video', + type: 'Video' as 'Video', id: getActivityPubUrl('video', this.uuid), name: this.name, // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration @@ -604,15 +598,15 @@ toActivityPubObject = function (this: VideoInstance) { uuid: this.uuid, tag, category: { - id: this.category, - label: this.getCategoryLabel() + identifier: this.category + '', + name: this.getCategoryLabel() }, licence: { - id: this.licence, + identifier: this.licence + '', name: this.getLicenceLabel() }, language: { - id: this.language, + identifier: this.language + '', name: this.getLanguageLabel() }, views: this.views, -- cgit v1.2.3