Fix multiple server tests
This commit is contained in:
parent
bfbd912886
commit
970ceac0a6
|
@ -44,6 +44,21 @@
|
||||||
"buildOptimizer": true,
|
"buildOptimizer": true,
|
||||||
"serviceWorker": true,
|
"serviceWorker": true,
|
||||||
"ngswConfigPath": "src/ngsw-config.json",
|
"ngswConfigPath": "src/ngsw-config.json",
|
||||||
|
"budgets": [
|
||||||
|
{
|
||||||
|
"type": "initial",
|
||||||
|
"type": "initial",
|
||||||
|
"maximumWarning": "2mb",
|
||||||
|
"maximumWarning": "2mb",
|
||||||
|
"maximumError": "5mb"
|
||||||
|
"maximumError": "5mb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "anyComponentStyle",
|
||||||
|
"maximumWarning": "6kb",
|
||||||
|
"maximumError": "10kb"
|
||||||
|
}
|
||||||
|
],
|
||||||
"fileReplacements": [
|
"fileReplacements": [
|
||||||
{
|
{
|
||||||
"replace": "src/environments/environment.ts",
|
"replace": "src/environments/environment.ts",
|
||||||
|
|
|
@ -29,20 +29,21 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct
|
||||||
const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject })
|
const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject })
|
||||||
|
|
||||||
return sequelizeTypescript.transaction(async t => {
|
return sequelizeTypescript.transaction(async t => {
|
||||||
const rate = {
|
const url = getVideoDislikeActivityPubUrl(byActor, video)
|
||||||
|
|
||||||
|
const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url)
|
||||||
|
if (existingRate && existingRate.type === 'dislike') return
|
||||||
|
|
||||||
|
await AccountVideoRateModel.create({
|
||||||
type: 'dislike' as 'dislike',
|
type: 'dislike' as 'dislike',
|
||||||
videoId: video.id,
|
videoId: video.id,
|
||||||
accountId: byAccount.id
|
accountId: byAccount.id,
|
||||||
}
|
url
|
||||||
|
}, { transaction: t })
|
||||||
|
|
||||||
const [ , created ] = await AccountVideoRateModel.findOrCreate({
|
await video.increment('dislikes', { transaction: t })
|
||||||
where: rate,
|
|
||||||
defaults: Object.assign({}, rate, { url: getVideoDislikeActivityPubUrl(byActor, video) }),
|
|
||||||
transaction: t
|
|
||||||
})
|
|
||||||
if (created === true) await video.increment('dislikes', { transaction: t })
|
|
||||||
|
|
||||||
if (video.isOwned() && created === true) {
|
if (video.isOwned()) {
|
||||||
// Don't resend the activity to the sender
|
// Don't resend the activity to the sender
|
||||||
const exceptions = [ byActor ]
|
const exceptions = [ byActor ]
|
||||||
|
|
||||||
|
|
|
@ -29,19 +29,21 @@ async function processLikeVideo (byActor: ActorModel, activity: ActivityLike) {
|
||||||
const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoUrl })
|
const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoUrl })
|
||||||
|
|
||||||
return sequelizeTypescript.transaction(async t => {
|
return sequelizeTypescript.transaction(async t => {
|
||||||
const rate = {
|
const url = getVideoLikeActivityPubUrl(byActor, video)
|
||||||
|
|
||||||
|
const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url)
|
||||||
|
if (existingRate && existingRate.type === 'like') return
|
||||||
|
|
||||||
|
await AccountVideoRateModel.create({
|
||||||
type: 'like' as 'like',
|
type: 'like' as 'like',
|
||||||
videoId: video.id,
|
videoId: video.id,
|
||||||
accountId: byAccount.id
|
accountId: byAccount.id,
|
||||||
}
|
url
|
||||||
const [ , created ] = await AccountVideoRateModel.findOrCreate({
|
}, { transaction: t })
|
||||||
where: rate,
|
|
||||||
defaults: Object.assign({}, rate, { url: getVideoLikeActivityPubUrl(byActor, video) }),
|
|
||||||
transaction: t
|
|
||||||
})
|
|
||||||
if (created === true) await video.increment('likes', { transaction: t })
|
|
||||||
|
|
||||||
if (video.isOwned() && created === true) {
|
await video.increment('likes', { transaction: t })
|
||||||
|
|
||||||
|
if (video.isOwned()) {
|
||||||
// Don't resend the activity to the sender
|
// Don't resend the activity to the sender
|
||||||
const exceptions = [ byActor ]
|
const exceptions = [ byActor ]
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ async function addVideoComment (videoInstance: VideoModel, commentUrl: string) {
|
||||||
})
|
})
|
||||||
|
|
||||||
if (sanitizeAndCheckVideoCommentObject(body) === false) {
|
if (sanitizeAndCheckVideoCommentObject(body) === false) {
|
||||||
logger.debug('Remote video comment JSON is not valid.', { body })
|
logger.debug('Remote video comment JSON %s is not valid.', commentUrl, { body })
|
||||||
return { created: false }
|
return { created: false }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,10 @@ async function createVideoComment (obj: {
|
||||||
inReplyToCommentId,
|
inReplyToCommentId,
|
||||||
videoId: obj.video.id,
|
videoId: obj.video.id,
|
||||||
accountId: obj.account.id,
|
accountId: obj.account.id,
|
||||||
url: 'fake url'
|
url: new Date().toISOString()
|
||||||
}, { transaction: t, validate: false } as any) // FIXME: sequelize typings
|
}, { transaction: t, validate: false })
|
||||||
|
|
||||||
comment.set('url', getVideoCommentActivityPubUrl(obj.video, comment))
|
comment.url = getVideoCommentActivityPubUrl(obj.video, comment)
|
||||||
|
|
||||||
const savedComment = await comment.save({ transaction: t })
|
const savedComment = await comment.save({ transaction: t })
|
||||||
savedComment.InReplyToVideoComment = obj.inReplyToComment
|
savedComment.InReplyToVideoComment = obj.inReplyToComment
|
||||||
|
|
|
@ -89,6 +89,25 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
|
||||||
return AccountVideoRateModel.findOne(options)
|
return AccountVideoRateModel.findOne(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static loadByAccountAndVideoOrUrl (accountId: number, videoId: number, url: string, transaction?: Transaction) {
|
||||||
|
const options: FindOptions = {
|
||||||
|
where: {
|
||||||
|
[ Op.or]: [
|
||||||
|
{
|
||||||
|
accountId,
|
||||||
|
videoId
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (transaction) options.transaction = transaction
|
||||||
|
|
||||||
|
return AccountVideoRateModel.findOne(options)
|
||||||
|
}
|
||||||
|
|
||||||
static listByAccountForApi (options: {
|
static listByAccountForApi (options: {
|
||||||
start: number,
|
start: number,
|
||||||
count: number,
|
count: number,
|
||||||
|
@ -202,6 +221,23 @@ export class AccountVideoRateModel extends Model<AccountVideoRateModel> {
|
||||||
videoId,
|
videoId,
|
||||||
type
|
type
|
||||||
},
|
},
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: AccountModel.unscoped(),
|
||||||
|
required: true,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: ActorModel.unscoped(),
|
||||||
|
required: true,
|
||||||
|
where: {
|
||||||
|
serverId: {
|
||||||
|
[Op.ne]: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
transaction: t
|
transaction: t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -472,7 +472,24 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
|
||||||
[Op.lt]: beforeUpdatedAt
|
[Op.lt]: beforeUpdatedAt
|
||||||
},
|
},
|
||||||
videoId
|
videoId
|
||||||
}
|
},
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
model: AccountModel.unscoped(),
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
model: ActorModel.unscoped(),
|
||||||
|
where: {
|
||||||
|
serverId: {
|
||||||
|
[Op.ne]: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
return VideoCommentModel.destroy(query)
|
return VideoCommentModel.destroy(query)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import * as Sequelize from 'sequelize'
|
|
||||||
import * as Bluebird from 'bluebird'
|
import * as Bluebird from 'bluebird'
|
||||||
import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
|
import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
|
||||||
import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
|
import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
|
||||||
|
@ -8,6 +7,7 @@ import { ActorModel } from '../activitypub/actor'
|
||||||
import { throwIfNotValid } from '../utils'
|
import { throwIfNotValid } from '../utils'
|
||||||
import { VideoModel } from './video'
|
import { VideoModel } from './video'
|
||||||
import { VideoChannelModel } from './video-channel'
|
import { VideoChannelModel } from './video-channel'
|
||||||
|
import { Op, Transaction } from 'sequelize'
|
||||||
|
|
||||||
enum ScopeNames {
|
enum ScopeNames {
|
||||||
FULL = 'FULL',
|
FULL = 'FULL',
|
||||||
|
@ -88,7 +88,7 @@ export class VideoShareModel extends Model<VideoShareModel> {
|
||||||
})
|
})
|
||||||
Video: VideoModel
|
Video: VideoModel
|
||||||
|
|
||||||
static load (actorId: number, videoId: number, t?: Sequelize.Transaction) {
|
static load (actorId: number, videoId: number, t?: Transaction) {
|
||||||
return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({
|
return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({
|
||||||
where: {
|
where: {
|
||||||
actorId,
|
actorId,
|
||||||
|
@ -98,7 +98,7 @@ export class VideoShareModel extends Model<VideoShareModel> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static loadByUrl (url: string, t: Sequelize.Transaction) {
|
static loadByUrl (url: string, t: Transaction) {
|
||||||
return VideoShareModel.scope(ScopeNames.FULL).findOne({
|
return VideoShareModel.scope(ScopeNames.FULL).findOne({
|
||||||
where: {
|
where: {
|
||||||
url
|
url
|
||||||
|
@ -107,7 +107,7 @@ export class VideoShareModel extends Model<VideoShareModel> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static loadActorsByShare (videoId: number, t: Sequelize.Transaction) {
|
static loadActorsByShare (videoId: number, t: Transaction) {
|
||||||
const query = {
|
const query = {
|
||||||
where: {
|
where: {
|
||||||
videoId
|
videoId
|
||||||
|
@ -125,7 +125,7 @@ export class VideoShareModel extends Model<VideoShareModel> {
|
||||||
.then(res => res.map(r => r.Actor))
|
.then(res => res.map(r => r.Actor))
|
||||||
}
|
}
|
||||||
|
|
||||||
static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Sequelize.Transaction): Bluebird<ActorModel[]> {
|
static loadActorsWhoSharedVideosOf (actorOwnerId: number, t: Transaction): Bluebird<ActorModel[]> {
|
||||||
const query = {
|
const query = {
|
||||||
attributes: [],
|
attributes: [],
|
||||||
include: [
|
include: [
|
||||||
|
@ -163,7 +163,7 @@ export class VideoShareModel extends Model<VideoShareModel> {
|
||||||
.then(res => res.map(r => r.Actor))
|
.then(res => res.map(r => r.Actor))
|
||||||
}
|
}
|
||||||
|
|
||||||
static loadActorsByVideoChannel (videoChannelId: number, t: Sequelize.Transaction): Bluebird<ActorModel[]> {
|
static loadActorsByVideoChannel (videoChannelId: number, t: Transaction): Bluebird<ActorModel[]> {
|
||||||
const query = {
|
const query = {
|
||||||
attributes: [],
|
attributes: [],
|
||||||
include: [
|
include: [
|
||||||
|
@ -188,7 +188,7 @@ export class VideoShareModel extends Model<VideoShareModel> {
|
||||||
.then(res => res.map(r => r.Actor))
|
.then(res => res.map(r => r.Actor))
|
||||||
}
|
}
|
||||||
|
|
||||||
static listAndCountByVideoId (videoId: number, start: number, count: number, t?: Sequelize.Transaction) {
|
static listAndCountByVideoId (videoId: number, start: number, count: number, t?: Transaction) {
|
||||||
const query = {
|
const query = {
|
||||||
offset: start,
|
offset: start,
|
||||||
limit: count,
|
limit: count,
|
||||||
|
@ -205,10 +205,21 @@ export class VideoShareModel extends Model<VideoShareModel> {
|
||||||
const query = {
|
const query = {
|
||||||
where: {
|
where: {
|
||||||
updatedAt: {
|
updatedAt: {
|
||||||
[Sequelize.Op.lt]: beforeUpdatedAt
|
[Op.lt]: beforeUpdatedAt
|
||||||
},
|
},
|
||||||
videoId
|
videoId
|
||||||
}
|
},
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
model: ActorModel.unscoped(),
|
||||||
|
required: true,
|
||||||
|
where: {
|
||||||
|
serverId: {
|
||||||
|
[ Op.ne ]: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
return VideoShareModel.destroy(query)
|
return VideoShareModel.destroy(query)
|
||||||
|
|
|
@ -379,7 +379,8 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg
|
||||||
req.field('licence', attributes.licence.toString())
|
req.field('licence', attributes.licence.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < attributes.tags.length; i++) {
|
const tags = attributes.tags || []
|
||||||
|
for (let i = 0; i < tags.length; i++) {
|
||||||
req.field('tags[' + i + ']', attributes.tags[i])
|
req.field('tags[' + i + ']', attributes.tags[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue