aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-16 11:08:25 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:52 +0100
commitefc32059d980c51793e8e9ac0fb6a885a8026f94 (patch)
treec272e63fd57a9625b53dc26ceb1b46aee35d21d3 /server/models
parentd846501818c2d29e66e6fd141789cb04fd55a437 (diff)
downloadPeerTube-efc32059d980c51793e8e9ac0fb6a885a8026f94.tar.gz
PeerTube-efc32059d980c51793e8e9ac0fb6a885a8026f94.tar.zst
PeerTube-efc32059d980c51793e8e9ac0fb6a885a8026f94.zip
Send server announce when users upload a video
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/account-follow-interface.ts6
-rw-r--r--server/models/account/account-follow.ts30
-rw-r--r--server/models/video/video-channel.ts4
-rw-r--r--server/models/video/video.ts6
4 files changed, 30 insertions, 16 deletions
diff --git a/server/models/account/account-follow-interface.ts b/server/models/account/account-follow-interface.ts
index 54baf45ed..21fda98ce 100644
--- a/server/models/account/account-follow-interface.ts
+++ b/server/models/account/account-follow-interface.ts
@@ -10,8 +10,9 @@ export namespace AccountFollowMethods {
10 export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> > 10 export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> >
11 export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> > 11 export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> >
12 12
13 export type ListAcceptedFollowerUrlsForApi = (id: number, start?: number, count?: number) => Promise< ResultList<string> > 13 export type ListAcceptedFollowerUrlsForApi = (accountId: number[], start?: number, count?: number) => Promise< ResultList<string> >
14 export type ListAcceptedFollowingUrlsForApi = (id: number, start?: number, count?: number) => Promise< ResultList<string> > 14 export type ListAcceptedFollowingUrlsForApi = (accountId: number[], start?: number, count?: number) => Promise< ResultList<string> >
15 export type ListAcceptedFollowerSharedInboxUrls = (accountId: number[]) => Promise< ResultList<string> >
15} 16}
16 17
17export interface AccountFollowClass { 18export interface AccountFollowClass {
@@ -21,6 +22,7 @@ export interface AccountFollowClass {
21 22
22 listAcceptedFollowerUrlsForApi: AccountFollowMethods.ListAcceptedFollowerUrlsForApi 23 listAcceptedFollowerUrlsForApi: AccountFollowMethods.ListAcceptedFollowerUrlsForApi
23 listAcceptedFollowingUrlsForApi: AccountFollowMethods.ListAcceptedFollowingUrlsForApi 24 listAcceptedFollowingUrlsForApi: AccountFollowMethods.ListAcceptedFollowingUrlsForApi
25 listAcceptedFollowerSharedInboxUrls: AccountFollowMethods.ListAcceptedFollowerSharedInboxUrls
24} 26}
25 27
26export interface AccountFollowAttributes { 28export interface AccountFollowAttributes {
diff --git a/server/models/account/account-follow.ts b/server/models/account/account-follow.ts
index f457e43e9..8a7474c9d 100644
--- a/server/models/account/account-follow.ts
+++ b/server/models/account/account-follow.ts
@@ -11,6 +11,7 @@ let listFollowingForApi: AccountFollowMethods.ListFollowingForApi
11let listFollowersForApi: AccountFollowMethods.ListFollowersForApi 11let listFollowersForApi: AccountFollowMethods.ListFollowersForApi
12let listAcceptedFollowerUrlsForApi: AccountFollowMethods.ListAcceptedFollowerUrlsForApi 12let listAcceptedFollowerUrlsForApi: AccountFollowMethods.ListAcceptedFollowerUrlsForApi
13let listAcceptedFollowingUrlsForApi: AccountFollowMethods.ListAcceptedFollowingUrlsForApi 13let listAcceptedFollowingUrlsForApi: AccountFollowMethods.ListAcceptedFollowingUrlsForApi
14let listAcceptedFollowerSharedInboxUrls: AccountFollowMethods.ListAcceptedFollowerSharedInboxUrls
14 15
15export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { 16export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
16 AccountFollow = sequelize.define<AccountFollowInstance, AccountFollowAttributes>('AccountFollow', 17 AccountFollow = sequelize.define<AccountFollowInstance, AccountFollowAttributes>('AccountFollow',
@@ -42,7 +43,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
42 listFollowingForApi, 43 listFollowingForApi,
43 listFollowersForApi, 44 listFollowersForApi,
44 listAcceptedFollowerUrlsForApi, 45 listAcceptedFollowerUrlsForApi,
45 listAcceptedFollowingUrlsForApi 46 listAcceptedFollowingUrlsForApi,
47 listAcceptedFollowerSharedInboxUrls
46 ] 48 ]
47 addMethodsToModel(AccountFollow, classMethods) 49 addMethodsToModel(AccountFollow, classMethods)
48 50
@@ -146,17 +148,27 @@ listFollowersForApi = function (id: number, start: number, count: number, sort:
146 }) 148 })
147} 149}
148 150
149listAcceptedFollowerUrlsForApi = function (accountId: number, start?: number, count?: number) { 151listAcceptedFollowerUrlsForApi = function (accountIds: number[], start?: number, count?: number) {
150 return createListAcceptedFollowForApiQuery('followers', accountId, start, count) 152 return createListAcceptedFollowForApiQuery('followers', accountIds, start, count)
151} 153}
152 154
153listAcceptedFollowingUrlsForApi = function (accountId: number, start?: number, count?: number) { 155listAcceptedFollowerSharedInboxUrls = function (accountIds: number[]) {
154 return createListAcceptedFollowForApiQuery('following', accountId, start, count) 156 return createListAcceptedFollowForApiQuery('followers', accountIds, undefined, undefined, 'sharedInboxUrl')
157}
158
159listAcceptedFollowingUrlsForApi = function (accountIds: number[], start?: number, count?: number) {
160 return createListAcceptedFollowForApiQuery('following', accountIds, start, count)
155} 161}
156 162
157// ------------------------------ UTILS ------------------------------ 163// ------------------------------ UTILS ------------------------------
158 164
159async function createListAcceptedFollowForApiQuery (type: 'followers' | 'following', accountId: number, start?: number, count?: number) { 165async function createListAcceptedFollowForApiQuery (
166 type: 'followers' | 'following',
167 accountIds: number[],
168 start?: number,
169 count?: number,
170 columnUrl = 'url'
171) {
160 let firstJoin: string 172 let firstJoin: string
161 let secondJoin: string 173 let secondJoin: string
162 174
@@ -168,20 +180,20 @@ async function createListAcceptedFollowForApiQuery (type: 'followers' | 'followi
168 secondJoin = 'targetAccountId' 180 secondJoin = 'targetAccountId'
169 } 181 }
170 182
171 const selections = [ '"Follows"."url" AS "url"', 'COUNT(*) AS "total"' ] 183 const selections = [ '"Follows"."' + columnUrl + '" AS "url"', 'COUNT(*) AS "total"' ]
172 const tasks: Promise<any>[] = [] 184 const tasks: Promise<any>[] = []
173 185
174 for (const selection of selections) { 186 for (const selection of selections) {
175 let query = 'SELECT ' + selection + ' FROM "Accounts" ' + 187 let query = 'SELECT ' + selection + ' FROM "Accounts" ' +
176 'INNER JOIN "AccountFollows" ON "AccountFollows"."' + firstJoin + '" = "Accounts"."id" ' + 188 'INNER JOIN "AccountFollows" ON "AccountFollows"."' + firstJoin + '" = "Accounts"."id" ' +
177 'INNER JOIN "Accounts" AS "Follows" ON "AccountFollows"."' + secondJoin + '" = "Follows"."id" ' + 189 'INNER JOIN "Accounts" AS "Follows" ON "AccountFollows"."' + secondJoin + '" = "Follows"."id" ' +
178 'WHERE "Accounts"."id" = $accountId AND "AccountFollows"."state" = \'accepted\' ' 190 'WHERE "Accounts"."id" IN ($accountIds) AND "AccountFollows"."state" = \'accepted\' '
179 191
180 if (start !== undefined) query += 'LIMIT ' + start 192 if (start !== undefined) query += 'LIMIT ' + start
181 if (count !== undefined) query += ', ' + count 193 if (count !== undefined) query += ', ' + count
182 194
183 const options = { 195 const options = {
184 bind: { accountId }, 196 bind: { accountIds: accountIds.join(',') },
185 type: Sequelize.QueryTypes.SELECT 197 type: Sequelize.QueryTypes.SELECT
186 } 198 }
187 tasks.push(AccountFollow['sequelize'].query(query, options)) 199 tasks.push(AccountFollow['sequelize'].query(query, options))
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index 3cb4a33b9..1f4604f1d 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -153,8 +153,8 @@ toActivityPubObject = function (this: VideoChannelInstance) {
153 uuid: this.uuid, 153 uuid: this.uuid,
154 content: this.description, 154 content: this.description,
155 name: this.name, 155 name: this.name,
156 published: this.createdAt, 156 published: this.createdAt.toISOString(),
157 updated: this.updatedAt 157 updated: this.updatedAt.toISOString()
158 } 158 }
159 159
160 return json 160 return json
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 480e54276..64ee7ae34 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -558,7 +558,7 @@ toActivityPubObject = function (this: VideoInstance) {
558 for (const file of this.VideoFiles) { 558 for (const file of this.VideoFiles) {
559 url.push({ 559 url.push({
560 type: 'Link', 560 type: 'Link',
561 mimeType: 'video/' + file.extname, 561 mimeType: 'video/' + file.extname.replace('.', ''),
562 url: getVideoFileUrl(this, file, baseUrlHttp), 562 url: getVideoFileUrl(this, file, baseUrlHttp),
563 width: file.resolution, 563 width: file.resolution,
564 size: file.size 564 size: file.size
@@ -601,8 +601,8 @@ toActivityPubObject = function (this: VideoInstance) {
601 }, 601 },
602 views: this.views, 602 views: this.views,
603 nsfw: this.nsfw, 603 nsfw: this.nsfw,
604 published: this.createdAt, 604 published: this.createdAt.toISOString(),
605 updated: this.updatedAt, 605 updated: this.updatedAt.toISOString(),
606 mediaType: 'text/markdown', 606 mediaType: 'text/markdown',
607 content: this.getTruncatedDescription(), 607 content: this.getTruncatedDescription(),
608 icon: { 608 icon: {