diff options
Diffstat (limited to 'server/models')
44 files changed, 186 insertions, 94 deletions
diff --git a/server/models/abuse/abuse-message.ts b/server/models/abuse/abuse-message.ts index 2c5987e96..6a441a210 100644 --- a/server/models/abuse/abuse-message.ts +++ b/server/models/abuse/abuse-message.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { isAbuseMessageValid } from '@server/helpers/custom-validators/abuses' | 2 | import { isAbuseMessageValid } from '@server/helpers/custom-validators/abuses' |
3 | import { MAbuseMessage, MAbuseMessageFormattable } from '@server/types/models' | 3 | import { MAbuseMessage, MAbuseMessageFormattable } from '@server/types/models' |
4 | import { AttributesOnly } from '@shared/core-utils' | 4 | import { AttributesOnly } from '@shared/typescript-utils' |
5 | import { AbuseMessage } from '@shared/models' | 5 | import { AbuseMessage } from '@shared/models' |
6 | import { AccountModel, ScopeNames as AccountScopeNames } from '../account/account' | 6 | import { AccountModel, ScopeNames as AccountScopeNames } from '../account/account' |
7 | import { getSort, throwIfNotValid } from '../utils' | 7 | import { getSort, throwIfNotValid } from '../utils' |
diff --git a/server/models/abuse/abuse.ts b/server/models/abuse/abuse.ts index 3518f5c02..4344df006 100644 --- a/server/models/abuse/abuse.ts +++ b/server/models/abuse/abuse.ts | |||
@@ -16,7 +16,7 @@ import { | |||
16 | UpdatedAt | 16 | UpdatedAt |
17 | } from 'sequelize-typescript' | 17 | } from 'sequelize-typescript' |
18 | import { isAbuseModerationCommentValid, isAbuseReasonValid, isAbuseStateValid } from '@server/helpers/custom-validators/abuses' | 18 | import { isAbuseModerationCommentValid, isAbuseReasonValid, isAbuseStateValid } from '@server/helpers/custom-validators/abuses' |
19 | import { abusePredefinedReasonsMap, AttributesOnly } from '@shared/core-utils' | 19 | import { abusePredefinedReasonsMap } from '@shared/core-utils' |
20 | import { | 20 | import { |
21 | AbuseFilter, | 21 | AbuseFilter, |
22 | AbuseObject, | 22 | AbuseObject, |
@@ -30,6 +30,7 @@ import { | |||
30 | UserAbuse, | 30 | UserAbuse, |
31 | UserVideoAbuse | 31 | UserVideoAbuse |
32 | } from '@shared/models' | 32 | } from '@shared/models' |
33 | import { AttributesOnly } from '@shared/typescript-utils' | ||
33 | import { ABUSE_STATES, CONSTRAINTS_FIELDS } from '../../initializers/constants' | 34 | import { ABUSE_STATES, CONSTRAINTS_FIELDS } from '../../initializers/constants' |
34 | import { MAbuseAdminFormattable, MAbuseAP, MAbuseFull, MAbuseReporter, MAbuseUserFormattable, MUserAccountId } from '../../types/models' | 35 | import { MAbuseAdminFormattable, MAbuseAP, MAbuseFull, MAbuseReporter, MAbuseUserFormattable, MUserAccountId } from '../../types/models' |
35 | import { AccountModel, ScopeNames as AccountScopeNames, SummaryOptions as AccountSummaryOptions } from '../account/account' | 36 | import { AccountModel, ScopeNames as AccountScopeNames, SummaryOptions as AccountSummaryOptions } from '../account/account' |
diff --git a/server/models/abuse/video-abuse.ts b/server/models/abuse/video-abuse.ts index 95bff50d0..773a9ebba 100644 --- a/server/models/abuse/video-abuse.ts +++ b/server/models/abuse/video-abuse.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { AttributesOnly } from '@shared/core-utils' | 2 | import { AttributesOnly } from '@shared/typescript-utils' |
3 | import { VideoDetails } from '@shared/models' | 3 | import { VideoDetails } from '@shared/models' |
4 | import { VideoModel } from '../video/video' | 4 | import { VideoModel } from '../video/video' |
5 | import { AbuseModel } from './abuse' | 5 | import { AbuseModel } from './abuse' |
diff --git a/server/models/abuse/video-comment-abuse.ts b/server/models/abuse/video-comment-abuse.ts index 32cb2ca64..337aaaa58 100644 --- a/server/models/abuse/video-comment-abuse.ts +++ b/server/models/abuse/video-comment-abuse.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { AttributesOnly } from '@shared/core-utils' | 2 | import { AttributesOnly } from '@shared/typescript-utils' |
3 | import { VideoCommentModel } from '../video/video-comment' | 3 | import { VideoCommentModel } from '../video/video-comment' |
4 | import { AbuseModel } from './abuse' | 4 | import { AbuseModel } from './abuse' |
5 | 5 | ||
diff --git a/server/models/account/account-blocklist.ts b/server/models/account/account-blocklist.ts index b2375b006..1162962bf 100644 --- a/server/models/account/account-blocklist.ts +++ b/server/models/account/account-blocklist.ts | |||
@@ -1,11 +1,12 @@ | |||
1 | import { Op } from 'sequelize' | 1 | import { Op, QueryTypes } from 'sequelize' |
2 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { handlesToNameAndHost } from '@server/helpers/actors' | ||
3 | import { MAccountBlocklist, MAccountBlocklistAccounts, MAccountBlocklistFormattable } from '@server/types/models' | 4 | import { MAccountBlocklist, MAccountBlocklistAccounts, MAccountBlocklistFormattable } from '@server/types/models' |
4 | import { AttributesOnly } from '@shared/core-utils' | 5 | import { AttributesOnly } from '@shared/typescript-utils' |
5 | import { AccountBlock } from '../../../shared/models' | 6 | import { AccountBlock } from '../../../shared/models' |
6 | import { ActorModel } from '../actor/actor' | 7 | import { ActorModel } from '../actor/actor' |
7 | import { ServerModel } from '../server/server' | 8 | import { ServerModel } from '../server/server' |
8 | import { getSort, searchAttribute } from '../utils' | 9 | import { createSafeIn, getSort, searchAttribute } from '../utils' |
9 | import { AccountModel } from './account' | 10 | import { AccountModel } from './account' |
10 | 11 | ||
11 | enum ScopeNames { | 12 | enum ScopeNames { |
@@ -77,7 +78,7 @@ export class AccountBlocklistModel extends Model<Partial<AttributesOnly<AccountB | |||
77 | }) | 78 | }) |
78 | BlockedAccount: AccountModel | 79 | BlockedAccount: AccountModel |
79 | 80 | ||
80 | static isAccountMutedByMulti (accountIds: number[], targetAccountId: number) { | 81 | static isAccountMutedByAccounts (accountIds: number[], targetAccountId: number) { |
81 | const query = { | 82 | const query = { |
82 | attributes: [ 'accountId', 'id' ], | 83 | attributes: [ 'accountId', 'id' ], |
83 | where: { | 84 | where: { |
@@ -187,6 +188,39 @@ export class AccountBlocklistModel extends Model<Partial<AttributesOnly<AccountB | |||
187 | .then(entries => entries.map(e => `${e.BlockedAccount.Actor.preferredUsername}@${e.BlockedAccount.Actor.Server.host}`)) | 188 | .then(entries => entries.map(e => `${e.BlockedAccount.Actor.preferredUsername}@${e.BlockedAccount.Actor.Server.host}`)) |
188 | } | 189 | } |
189 | 190 | ||
191 | static getBlockStatus (byAccountIds: number[], handles: string[]): Promise<{ name: string, host: string, accountId: number }[]> { | ||
192 | const sanitizedHandles = handlesToNameAndHost(handles) | ||
193 | |||
194 | const localHandles = sanitizedHandles.filter(h => !h.host) | ||
195 | .map(h => h.name) | ||
196 | |||
197 | const remoteHandles = sanitizedHandles.filter(h => !!h.host) | ||
198 | .map(h => ([ h.name, h.host ])) | ||
199 | |||
200 | const handlesWhere: string[] = [] | ||
201 | |||
202 | if (localHandles.length !== 0) { | ||
203 | handlesWhere.push(`("actor"."preferredUsername" IN (:localHandles) AND "server"."id" IS NULL)`) | ||
204 | } | ||
205 | |||
206 | if (remoteHandles.length !== 0) { | ||
207 | handlesWhere.push(`(("actor"."preferredUsername", "server"."host") IN (:remoteHandles))`) | ||
208 | } | ||
209 | |||
210 | const rawQuery = `SELECT "accountBlocklist"."accountId", "actor"."preferredUsername" AS "name", "server"."host" ` + | ||
211 | `FROM "accountBlocklist" ` + | ||
212 | `INNER JOIN "account" ON "account"."id" = "accountBlocklist"."targetAccountId" ` + | ||
213 | `INNER JOIN "actor" ON "actor"."id" = "account"."actorId" ` + | ||
214 | `LEFT JOIN "server" ON "server"."id" = "actor"."serverId" ` + | ||
215 | `WHERE "accountBlocklist"."accountId" IN (${createSafeIn(AccountBlocklistModel.sequelize, byAccountIds)}) ` + | ||
216 | `AND (${handlesWhere.join(' OR ')})` | ||
217 | |||
218 | return AccountBlocklistModel.sequelize.query(rawQuery, { | ||
219 | type: QueryTypes.SELECT as QueryTypes.SELECT, | ||
220 | replacements: { byAccountIds, localHandles, remoteHandles } | ||
221 | }) | ||
222 | } | ||
223 | |||
190 | toFormattedJSON (this: MAccountBlocklistFormattable): AccountBlock { | 224 | toFormattedJSON (this: MAccountBlocklistFormattable): AccountBlock { |
191 | return { | 225 | return { |
192 | byAccount: this.ByAccount.toFormattedJSON(), | 226 | byAccount: this.ByAccount.toFormattedJSON(), |
diff --git a/server/models/account/account-video-rate.ts b/server/models/account/account-video-rate.ts index ee6dbc6da..e89d31adf 100644 --- a/server/models/account/account-video-rate.ts +++ b/server/models/account/account-video-rate.ts | |||
@@ -6,10 +6,9 @@ import { | |||
6 | MAccountVideoRateAccountUrl, | 6 | MAccountVideoRateAccountUrl, |
7 | MAccountVideoRateAccountVideo, | 7 | MAccountVideoRateAccountVideo, |
8 | MAccountVideoRateFormattable | 8 | MAccountVideoRateFormattable |
9 | } from '@server/types/models/video/video-rate' | 9 | } from '@server/types/models' |
10 | import { AttributesOnly } from '@shared/core-utils' | 10 | import { AccountVideoRate, VideoRateType } from '@shared/models' |
11 | import { AccountVideoRate } from '../../../shared' | 11 | import { AttributesOnly } from '@shared/typescript-utils' |
12 | import { VideoRateType } from '../../../shared/models/videos' | ||
13 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 12 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
14 | import { CONSTRAINTS_FIELDS, VIDEO_RATE_TYPES } from '../../initializers/constants' | 13 | import { CONSTRAINTS_FIELDS, VIDEO_RATE_TYPES } from '../../initializers/constants' |
15 | import { ActorModel } from '../actor/actor' | 14 | import { ActorModel } from '../actor/actor' |
diff --git a/server/models/account/account.ts b/server/models/account/account.ts index 71a9b8ccb..619a598dd 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts | |||
@@ -17,7 +17,7 @@ import { | |||
17 | UpdatedAt | 17 | UpdatedAt |
18 | } from 'sequelize-typescript' | 18 | } from 'sequelize-typescript' |
19 | import { ModelCache } from '@server/models/model-cache' | 19 | import { ModelCache } from '@server/models/model-cache' |
20 | import { AttributesOnly } from '@shared/core-utils' | 20 | import { AttributesOnly } from '@shared/typescript-utils' |
21 | import { Account, AccountSummary } from '../../../shared/models/actors' | 21 | import { Account, AccountSummary } from '../../../shared/models/actors' |
22 | import { isAccountDescriptionValid } from '../../helpers/custom-validators/accounts' | 22 | import { isAccountDescriptionValid } from '../../helpers/custom-validators/accounts' |
23 | import { CONSTRAINTS_FIELDS, SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants' | 23 | import { CONSTRAINTS_FIELDS, SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers/constants' |
diff --git a/server/models/actor/actor-follow.ts b/server/models/actor/actor-follow.ts index d6a2387a5..006282530 100644 --- a/server/models/actor/actor-follow.ts +++ b/server/models/actor/actor-follow.ts | |||
@@ -30,7 +30,7 @@ import { | |||
30 | MActorFollowFormattable, | 30 | MActorFollowFormattable, |
31 | MActorFollowSubscriptions | 31 | MActorFollowSubscriptions |
32 | } from '@server/types/models' | 32 | } from '@server/types/models' |
33 | import { AttributesOnly } from '@shared/core-utils' | 33 | import { AttributesOnly } from '@shared/typescript-utils' |
34 | import { ActivityPubActorType } from '@shared/models' | 34 | import { ActivityPubActorType } from '@shared/models' |
35 | import { FollowState } from '../../../shared/models/actors' | 35 | import { FollowState } from '../../../shared/models/actors' |
36 | import { ActorFollow } from '../../../shared/models/actors/follow.model' | 36 | import { ActorFollow } from '../../../shared/models/actors/follow.model' |
diff --git a/server/models/actor/actor-image.ts b/server/models/actor/actor-image.ts index 98a7f6fba..8edff5ab4 100644 --- a/server/models/actor/actor-image.ts +++ b/server/models/actor/actor-image.ts | |||
@@ -2,7 +2,7 @@ import { remove } from 'fs-extra' | |||
2 | import { join } from 'path' | 2 | import { join } from 'path' |
3 | import { AfterDestroy, AllowNull, Column, CreatedAt, Default, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 3 | import { AfterDestroy, AllowNull, Column, CreatedAt, Default, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
4 | import { MActorImageFormattable } from '@server/types/models' | 4 | import { MActorImageFormattable } from '@server/types/models' |
5 | import { AttributesOnly } from '@shared/core-utils' | 5 | import { AttributesOnly } from '@shared/typescript-utils' |
6 | import { ActorImageType } from '@shared/models' | 6 | import { ActorImageType } from '@shared/models' |
7 | import { ActorImage } from '../../../shared/models/actors/actor-image.model' | 7 | import { ActorImage } from '../../../shared/models/actors/actor-image.model' |
8 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 8 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
diff --git a/server/models/actor/actor.ts b/server/models/actor/actor.ts index 8df49951d..c12dcf634 100644 --- a/server/models/actor/actor.ts +++ b/server/models/actor/actor.ts | |||
@@ -16,9 +16,9 @@ import { | |||
16 | Table, | 16 | Table, |
17 | UpdatedAt | 17 | UpdatedAt |
18 | } from 'sequelize-typescript' | 18 | } from 'sequelize-typescript' |
19 | import { getLowercaseExtension } from '@server/helpers/core-utils' | ||
20 | import { ModelCache } from '@server/models/model-cache' | 19 | import { ModelCache } from '@server/models/model-cache' |
21 | import { AttributesOnly } from '@shared/core-utils' | 20 | import { getLowercaseExtension } from '@shared/core-utils' |
21 | import { AttributesOnly } from '@shared/typescript-utils' | ||
22 | import { ActivityIconObject, ActivityPubActorType } from '../../../shared/models/activitypub' | 22 | import { ActivityIconObject, ActivityPubActorType } from '../../../shared/models/activitypub' |
23 | import { ActorImage } from '../../../shared/models/actors/actor-image.model' | 23 | import { ActorImage } from '../../../shared/models/actors/actor-image.model' |
24 | import { activityPubContextify } from '../../helpers/activitypub' | 24 | import { activityPubContextify } from '../../helpers/activitypub' |
diff --git a/server/models/application/application.ts b/server/models/application/application.ts index e3939383b..a479de5d2 100644 --- a/server/models/application/application.ts +++ b/server/models/application/application.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import memoizee from 'memoizee' | 1 | import memoizee from 'memoizee' |
2 | import { AllowNull, Column, Default, DefaultScope, HasOne, IsInt, Model, Table } from 'sequelize-typescript' | 2 | import { AllowNull, Column, Default, DefaultScope, HasOne, IsInt, Model, Table } from 'sequelize-typescript' |
3 | import { AttributesOnly } from '@shared/core-utils' | 3 | import { AttributesOnly } from '@shared/typescript-utils' |
4 | import { AccountModel } from '../account/account' | 4 | import { AccountModel } from '../account/account' |
5 | 5 | ||
6 | export const getServerActor = memoizee(async function () { | 6 | export const getServerActor = memoizee(async function () { |
diff --git a/server/models/oauth/oauth-client.ts b/server/models/oauth/oauth-client.ts index 890954bdb..860fa6f53 100644 --- a/server/models/oauth/oauth-client.ts +++ b/server/models/oauth/oauth-client.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { AllowNull, Column, CreatedAt, DataType, HasMany, Model, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { AllowNull, Column, CreatedAt, DataType, HasMany, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { AttributesOnly } from '@shared/core-utils' | 2 | import { AttributesOnly } from '@shared/typescript-utils' |
3 | import { OAuthTokenModel } from './oauth-token' | 3 | import { OAuthTokenModel } from './oauth-token' |
4 | 4 | ||
5 | @Table({ | 5 | @Table({ |
diff --git a/server/models/oauth/oauth-token.ts b/server/models/oauth/oauth-token.ts index af4b0ec42..f72423190 100644 --- a/server/models/oauth/oauth-token.ts +++ b/server/models/oauth/oauth-token.ts | |||
@@ -15,7 +15,7 @@ import { | |||
15 | import { TokensCache } from '@server/lib/auth/tokens-cache' | 15 | import { TokensCache } from '@server/lib/auth/tokens-cache' |
16 | import { MUserAccountId } from '@server/types/models' | 16 | import { MUserAccountId } from '@server/types/models' |
17 | import { MOAuthTokenUser } from '@server/types/models/oauth/oauth-token' | 17 | import { MOAuthTokenUser } from '@server/types/models/oauth/oauth-token' |
18 | import { AttributesOnly } from '@shared/core-utils' | 18 | import { AttributesOnly } from '@shared/typescript-utils' |
19 | import { logger } from '../../helpers/logger' | 19 | import { logger } from '../../helpers/logger' |
20 | import { AccountModel } from '../account/account' | 20 | import { AccountModel } from '../account/account' |
21 | import { ActorModel } from '../actor/actor' | 21 | import { ActorModel } from '../actor/actor' |
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts index e8d79a3ab..6f84747da 100644 --- a/server/models/redundancy/video-redundancy.ts +++ b/server/models/redundancy/video-redundancy.ts | |||
@@ -16,15 +16,17 @@ import { | |||
16 | } from 'sequelize-typescript' | 16 | } from 'sequelize-typescript' |
17 | import { getServerActor } from '@server/models/application/application' | 17 | import { getServerActor } from '@server/models/application/application' |
18 | import { MActor, MVideoForRedundancyAPI, MVideoRedundancy, MVideoRedundancyAP, MVideoRedundancyVideo } from '@server/types/models' | 18 | import { MActor, MVideoForRedundancyAPI, MVideoRedundancy, MVideoRedundancyAP, MVideoRedundancyVideo } from '@server/types/models' |
19 | import { AttributesOnly } from '@shared/core-utils' | ||
20 | import { VideoRedundanciesTarget } from '@shared/models/redundancy/video-redundancies-filters.model' | ||
21 | import { | 19 | import { |
20 | CacheFileObject, | ||
22 | FileRedundancyInformation, | 21 | FileRedundancyInformation, |
23 | StreamingPlaylistRedundancyInformation, | 22 | StreamingPlaylistRedundancyInformation, |
24 | VideoRedundancy | 23 | VideoPrivacy, |
25 | } from '@shared/models/redundancy/video-redundancy.model' | 24 | VideoRedundanciesTarget, |
26 | import { CacheFileObject, VideoPrivacy } from '../../../shared' | 25 | VideoRedundancy, |
27 | import { VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../shared/models/redundancy' | 26 | VideoRedundancyStrategy, |
27 | VideoRedundancyStrategyWithManual | ||
28 | } from '@shared/models' | ||
29 | import { AttributesOnly } from '@shared/typescript-utils' | ||
28 | import { isTestInstance } from '../../helpers/core-utils' | 30 | import { isTestInstance } from '../../helpers/core-utils' |
29 | import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 31 | import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
30 | import { logger } from '../../helpers/logger' | 32 | import { logger } from '../../helpers/logger' |
diff --git a/server/models/server/plugin.ts b/server/models/server/plugin.ts index a8de64dd4..84f7a14e4 100644 --- a/server/models/server/plugin.ts +++ b/server/models/server/plugin.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { FindAndCountOptions, json, QueryTypes } from 'sequelize' | 1 | import { FindAndCountOptions, json, QueryTypes } from 'sequelize' |
2 | import { AllowNull, Column, CreatedAt, DataType, DefaultScope, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, Column, CreatedAt, DataType, DefaultScope, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { MPlugin, MPluginFormattable } from '@server/types/models' | 3 | import { MPlugin, MPluginFormattable } from '@server/types/models' |
4 | import { AttributesOnly } from '@shared/core-utils' | 4 | import { AttributesOnly } from '@shared/typescript-utils' |
5 | import { PeerTubePlugin, PluginType, RegisterServerSettingOptions } from '../../../shared/models' | 5 | import { PeerTubePlugin, PluginType, RegisterServerSettingOptions } from '../../../shared/models' |
6 | import { | 6 | import { |
7 | isPluginDescriptionValid, | 7 | isPluginDescriptionValid, |
@@ -197,15 +197,11 @@ export class PluginModel extends Model<Partial<AttributesOnly<PluginModel>>> { | |||
197 | if (!c) return undefined | 197 | if (!c) return undefined |
198 | const value = c.value | 198 | const value = c.value |
199 | 199 | ||
200 | if (typeof value === 'string' && value.startsWith('{')) { | 200 | try { |
201 | try { | 201 | return JSON.parse(value) |
202 | return JSON.parse(value) | 202 | } catch { |
203 | } catch { | 203 | return value |
204 | return value | ||
205 | } | ||
206 | } | 204 | } |
207 | |||
208 | return c.value | ||
209 | }) | 205 | }) |
210 | } | 206 | } |
211 | 207 | ||
diff --git a/server/models/server/server-blocklist.ts b/server/models/server/server-blocklist.ts index b3579d589..9f64eeb7f 100644 --- a/server/models/server/server-blocklist.ts +++ b/server/models/server/server-blocklist.ts | |||
@@ -1,10 +1,10 @@ | |||
1 | import { Op } from 'sequelize' | 1 | import { Op, QueryTypes } from 'sequelize' |
2 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { MServerBlocklist, MServerBlocklistAccountServer, MServerBlocklistFormattable } from '@server/types/models' | 3 | import { MServerBlocklist, MServerBlocklistAccountServer, MServerBlocklistFormattable } from '@server/types/models' |
4 | import { AttributesOnly } from '@shared/core-utils' | 4 | import { AttributesOnly } from '@shared/typescript-utils' |
5 | import { ServerBlock } from '@shared/models' | 5 | import { ServerBlock } from '@shared/models' |
6 | import { AccountModel } from '../account/account' | 6 | import { AccountModel } from '../account/account' |
7 | import { getSort, searchAttribute } from '../utils' | 7 | import { createSafeIn, getSort, searchAttribute } from '../utils' |
8 | import { ServerModel } from './server' | 8 | import { ServerModel } from './server' |
9 | 9 | ||
10 | enum ScopeNames { | 10 | enum ScopeNames { |
@@ -76,7 +76,7 @@ export class ServerBlocklistModel extends Model<Partial<AttributesOnly<ServerBlo | |||
76 | }) | 76 | }) |
77 | BlockedServer: ServerModel | 77 | BlockedServer: ServerModel |
78 | 78 | ||
79 | static isServerMutedByMulti (accountIds: number[], targetServerId: number) { | 79 | static isServerMutedByAccounts (accountIds: number[], targetServerId: number) { |
80 | const query = { | 80 | const query = { |
81 | attributes: [ 'accountId', 'id' ], | 81 | attributes: [ 'accountId', 'id' ], |
82 | where: { | 82 | where: { |
@@ -141,6 +141,19 @@ export class ServerBlocklistModel extends Model<Partial<AttributesOnly<ServerBlo | |||
141 | .then(entries => entries.map(e => e.BlockedServer.host)) | 141 | .then(entries => entries.map(e => e.BlockedServer.host)) |
142 | } | 142 | } |
143 | 143 | ||
144 | static getBlockStatus (byAccountIds: number[], hosts: string[]): Promise<{ host: string, accountId: number }[]> { | ||
145 | const rawQuery = `SELECT "server"."host", "serverBlocklist"."accountId" ` + | ||
146 | `FROM "serverBlocklist" ` + | ||
147 | `INNER JOIN "server" ON "server"."id" = "serverBlocklist"."targetServerId" ` + | ||
148 | `WHERE "server"."host" IN (:hosts) ` + | ||
149 | `AND "serverBlocklist"."accountId" IN (${createSafeIn(ServerBlocklistModel.sequelize, byAccountIds)})` | ||
150 | |||
151 | return ServerBlocklistModel.sequelize.query(rawQuery, { | ||
152 | type: QueryTypes.SELECT as QueryTypes.SELECT, | ||
153 | replacements: { hosts } | ||
154 | }) | ||
155 | } | ||
156 | |||
144 | static listForApi (parameters: { | 157 | static listForApi (parameters: { |
145 | start: number | 158 | start: number |
146 | count: number | 159 | count: number |
diff --git a/server/models/server/server.ts b/server/models/server/server.ts index edbe92f73..ef42de090 100644 --- a/server/models/server/server.ts +++ b/server/models/server/server.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { AllowNull, Column, CreatedAt, Default, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, Column, CreatedAt, Default, HasMany, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { MServer, MServerFormattable } from '@server/types/models/server' | 3 | import { MServer, MServerFormattable } from '@server/types/models/server' |
4 | import { AttributesOnly } from '@shared/core-utils' | 4 | import { AttributesOnly } from '@shared/typescript-utils' |
5 | import { isHostValid } from '../../helpers/custom-validators/servers' | 5 | import { isHostValid } from '../../helpers/custom-validators/servers' |
6 | import { ActorModel } from '../actor/actor' | 6 | import { ActorModel } from '../actor/actor' |
7 | import { throwIfNotValid } from '../utils' | 7 | import { throwIfNotValid } from '../utils' |
diff --git a/server/models/server/tracker.ts b/server/models/server/tracker.ts index c09fdd64b..ee087c4a3 100644 --- a/server/models/server/tracker.ts +++ b/server/models/server/tracker.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { AllowNull, BelongsToMany, Column, CreatedAt, Model, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { AllowNull, BelongsToMany, Column, CreatedAt, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { Transaction } from 'sequelize/types' | 2 | import { Transaction } from 'sequelize/types' |
3 | import { MTracker } from '@server/types/models/server/tracker' | 3 | import { MTracker } from '@server/types/models/server/tracker' |
4 | import { AttributesOnly } from '@shared/core-utils' | 4 | import { AttributesOnly } from '@shared/typescript-utils' |
5 | import { VideoModel } from '../video/video' | 5 | import { VideoModel } from '../video/video' |
6 | import { VideoTrackerModel } from './video-tracker' | 6 | import { VideoTrackerModel } from './video-tracker' |
7 | 7 | ||
diff --git a/server/models/server/video-tracker.ts b/server/models/server/video-tracker.ts index c49fbd1c6..f14f3bd7d 100644 --- a/server/models/server/video-tracker.ts +++ b/server/models/server/video-tracker.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { AttributesOnly } from '@shared/core-utils' | 2 | import { AttributesOnly } from '@shared/typescript-utils' |
3 | import { VideoModel } from '../video/video' | 3 | import { VideoModel } from '../video/video' |
4 | import { TrackerModel } from './tracker' | 4 | import { TrackerModel } from './tracker' |
5 | 5 | ||
diff --git a/server/models/user/user-notification-setting.ts b/server/models/user/user-notification-setting.ts index bee7d7851..f03b19e41 100644 --- a/server/models/user/user-notification-setting.ts +++ b/server/models/user/user-notification-setting.ts | |||
@@ -14,7 +14,7 @@ import { | |||
14 | } from 'sequelize-typescript' | 14 | } from 'sequelize-typescript' |
15 | import { TokensCache } from '@server/lib/auth/tokens-cache' | 15 | import { TokensCache } from '@server/lib/auth/tokens-cache' |
16 | import { MNotificationSettingFormattable } from '@server/types/models' | 16 | import { MNotificationSettingFormattable } from '@server/types/models' |
17 | import { AttributesOnly } from '@shared/core-utils' | 17 | import { AttributesOnly } from '@shared/typescript-utils' |
18 | import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model' | 18 | import { UserNotificationSetting, UserNotificationSettingValue } from '../../../shared/models/users/user-notification-setting.model' |
19 | import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' | 19 | import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' |
20 | import { throwIfNotValid } from '../utils' | 20 | import { throwIfNotValid } from '../utils' |
diff --git a/server/models/user/user-notification.ts b/server/models/user/user-notification.ts index 04c5513a9..edad10a55 100644 --- a/server/models/user/user-notification.ts +++ b/server/models/user/user-notification.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | import { FindOptions, ModelIndexesOptions, Op, WhereOptions } from 'sequelize' | 1 | import { FindOptions, ModelIndexesOptions, Op, WhereOptions } from 'sequelize' |
2 | import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { uuidToShort } from '@server/helpers/uuid' | ||
4 | import { UserNotificationIncludes, UserNotificationModelForApi } from '@server/types/models/user' | 3 | import { UserNotificationIncludes, UserNotificationModelForApi } from '@server/types/models/user' |
5 | import { AttributesOnly } from '@shared/core-utils' | 4 | import { uuidToShort } from '@shared/extra-utils' |
6 | import { UserNotification, UserNotificationType } from '../../../shared' | 5 | import { UserNotification, UserNotificationType } from '@shared/models' |
6 | import { AttributesOnly } from '@shared/typescript-utils' | ||
7 | import { isBooleanValid } from '../../helpers/custom-validators/misc' | 7 | import { isBooleanValid } from '../../helpers/custom-validators/misc' |
8 | import { isUserNotificationTypeValid } from '../../helpers/custom-validators/user-notifications' | 8 | import { isUserNotificationTypeValid } from '../../helpers/custom-validators/user-notifications' |
9 | import { AbuseModel } from '../abuse/abuse' | 9 | import { AbuseModel } from '../abuse/abuse' |
diff --git a/server/models/user/user-video-history.ts b/server/models/user/user-video-history.ts index 1aefdf02b..6d9f2e03f 100644 --- a/server/models/user/user-video-history.ts +++ b/server/models/user/user-video-history.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { DestroyOptions, Op, Transaction } from 'sequelize' | 1 | import { DestroyOptions, Op, Transaction } from 'sequelize' |
2 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, IsInt, Model, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, IsInt, Model, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { MUserAccountId, MUserId } from '@server/types/models' | 3 | import { MUserAccountId, MUserId } from '@server/types/models' |
4 | import { AttributesOnly } from '@shared/core-utils' | 4 | import { AttributesOnly } from '@shared/typescript-utils' |
5 | import { VideoModel } from '../video/video' | 5 | import { VideoModel } from '../video/video' |
6 | import { UserModel } from './user' | 6 | import { UserModel } from './user' |
7 | import { getServerActor } from '../application/application' | 7 | import { getServerActor } from '../application/application' |
diff --git a/server/models/user/user.ts b/server/models/user/user.ts index b56f37e55..4ad76e5bc 100644 --- a/server/models/user/user.ts +++ b/server/models/user/user.ts | |||
@@ -31,7 +31,7 @@ import { | |||
31 | MUserWithNotificationSetting, | 31 | MUserWithNotificationSetting, |
32 | MVideoWithRights | 32 | MVideoWithRights |
33 | } from '@server/types/models' | 33 | } from '@server/types/models' |
34 | import { AttributesOnly } from '@shared/core-utils' | 34 | import { AttributesOnly } from '@shared/typescript-utils' |
35 | import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users' | 35 | import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users' |
36 | import { AbuseState, MyUser, UserRight, VideoPlaylistType, VideoPrivacy } from '../../../shared/models' | 36 | import { AbuseState, MyUser, UserRight, VideoPlaylistType, VideoPrivacy } from '../../../shared/models' |
37 | import { User, UserRole } from '../../../shared/models/users' | 37 | import { User, UserRole } from '../../../shared/models/users' |
@@ -55,7 +55,7 @@ import { | |||
55 | isUserVideoQuotaDailyValid, | 55 | isUserVideoQuotaDailyValid, |
56 | isUserVideoQuotaValid, | 56 | isUserVideoQuotaValid, |
57 | isUserVideosHistoryEnabledValid, | 57 | isUserVideosHistoryEnabledValid, |
58 | isUserWebTorrentEnabledValid | 58 | isUserP2PEnabledValid |
59 | } from '../../helpers/custom-validators/users' | 59 | } from '../../helpers/custom-validators/users' |
60 | import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' | 60 | import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto' |
61 | import { DEFAULT_USER_THEME_NAME, NSFW_POLICY_TYPES } from '../../initializers/constants' | 61 | import { DEFAULT_USER_THEME_NAME, NSFW_POLICY_TYPES } from '../../initializers/constants' |
@@ -267,10 +267,9 @@ export class UserModel extends Model<Partial<AttributesOnly<UserModel>>> { | |||
267 | nsfwPolicy: NSFWPolicyType | 267 | nsfwPolicy: NSFWPolicyType |
268 | 268 | ||
269 | @AllowNull(false) | 269 | @AllowNull(false) |
270 | @Default(true) | 270 | @Is('p2pEnabled', value => throwIfNotValid(value, isUserP2PEnabledValid, 'P2P enabled')) |
271 | @Is('UserWebTorrentEnabled', value => throwIfNotValid(value, isUserWebTorrentEnabledValid, 'WebTorrent enabled')) | ||
272 | @Column | 271 | @Column |
273 | webTorrentEnabled: boolean | 272 | p2pEnabled: boolean |
274 | 273 | ||
275 | @AllowNull(false) | 274 | @AllowNull(false) |
276 | @Default(true) | 275 | @Default(true) |
@@ -892,7 +891,11 @@ export class UserModel extends Model<Partial<AttributesOnly<UserModel>>> { | |||
892 | emailVerified: this.emailVerified, | 891 | emailVerified: this.emailVerified, |
893 | 892 | ||
894 | nsfwPolicy: this.nsfwPolicy, | 893 | nsfwPolicy: this.nsfwPolicy, |
895 | webTorrentEnabled: this.webTorrentEnabled, | 894 | |
895 | // FIXME: deprecated in 4.1 | ||
896 | webTorrentEnabled: this.p2pEnabled, | ||
897 | p2pEnabled: this.p2pEnabled, | ||
898 | |||
896 | videosHistoryEnabled: this.videosHistoryEnabled, | 899 | videosHistoryEnabled: this.videosHistoryEnabled, |
897 | autoPlayVideo: this.autoPlayVideo, | 900 | autoPlayVideo: this.autoPlayVideo, |
898 | autoPlayNextVideo: this.autoPlayNextVideo, | 901 | autoPlayNextVideo: this.autoPlayNextVideo, |
diff --git a/server/models/video/formatter/video-format-utils.ts b/server/models/video/formatter/video-format-utils.ts index fd4da68ed..7456f37c5 100644 --- a/server/models/video/formatter/video-format-utils.ts +++ b/server/models/video/formatter/video-format-utils.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { uuidToShort } from '@server/helpers/uuid' | ||
2 | import { generateMagnetUri } from '@server/helpers/webtorrent' | 1 | import { generateMagnetUri } from '@server/helpers/webtorrent' |
3 | import { getLocalVideoFileMetadataUrl } from '@server/lib/video-urls' | 2 | import { getLocalVideoFileMetadataUrl } from '@server/lib/video-urls' |
4 | import { VideoViews } from '@server/lib/video-views' | 3 | import { VideoViews } from '@server/lib/video-views' |
4 | import { uuidToShort } from '@shared/extra-utils' | ||
5 | import { VideoFile, VideosCommonQueryAfterSanitize } from '@shared/models' | 5 | import { VideoFile, VideosCommonQueryAfterSanitize } from '@shared/models' |
6 | import { ActivityTagObject, ActivityUrlObject, VideoObject } from '../../../../shared/models/activitypub/objects' | 6 | import { ActivityTagObject, ActivityUrlObject, VideoObject } from '../../../../shared/models/activitypub/objects' |
7 | import { Video, VideoDetails, VideoInclude } from '../../../../shared/models/videos' | 7 | import { Video, VideoDetails, VideoInclude } from '../../../../shared/models/videos' |
diff --git a/server/models/video/schedule-video-update.ts b/server/models/video/schedule-video-update.ts index d462c20c7..b3cf26966 100644 --- a/server/models/video/schedule-video-update.ts +++ b/server/models/video/schedule-video-update.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { Op, Transaction } from 'sequelize' | 1 | import { Op, Transaction } from 'sequelize' |
2 | import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { MScheduleVideoUpdateFormattable, MScheduleVideoUpdate } from '@server/types/models' | 3 | import { MScheduleVideoUpdateFormattable, MScheduleVideoUpdate } from '@server/types/models' |
4 | import { AttributesOnly } from '@shared/core-utils' | 4 | import { AttributesOnly } from '@shared/typescript-utils' |
5 | import { VideoPrivacy } from '../../../shared/models/videos' | 5 | import { VideoPrivacy } from '../../../shared/models/videos' |
6 | import { VideoModel } from './video' | 6 | import { VideoModel } from './video' |
7 | 7 | ||
diff --git a/server/models/video/sql/videos-id-list-query-builder.ts b/server/models/video/sql/videos-id-list-query-builder.ts index d825225ab..76aafb883 100644 --- a/server/models/video/sql/videos-id-list-query-builder.ts +++ b/server/models/video/sql/videos-id-list-query-builder.ts | |||
@@ -367,9 +367,10 @@ export class VideosIdListQueryBuilder extends AbstractRunQuery { | |||
367 | ' WHERE "videoShare"."videoId" = "video"."id"' + | 367 | ' WHERE "videoShare"."videoId" = "video"."id"' + |
368 | ' )' + | 368 | ' )' + |
369 | ' OR' + | 369 | ' OR' + |
370 | ' EXISTS (' + // Videos published by accounts we follow | 370 | ' EXISTS (' + // Videos published by channels or accounts we follow |
371 | ' SELECT 1 from "actorFollow" ' + | 371 | ' SELECT 1 from "actorFollow" ' + |
372 | ' WHERE "actorFollow"."targetActorId" = "account"."actorId" AND "actorFollow"."actorId" = :followerActorId ' + | 372 | ' WHERE ("actorFollow"."targetActorId" = "account"."actorId" OR "actorFollow"."targetActorId" = "videoChannel"."actorId") ' + |
373 | ' AND "actorFollow"."actorId" = :followerActorId ' + | ||
373 | ' AND "actorFollow"."state" = \'accepted\'' + | 374 | ' AND "actorFollow"."state" = \'accepted\'' + |
374 | ' )' | 375 | ' )' |
375 | 376 | ||
diff --git a/server/models/video/tag.ts b/server/models/video/tag.ts index 61dfb224d..7900e070d 100644 --- a/server/models/video/tag.ts +++ b/server/models/video/tag.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { col, fn, QueryTypes, Transaction } from 'sequelize' | 1 | import { col, fn, QueryTypes, Transaction } from 'sequelize' |
2 | import { AllowNull, BelongsToMany, Column, CreatedAt, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsToMany, Column, CreatedAt, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { MTag } from '@server/types/models' | 3 | import { MTag } from '@server/types/models' |
4 | import { AttributesOnly } from '@shared/core-utils' | 4 | import { AttributesOnly } from '@shared/typescript-utils' |
5 | import { VideoPrivacy, VideoState } from '../../../shared/models/videos' | 5 | import { VideoPrivacy, VideoState } from '../../../shared/models/videos' |
6 | import { isVideoTagValid } from '../../helpers/custom-validators/videos' | 6 | import { isVideoTagValid } from '../../helpers/custom-validators/videos' |
7 | import { throwIfNotValid } from '../utils' | 7 | import { throwIfNotValid } from '../utils' |
diff --git a/server/models/video/thumbnail.ts b/server/models/video/thumbnail.ts index 3388478d9..05c58cf19 100644 --- a/server/models/video/thumbnail.ts +++ b/server/models/video/thumbnail.ts | |||
@@ -17,7 +17,7 @@ import { | |||
17 | } from 'sequelize-typescript' | 17 | } from 'sequelize-typescript' |
18 | import { afterCommitIfTransaction } from '@server/helpers/database-utils' | 18 | import { afterCommitIfTransaction } from '@server/helpers/database-utils' |
19 | import { MThumbnail, MThumbnailVideo, MVideo } from '@server/types/models' | 19 | import { MThumbnail, MThumbnailVideo, MVideo } from '@server/types/models' |
20 | import { AttributesOnly } from '@shared/core-utils' | 20 | import { AttributesOnly } from '@shared/typescript-utils' |
21 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' | 21 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' |
22 | import { logger } from '../../helpers/logger' | 22 | import { logger } from '../../helpers/logger' |
23 | import { CONFIG } from '../../initializers/config' | 23 | import { CONFIG } from '../../initializers/config' |
diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts index 98f4ec9c5..1cd8224c0 100644 --- a/server/models/video/video-blacklist.ts +++ b/server/models/video/video-blacklist.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { FindOptions } from 'sequelize' | 1 | import { FindOptions } from 'sequelize' |
2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { MVideoBlacklist, MVideoBlacklistFormattable } from '@server/types/models' | 3 | import { MVideoBlacklist, MVideoBlacklistFormattable } from '@server/types/models' |
4 | import { AttributesOnly } from '@shared/core-utils' | 4 | import { AttributesOnly } from '@shared/typescript-utils' |
5 | import { VideoBlacklist, VideoBlacklistType } from '../../../shared/models/videos' | 5 | import { VideoBlacklist, VideoBlacklistType } from '../../../shared/models/videos' |
6 | import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist' | 6 | import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../helpers/custom-validators/video-blacklist' |
7 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | 7 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' |
diff --git a/server/models/video/video-caption.ts b/server/models/video/video-caption.ts index d24be56c3..6b240f116 100644 --- a/server/models/video/video-caption.ts +++ b/server/models/video/video-caption.ts | |||
@@ -15,9 +15,9 @@ import { | |||
15 | Table, | 15 | Table, |
16 | UpdatedAt | 16 | UpdatedAt |
17 | } from 'sequelize-typescript' | 17 | } from 'sequelize-typescript' |
18 | import { buildUUID } from '@server/helpers/uuid' | ||
19 | import { MVideo, MVideoCaption, MVideoCaptionFormattable, MVideoCaptionVideo } from '@server/types/models' | 18 | import { MVideo, MVideoCaption, MVideoCaptionFormattable, MVideoCaptionVideo } from '@server/types/models' |
20 | import { AttributesOnly } from '@shared/core-utils' | 19 | import { buildUUID } from '@shared/extra-utils' |
20 | import { AttributesOnly } from '@shared/typescript-utils' | ||
21 | import { VideoCaption } from '../../../shared/models/videos/caption/video-caption.model' | 21 | import { VideoCaption } from '../../../shared/models/videos/caption/video-caption.model' |
22 | import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions' | 22 | import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions' |
23 | import { logger } from '../../helpers/logger' | 23 | import { logger } from '../../helpers/logger' |
diff --git a/server/models/video/video-change-ownership.ts b/server/models/video/video-change-ownership.ts index 7d20a954d..1a1b8c88d 100644 --- a/server/models/video/video-change-ownership.ts +++ b/server/models/video/video-change-ownership.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { MVideoChangeOwnershipFormattable, MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership' | 2 | import { MVideoChangeOwnershipFormattable, MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership' |
3 | import { AttributesOnly } from '@shared/core-utils' | 3 | import { AttributesOnly } from '@shared/typescript-utils' |
4 | import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos' | 4 | import { VideoChangeOwnership, VideoChangeOwnershipStatus } from '../../../shared/models/videos' |
5 | import { AccountModel } from '../account/account' | 5 | import { AccountModel } from '../account/account' |
6 | import { getSort } from '../utils' | 6 | import { getSort } from '../utils' |
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index b652d8531..2c6669bcb 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts | |||
@@ -17,8 +17,10 @@ import { | |||
17 | Table, | 17 | Table, |
18 | UpdatedAt | 18 | UpdatedAt |
19 | } from 'sequelize-typescript' | 19 | } from 'sequelize-typescript' |
20 | import { CONFIG } from '@server/initializers/config' | ||
20 | import { MAccountActor } from '@server/types/models' | 21 | import { MAccountActor } from '@server/types/models' |
21 | import { AttributesOnly, pick } from '@shared/core-utils' | 22 | import { pick } from '@shared/core-utils' |
23 | import { AttributesOnly } from '@shared/typescript-utils' | ||
22 | import { ActivityPubActor } from '../../../shared/models/activitypub' | 24 | import { ActivityPubActor } from '../../../shared/models/activitypub' |
23 | import { VideoChannel, VideoChannelSummary } from '../../../shared/models/videos' | 25 | import { VideoChannel, VideoChannelSummary } from '../../../shared/models/videos' |
24 | import { | 26 | import { |
@@ -44,7 +46,6 @@ import { setAsUpdated } from '../shared' | |||
44 | import { buildServerIdsFollowedBy, buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils' | 46 | import { buildServerIdsFollowedBy, buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils' |
45 | import { VideoModel } from './video' | 47 | import { VideoModel } from './video' |
46 | import { VideoPlaylistModel } from './video-playlist' | 48 | import { VideoPlaylistModel } from './video-playlist' |
47 | import { CONFIG } from '@server/initializers/config' | ||
48 | 49 | ||
49 | export enum ScopeNames { | 50 | export enum ScopeNames { |
50 | FOR_API = 'FOR_API', | 51 | FOR_API = 'FOR_API', |
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index c89279c65..7f28b86b4 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts | |||
@@ -16,7 +16,7 @@ import { | |||
16 | } from 'sequelize-typescript' | 16 | } from 'sequelize-typescript' |
17 | import { getServerActor } from '@server/models/application/application' | 17 | import { getServerActor } from '@server/models/application/application' |
18 | import { MAccount, MAccountId, MUserAccountId } from '@server/types/models' | 18 | import { MAccount, MAccountId, MUserAccountId } from '@server/types/models' |
19 | import { AttributesOnly } from '@shared/core-utils' | 19 | import { AttributesOnly } from '@shared/typescript-utils' |
20 | import { VideoPrivacy } from '@shared/models' | 20 | import { VideoPrivacy } from '@shared/models' |
21 | import { ActivityTagObject, ActivityTombstoneObject } from '../../../shared/models/activitypub/objects/common-objects' | 21 | import { ActivityTagObject, ActivityTombstoneObject } from '../../../shared/models/activitypub/objects/common-objects' |
22 | import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' | 22 | import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' |
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts index 87311c0ed..6f03fae3a 100644 --- a/server/models/video/video-file.ts +++ b/server/models/video/video-file.ts | |||
@@ -26,8 +26,8 @@ import { extractVideo } from '@server/helpers/video' | |||
26 | import { getHLSPublicFileUrl, getWebTorrentPublicFileUrl } from '@server/lib/object-storage' | 26 | import { getHLSPublicFileUrl, getWebTorrentPublicFileUrl } from '@server/lib/object-storage' |
27 | import { getFSTorrentFilePath } from '@server/lib/paths' | 27 | import { getFSTorrentFilePath } from '@server/lib/paths' |
28 | import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoWithHost } from '@server/types/models' | 28 | import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoWithHost } from '@server/types/models' |
29 | import { AttributesOnly } from '@shared/core-utils' | 29 | import { VideoResolution, VideoStorage } from '@shared/models' |
30 | import { VideoStorage } from '@shared/models' | 30 | import { AttributesOnly } from '@shared/typescript-utils' |
31 | import { | 31 | import { |
32 | isVideoFileExtnameValid, | 32 | isVideoFileExtnameValid, |
33 | isVideoFileInfoHashValid, | 33 | isVideoFileInfoHashValid, |
@@ -39,7 +39,6 @@ import { | |||
39 | LAZY_STATIC_PATHS, | 39 | LAZY_STATIC_PATHS, |
40 | MEMOIZE_LENGTH, | 40 | MEMOIZE_LENGTH, |
41 | MEMOIZE_TTL, | 41 | MEMOIZE_TTL, |
42 | MIMETYPES, | ||
43 | STATIC_DOWNLOAD_PATHS, | 42 | STATIC_DOWNLOAD_PATHS, |
44 | STATIC_PATHS, | 43 | STATIC_PATHS, |
45 | WEBSERVER | 44 | WEBSERVER |
@@ -448,7 +447,7 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel> | |||
448 | } | 447 | } |
449 | 448 | ||
450 | isAudio () { | 449 | isAudio () { |
451 | return !!MIMETYPES.AUDIO.EXT_MIMETYPE[this.extname] | 450 | return this.resolution === VideoResolution.H_NOVIDEO |
452 | } | 451 | } |
453 | 452 | ||
454 | isLive () { | 453 | isLive () { |
diff --git a/server/models/video/video-import.ts b/server/models/video/video-import.ts index 5c73fb07c..c5c1a10f4 100644 --- a/server/models/video/video-import.ts +++ b/server/models/video/video-import.ts | |||
@@ -15,8 +15,8 @@ import { | |||
15 | } from 'sequelize-typescript' | 15 | } from 'sequelize-typescript' |
16 | import { afterCommitIfTransaction } from '@server/helpers/database-utils' | 16 | import { afterCommitIfTransaction } from '@server/helpers/database-utils' |
17 | import { MVideoImportDefault, MVideoImportFormattable } from '@server/types/models/video/video-import' | 17 | import { MVideoImportDefault, MVideoImportFormattable } from '@server/types/models/video/video-import' |
18 | import { AttributesOnly } from '@shared/core-utils' | 18 | import { VideoImport, VideoImportState } from '@shared/models' |
19 | import { VideoImport, VideoImportState } from '../../../shared' | 19 | import { AttributesOnly } from '@shared/typescript-utils' |
20 | import { isVideoImportStateValid, isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports' | 20 | import { isVideoImportStateValid, isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports' |
21 | import { isVideoMagnetUriValid } from '../../helpers/custom-validators/videos' | 21 | import { isVideoMagnetUriValid } from '../../helpers/custom-validators/videos' |
22 | import { CONSTRAINTS_FIELDS, VIDEO_IMPORT_STATES } from '../../initializers/constants' | 22 | import { CONSTRAINTS_FIELDS, VIDEO_IMPORT_STATES } from '../../initializers/constants' |
diff --git a/server/models/video/video-job-info.ts b/server/models/video/video-job-info.ts index 7da5128d7..7497addf1 100644 --- a/server/models/video/video-job-info.ts +++ b/server/models/video/video-job-info.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { Op, QueryTypes, Transaction } from 'sequelize' | 1 | import { Op, QueryTypes, Transaction } from 'sequelize' |
2 | import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, IsInt, Model, Table, Unique, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, IsInt, Model, Table, Unique, UpdatedAt } from 'sequelize-typescript' |
3 | import { AttributesOnly } from '@shared/core-utils' | 3 | import { AttributesOnly } from '@shared/typescript-utils' |
4 | import { VideoModel } from './video' | 4 | import { VideoModel } from './video' |
5 | 5 | ||
6 | export type VideoJobInfoColumnType = 'pendingMove' | 'pendingTranscode' | 6 | export type VideoJobInfoColumnType = 'pendingMove' | 'pendingTranscode' |
@@ -99,4 +99,19 @@ export class VideoJobInfoModel extends Model<Partial<AttributesOnly<VideoJobInfo | |||
99 | 99 | ||
100 | return pendingMove | 100 | return pendingMove |
101 | } | 101 | } |
102 | |||
103 | static async abortAllTasks (videoUUID: string, column: VideoJobInfoColumnType): Promise<void> { | ||
104 | const options = { type: QueryTypes.UPDATE as QueryTypes.UPDATE, bind: { videoUUID } } | ||
105 | |||
106 | await VideoJobInfoModel.sequelize.query(` | ||
107 | UPDATE | ||
108 | "videoJobInfo" | ||
109 | SET | ||
110 | "${column}" = 0, | ||
111 | "updatedAt" = NOW() | ||
112 | FROM "video" | ||
113 | WHERE | ||
114 | "video"."id" = "videoJobInfo"."videoId" AND "video"."uuid" = $videoUUID | ||
115 | `, options) | ||
116 | } | ||
102 | } | 117 | } |
diff --git a/server/models/video/video-live.ts b/server/models/video/video-live.ts index 0bc8da022..e3fdcc0ba 100644 --- a/server/models/video/video-live.ts +++ b/server/models/video/video-live.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, DefaultScope, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, DefaultScope, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { WEBSERVER } from '@server/initializers/constants' | 2 | import { WEBSERVER } from '@server/initializers/constants' |
3 | import { MVideoLive, MVideoLiveVideo } from '@server/types/models' | 3 | import { MVideoLive, MVideoLiveVideo } from '@server/types/models' |
4 | import { AttributesOnly } from '@shared/core-utils' | 4 | import { AttributesOnly } from '@shared/typescript-utils' |
5 | import { LiveVideo, VideoState } from '@shared/models' | 5 | import { LiveVideo, VideoState } from '@shared/models' |
6 | import { VideoModel } from './video' | 6 | import { VideoModel } from './video' |
7 | import { VideoBlacklistModel } from './video-blacklist' | 7 | import { VideoBlacklistModel } from './video-blacklist' |
diff --git a/server/models/video/video-playlist-element.ts b/server/models/video/video-playlist-element.ts index 82c832188..e20e32f8b 100644 --- a/server/models/video/video-playlist-element.ts +++ b/server/models/video/video-playlist-element.ts | |||
@@ -32,7 +32,7 @@ import { AccountModel } from '../account/account' | |||
32 | import { getSort, throwIfNotValid } from '../utils' | 32 | import { getSort, throwIfNotValid } from '../utils' |
33 | import { ForAPIOptions, ScopeNames as VideoScopeNames, VideoModel } from './video' | 33 | import { ForAPIOptions, ScopeNames as VideoScopeNames, VideoModel } from './video' |
34 | import { VideoPlaylistModel } from './video-playlist' | 34 | import { VideoPlaylistModel } from './video-playlist' |
35 | import { AttributesOnly } from '@shared/core-utils' | 35 | import { AttributesOnly } from '@shared/typescript-utils' |
36 | 36 | ||
37 | @Table({ | 37 | @Table({ |
38 | tableName: 'videoPlaylistElement', | 38 | tableName: 'videoPlaylistElement', |
@@ -276,7 +276,7 @@ export class VideoPlaylistElementModel extends Model<Partial<AttributesOnly<Vide | |||
276 | } | 276 | } |
277 | 277 | ||
278 | const positionQuery = Sequelize.literal(`${newPosition} + "position" - ${firstPosition}`) | 278 | const positionQuery = Sequelize.literal(`${newPosition} + "position" - ${firstPosition}`) |
279 | return VideoPlaylistElementModel.update({ position: positionQuery as any }, query) | 279 | return VideoPlaylistElementModel.update({ position: positionQuery }, query) |
280 | } | 280 | } |
281 | 281 | ||
282 | static increasePositionOf ( | 282 | static increasePositionOf ( |
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index 630684a88..0d43c795e 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts | |||
@@ -17,9 +17,10 @@ import { | |||
17 | Table, | 17 | Table, |
18 | UpdatedAt | 18 | UpdatedAt |
19 | } from 'sequelize-typescript' | 19 | } from 'sequelize-typescript' |
20 | import { buildUUID, uuidToShort } from '@server/helpers/uuid' | ||
21 | import { MAccountId, MChannelId } from '@server/types/models' | 20 | import { MAccountId, MChannelId } from '@server/types/models' |
22 | import { AttributesOnly, buildPlaylistEmbedPath, buildPlaylistWatchPath, pick } from '@shared/core-utils' | 21 | import { buildPlaylistEmbedPath, buildPlaylistWatchPath, pick } from '@shared/core-utils' |
22 | import { buildUUID, uuidToShort } from '@shared/extra-utils' | ||
23 | import { AttributesOnly } from '@shared/typescript-utils' | ||
23 | import { ActivityIconObject } from '../../../shared/models/activitypub/objects' | 24 | import { ActivityIconObject } from '../../../shared/models/activitypub/objects' |
24 | import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object' | 25 | import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object' |
25 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' | 26 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' |
diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index 505c305e2..f6659b992 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { literal, Op, QueryTypes, Transaction } from 'sequelize' | 1 | import { literal, Op, QueryTypes, Transaction } from 'sequelize' |
2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { AttributesOnly } from '@shared/core-utils' | 3 | import { AttributesOnly } from '@shared/typescript-utils' |
4 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 4 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
5 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' | 5 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' |
6 | import { MActorDefault } from '../../types/models' | 6 | import { MActorDefault } from '../../types/models' |
diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts index 4643c5452..9957ffee3 100644 --- a/server/models/video/video-streaming-playlist.ts +++ b/server/models/video/video-streaming-playlist.ts | |||
@@ -18,10 +18,10 @@ import { | |||
18 | import { getHLSPublicFileUrl } from '@server/lib/object-storage' | 18 | import { getHLSPublicFileUrl } from '@server/lib/object-storage' |
19 | import { VideoFileModel } from '@server/models/video/video-file' | 19 | import { VideoFileModel } from '@server/models/video/video-file' |
20 | import { MStreamingPlaylist, MVideo } from '@server/types/models' | 20 | import { MStreamingPlaylist, MVideo } from '@server/types/models' |
21 | import { AttributesOnly } from '@shared/core-utils' | 21 | import { sha1 } from '@shared/extra-utils' |
22 | import { VideoStorage } from '@shared/models' | 22 | import { VideoStorage } from '@shared/models' |
23 | import { AttributesOnly } from '@shared/typescript-utils' | ||
23 | import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' | 24 | import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' |
24 | import { sha1 } from '../../helpers/core-utils' | ||
25 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 25 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
26 | import { isArrayOf } from '../../helpers/custom-validators/misc' | 26 | import { isArrayOf } from '../../helpers/custom-validators/misc' |
27 | import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' | 27 | import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' |
@@ -198,6 +198,15 @@ export class VideoStreamingPlaylistModel extends Model<Partial<AttributesOnly<Vi | |||
198 | return Object.assign(playlist, { videoId: video.id, Video: video }) | 198 | return Object.assign(playlist, { videoId: video.id, Video: video }) |
199 | } | 199 | } |
200 | 200 | ||
201 | static doesOwnedHLSPlaylistExist (videoUUID: string) { | ||
202 | const query = `SELECT 1 FROM "videoStreamingPlaylist" ` + | ||
203 | `INNER JOIN "video" ON "video"."id" = "videoStreamingPlaylist"."videoId" ` + | ||
204 | `AND "video"."remote" IS FALSE AND "video"."uuid" = $videoUUID ` + | ||
205 | `AND "storage" = ${VideoStorage.FILE_SYSTEM} LIMIT 1` | ||
206 | |||
207 | return doesExist(query, { videoUUID }) | ||
208 | } | ||
209 | |||
201 | assignP2PMediaLoaderInfoHashes (video: MVideo, files: unknown[]) { | 210 | assignP2PMediaLoaderInfoHashes (video: MVideo, files: unknown[]) { |
202 | const masterPlaylistUrl = this.getMasterPlaylistUrl(video) | 211 | const masterPlaylistUrl = this.getMasterPlaylistUrl(video) |
203 | 212 | ||
diff --git a/server/models/video/video-tag.ts b/server/models/video/video-tag.ts index 1285d375b..7e880c968 100644 --- a/server/models/video/video-tag.ts +++ b/server/models/video/video-tag.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { Column, CreatedAt, ForeignKey, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { AttributesOnly } from '@shared/core-utils' | 2 | import { AttributesOnly } from '@shared/typescript-utils' |
3 | import { TagModel } from './tag' | 3 | import { TagModel } from './tag' |
4 | import { VideoModel } from './video' | 4 | import { VideoModel } from './video' |
5 | 5 | ||
diff --git a/server/models/video/video-view.ts b/server/models/video/video-view.ts index b51f0f84d..d72df100f 100644 --- a/server/models/video/video-view.ts +++ b/server/models/video/video-view.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { literal, Op } from 'sequelize' | 1 | import { literal, Op } from 'sequelize' |
2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Model, Table } from 'sequelize-typescript' | 2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Model, Table } from 'sequelize-typescript' |
3 | import { AttributesOnly } from '@shared/core-utils' | 3 | import { AttributesOnly } from '@shared/typescript-utils' |
4 | import { VideoModel } from './video' | 4 | import { VideoModel } from './video' |
5 | 5 | ||
6 | @Table({ | 6 | @Table({ |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 1050463d2..12b937574 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -25,7 +25,6 @@ import { | |||
25 | UpdatedAt | 25 | UpdatedAt |
26 | } from 'sequelize-typescript' | 26 | } from 'sequelize-typescript' |
27 | import { buildNSFWFilter } from '@server/helpers/express-utils' | 27 | import { buildNSFWFilter } from '@server/helpers/express-utils' |
28 | import { uuidToShort } from '@server/helpers/uuid' | ||
29 | import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' | 28 | import { getPrivaciesForFederation, isPrivacyForFederation, isStateForFederation } from '@server/helpers/video' |
30 | import { LiveManager } from '@server/lib/live/live-manager' | 29 | import { LiveManager } from '@server/lib/live/live-manager' |
31 | import { removeHLSObjectStorage, removeWebTorrentObjectStorage } from '@server/lib/object-storage' | 30 | import { removeHLSObjectStorage, removeWebTorrentObjectStorage } from '@server/lib/object-storage' |
@@ -33,13 +32,24 @@ import { getHLSDirectory, getHLSRedundancyDirectory } from '@server/lib/paths' | |||
33 | import { VideoPathManager } from '@server/lib/video-path-manager' | 32 | import { VideoPathManager } from '@server/lib/video-path-manager' |
34 | import { getServerActor } from '@server/models/application/application' | 33 | import { getServerActor } from '@server/models/application/application' |
35 | import { ModelCache } from '@server/models/model-cache' | 34 | import { ModelCache } from '@server/models/model-cache' |
36 | import { AttributesOnly, buildVideoEmbedPath, buildVideoWatchPath, pick } from '@shared/core-utils' | 35 | import { buildVideoEmbedPath, buildVideoWatchPath, pick } from '@shared/core-utils' |
37 | import { VideoFile, VideoInclude } from '@shared/models' | 36 | import { ffprobePromise, getAudioStream, uuidToShort } from '@shared/extra-utils' |
38 | import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared' | 37 | import { |
39 | import { VideoObject } from '../../../shared/models/activitypub/objects' | 38 | ResultList, |
40 | import { Video, VideoDetails, VideoRateType, VideoStorage } from '../../../shared/models/videos' | 39 | ThumbnailType, |
41 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' | 40 | UserRight, |
42 | import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' | 41 | Video, |
42 | VideoDetails, | ||
43 | VideoFile, | ||
44 | VideoInclude, | ||
45 | VideoObject, | ||
46 | VideoPrivacy, | ||
47 | VideoRateType, | ||
48 | VideoState, | ||
49 | VideoStorage, | ||
50 | VideoStreamingPlaylistType | ||
51 | } from '@shared/models' | ||
52 | import { AttributesOnly } from '@shared/typescript-utils' | ||
43 | import { peertubeTruncate } from '../../helpers/core-utils' | 53 | import { peertubeTruncate } from '../../helpers/core-utils' |
44 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 54 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
45 | import { exists, isBooleanValid } from '../../helpers/custom-validators/misc' | 55 | import { exists, isBooleanValid } from '../../helpers/custom-validators/misc' |
@@ -1668,12 +1678,20 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1668 | return peertubeTruncate(this.description, { length: maxLength }) | 1678 | return peertubeTruncate(this.description, { length: maxLength }) |
1669 | } | 1679 | } |
1670 | 1680 | ||
1671 | getMaxQualityResolution () { | 1681 | getMaxQualityFileInfo () { |
1672 | const file = this.getMaxQualityFile() | 1682 | const file = this.getMaxQualityFile() |
1673 | const videoOrPlaylist = file.getVideoOrStreamingPlaylist() | 1683 | const videoOrPlaylist = file.getVideoOrStreamingPlaylist() |
1674 | 1684 | ||
1675 | return VideoPathManager.Instance.makeAvailableVideoFile(file.withVideoOrPlaylist(videoOrPlaylist), originalFilePath => { | 1685 | return VideoPathManager.Instance.makeAvailableVideoFile(file.withVideoOrPlaylist(videoOrPlaylist), async originalFilePath => { |
1676 | return getVideoFileResolution(originalFilePath) | 1686 | const probe = await ffprobePromise(originalFilePath) |
1687 | |||
1688 | const { audioStream } = await getAudioStream(originalFilePath, probe) | ||
1689 | |||
1690 | return { | ||
1691 | audioStream, | ||
1692 | |||
1693 | ...await getVideoFileResolution(originalFilePath, probe) | ||
1694 | } | ||
1677 | }) | 1695 | }) |
1678 | } | 1696 | } |
1679 | 1697 | ||