diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/account/account.ts | 19 | ||||
-rw-r--r-- | server/models/activitypub/actor.ts | 14 | ||||
-rw-r--r-- | server/models/video/thumbnail.ts | 8 | ||||
-rw-r--r-- | server/models/video/video-channel.ts | 34 | ||||
-rw-r--r-- | server/models/video/video-file.ts | 5 | ||||
-rw-r--r-- | server/models/video/video.ts | 23 |
6 files changed, 45 insertions, 58 deletions
diff --git a/server/models/account/account.ts b/server/models/account/account.ts index 2b04acd86..09cada096 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts | |||
@@ -47,7 +47,7 @@ export enum ScopeNames { | |||
47 | attributes: [ 'id', 'name' ], | 47 | attributes: [ 'id', 'name' ], |
48 | include: [ | 48 | include: [ |
49 | { | 49 | { |
50 | attributes: [ 'id', 'uuid', 'preferredUsername', 'url', 'serverId', 'avatarId' ], | 50 | attributes: [ 'id', 'preferredUsername', 'url', 'serverId', 'avatarId' ], |
51 | model: ActorModel.unscoped(), | 51 | model: ActorModel.unscoped(), |
52 | required: true, | 52 | required: true, |
53 | where: whereActor, | 53 | where: whereActor, |
@@ -180,22 +180,6 @@ export class AccountModel extends Model<AccountModel> { | |||
180 | return AccountModel.findByPk(id, { transaction }) | 180 | return AccountModel.findByPk(id, { transaction }) |
181 | } | 181 | } |
182 | 182 | ||
183 | static loadByUUID (uuid: string) { | ||
184 | const query = { | ||
185 | include: [ | ||
186 | { | ||
187 | model: ActorModel, | ||
188 | required: true, | ||
189 | where: { | ||
190 | uuid | ||
191 | } | ||
192 | } | ||
193 | ] | ||
194 | } | ||
195 | |||
196 | return AccountModel.findOne(query) | ||
197 | } | ||
198 | |||
199 | static loadByNameWithHost (nameWithHost: string) { | 183 | static loadByNameWithHost (nameWithHost: string) { |
200 | const [ accountName, host ] = nameWithHost.split('@') | 184 | const [ accountName, host ] = nameWithHost.split('@') |
201 | 185 | ||
@@ -332,7 +316,6 @@ export class AccountModel extends Model<AccountModel> { | |||
332 | 316 | ||
333 | return { | 317 | return { |
334 | id: this.id, | 318 | id: this.id, |
335 | uuid: actor.uuid, | ||
336 | name: actor.name, | 319 | name: actor.name, |
337 | displayName: this.getDisplayName(), | 320 | displayName: this.getDisplayName(), |
338 | url: actor.url, | 321 | url: actor.url, |
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index 4a466441c..bd6a2c8fd 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts | |||
@@ -7,13 +7,11 @@ import { | |||
7 | Column, | 7 | Column, |
8 | CreatedAt, | 8 | CreatedAt, |
9 | DataType, | 9 | DataType, |
10 | Default, | ||
11 | DefaultScope, | 10 | DefaultScope, |
12 | ForeignKey, | 11 | ForeignKey, |
13 | HasMany, | 12 | HasMany, |
14 | HasOne, | 13 | HasOne, |
15 | Is, | 14 | Is, |
16 | IsUUID, | ||
17 | Model, | 15 | Model, |
18 | Scopes, | 16 | Scopes, |
19 | Table, | 17 | Table, |
@@ -120,10 +118,6 @@ export const unusedActorAttributesForAPI = [ | |||
120 | fields: [ 'avatarId' ] | 118 | fields: [ 'avatarId' ] |
121 | }, | 119 | }, |
122 | { | 120 | { |
123 | fields: [ 'uuid' ], | ||
124 | unique: true | ||
125 | }, | ||
126 | { | ||
127 | fields: [ 'followersUrl' ] | 121 | fields: [ 'followersUrl' ] |
128 | } | 122 | } |
129 | ] | 123 | ] |
@@ -135,12 +129,6 @@ export class ActorModel extends Model<ActorModel> { | |||
135 | type: ActivityPubActorType | 129 | type: ActivityPubActorType |
136 | 130 | ||
137 | @AllowNull(false) | 131 | @AllowNull(false) |
138 | @Default(DataType.UUIDV4) | ||
139 | @IsUUID(4) | ||
140 | @Column(DataType.UUID) | ||
141 | uuid: string | ||
142 | |||
143 | @AllowNull(false) | ||
144 | @Is('ActorPreferredUsername', value => throwIfNotValid(value, isActorPreferredUsernameValid, 'actor preferred username')) | 132 | @Is('ActorPreferredUsername', value => throwIfNotValid(value, isActorPreferredUsernameValid, 'actor preferred username')) |
145 | @Column | 133 | @Column |
146 | preferredUsername: string | 134 | preferredUsername: string |
@@ -408,7 +396,6 @@ export class ActorModel extends Model<ActorModel> { | |||
408 | return { | 396 | return { |
409 | id: this.id, | 397 | id: this.id, |
410 | url: this.url, | 398 | url: this.url, |
411 | uuid: this.uuid, | ||
412 | name: this.preferredUsername, | 399 | name: this.preferredUsername, |
413 | host: this.getHost(), | 400 | host: this.getHost(), |
414 | hostRedundancyAllowed: this.getRedundancyAllowed(), | 401 | hostRedundancyAllowed: this.getRedundancyAllowed(), |
@@ -454,7 +441,6 @@ export class ActorModel extends Model<ActorModel> { | |||
454 | endpoints: { | 441 | endpoints: { |
455 | sharedInbox: this.sharedInboxUrl | 442 | sharedInbox: this.sharedInboxUrl |
456 | }, | 443 | }, |
457 | uuid: this.uuid, | ||
458 | publicKey: { | 444 | publicKey: { |
459 | id: this.getPublicKeyUrl(), | 445 | id: this.getPublicKeyUrl(), |
460 | owner: this.url, | 446 | owner: this.url, |
diff --git a/server/models/video/thumbnail.ts b/server/models/video/thumbnail.ts index 206e9a3d6..8faf0adba 100644 --- a/server/models/video/thumbnail.ts +++ b/server/models/video/thumbnail.ts | |||
@@ -107,10 +107,12 @@ export class ThumbnailModel extends Model<ThumbnailModel> { | |||
107 | return WEBSERVER.URL + staticPath + this.filename | 107 | return WEBSERVER.URL + staticPath + this.filename |
108 | } | 108 | } |
109 | 109 | ||
110 | removeThumbnail () { | 110 | getPath () { |
111 | const directory = ThumbnailModel.types[this.type].directory | 111 | const directory = ThumbnailModel.types[this.type].directory |
112 | const thumbnailPath = join(directory, this.filename) | 112 | return join(directory, this.filename) |
113 | } | ||
113 | 114 | ||
114 | return remove(thumbnailPath) | 115 | removeThumbnail () { |
116 | return remove(this.getPath()) | ||
115 | } | 117 | } |
116 | } | 118 | } |
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index fb70e6625..b0b261c88 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts | |||
@@ -72,7 +72,7 @@ type AvailableForListOptions = { | |||
72 | attributes: [ 'name', 'description', 'id', 'actorId' ], | 72 | attributes: [ 'name', 'description', 'id', 'actorId' ], |
73 | include: [ | 73 | include: [ |
74 | { | 74 | { |
75 | attributes: [ 'uuid', 'preferredUsername', 'url', 'serverId', 'avatarId' ], | 75 | attributes: [ 'preferredUsername', 'url', 'serverId', 'avatarId' ], |
76 | model: ActorModel.unscoped(), | 76 | model: ActorModel.unscoped(), |
77 | required: true, | 77 | required: true, |
78 | include: [ | 78 | include: [ |
@@ -334,14 +334,21 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
334 | }) | 334 | }) |
335 | } | 335 | } |
336 | 336 | ||
337 | static listByAccount (accountId: number) { | 337 | static listByAccount (options: { |
338 | accountId: number, | ||
339 | start: number, | ||
340 | count: number, | ||
341 | sort: string | ||
342 | }) { | ||
338 | const query = { | 343 | const query = { |
339 | order: getSort('createdAt'), | 344 | offset: options.start, |
345 | limit: options.count, | ||
346 | order: getSort(options.sort), | ||
340 | include: [ | 347 | include: [ |
341 | { | 348 | { |
342 | model: AccountModel, | 349 | model: AccountModel, |
343 | where: { | 350 | where: { |
344 | id: accountId | 351 | id: options.accountId |
345 | }, | 352 | }, |
346 | required: true | 353 | required: true |
347 | } | 354 | } |
@@ -380,24 +387,6 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
380 | .findByPk(id) | 387 | .findByPk(id) |
381 | } | 388 | } |
382 | 389 | ||
383 | static loadByUUIDAndPopulateAccount (uuid: string) { | ||
384 | const query = { | ||
385 | include: [ | ||
386 | { | ||
387 | model: ActorModel, | ||
388 | required: true, | ||
389 | where: { | ||
390 | uuid | ||
391 | } | ||
392 | } | ||
393 | ] | ||
394 | } | ||
395 | |||
396 | return VideoChannelModel | ||
397 | .scope([ ScopeNames.WITH_ACCOUNT ]) | ||
398 | .findOne(query) | ||
399 | } | ||
400 | |||
401 | static loadByUrlAndPopulateAccount (url: string) { | 390 | static loadByUrlAndPopulateAccount (url: string) { |
402 | const query = { | 391 | const query = { |
403 | include: [ | 392 | include: [ |
@@ -503,7 +492,6 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
503 | 492 | ||
504 | return { | 493 | return { |
505 | id: this.id, | 494 | id: this.id, |
506 | uuid: actor.uuid, | ||
507 | name: actor.name, | 495 | name: actor.name, |
508 | displayName: this.getDisplayName(), | 496 | displayName: this.getDisplayName(), |
509 | url: actor.url, | 497 | url: actor.url, |
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts index 2203a7aba..05c490759 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts | |||
@@ -24,6 +24,7 @@ import { VideoModel } from './video' | |||
24 | import { VideoRedundancyModel } from '../redundancy/video-redundancy' | 24 | import { VideoRedundancyModel } from '../redundancy/video-redundancy' |
25 | import { VideoStreamingPlaylistModel } from './video-streaming-playlist' | 25 | import { VideoStreamingPlaylistModel } from './video-streaming-playlist' |
26 | import { FindOptions, QueryTypes, Transaction } from 'sequelize' | 26 | import { FindOptions, QueryTypes, Transaction } from 'sequelize' |
27 | import { MIMETYPES } from '../../initializers/constants' | ||
27 | 28 | ||
28 | @Table({ | 29 | @Table({ |
29 | tableName: 'videoFile', | 30 | tableName: 'videoFile', |
@@ -161,6 +162,10 @@ export class VideoFileModel extends Model<VideoFileModel> { | |||
161 | })) | 162 | })) |
162 | } | 163 | } |
163 | 164 | ||
165 | isAudio () { | ||
166 | return !!MIMETYPES.AUDIO.EXT_MIMETYPE[this.extname] | ||
167 | } | ||
168 | |||
164 | hasSameUniqueKeysThan (other: VideoFileModel) { | 169 | hasSameUniqueKeysThan (other: VideoFileModel) { |
165 | return this.fps === other.fps && | 170 | return this.fps === other.fps && |
166 | this.resolution === other.resolution && | 171 | this.resolution === other.resolution && |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index c0a7892a4..eccf0a4fa 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -1515,6 +1515,29 @@ export class VideoModel extends Model<VideoModel> { | |||
1515 | .then(results => results.length === 1) | 1515 | .then(results => results.length === 1) |
1516 | } | 1516 | } |
1517 | 1517 | ||
1518 | static bulkUpdateSupportField (videoChannel: VideoChannelModel, t: Transaction) { | ||
1519 | const options = { | ||
1520 | where: { | ||
1521 | channelId: videoChannel.id | ||
1522 | }, | ||
1523 | transaction: t | ||
1524 | } | ||
1525 | |||
1526 | return VideoModel.update({ support: videoChannel.support }, options) | ||
1527 | } | ||
1528 | |||
1529 | static getAllIdsFromChannel (videoChannel: VideoChannelModel) { | ||
1530 | const query = { | ||
1531 | attributes: [ 'id' ], | ||
1532 | where: { | ||
1533 | channelId: videoChannel.id | ||
1534 | } | ||
1535 | } | ||
1536 | |||
1537 | return VideoModel.findAll(query) | ||
1538 | .then(videos => videos.map(v => v.id)) | ||
1539 | } | ||
1540 | |||
1518 | // threshold corresponds to how many video the field should have to be returned | 1541 | // threshold corresponds to how many video the field should have to be returned |
1519 | static async getRandomFieldSamples (field: 'category' | 'channelId', threshold: number, count: number) { | 1542 | static async getRandomFieldSamples (field: 'category' | 'channelId', threshold: number, count: number) { |
1520 | const serverActor = await getServerActor() | 1543 | const serverActor = await getServerActor() |