mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-02-25 18:55:32 -06:00
Fix remote actor creation date
This commit is contained in:
parent
64df4b65ae
commit
a66c2e3252
@ -1,6 +1,6 @@
|
|||||||
import validator from 'validator'
|
import validator from 'validator'
|
||||||
import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
|
import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
|
||||||
import { exists, isArray } from '../misc'
|
import { exists, isArray, isDateValid } from '../misc'
|
||||||
import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc'
|
import { isActivityPubUrlValid, isBaseActivityValid, setValidAttributedTo } from './misc'
|
||||||
import { isHostValid } from '../servers'
|
import { isHostValid } from '../servers'
|
||||||
import { peertubeTruncate } from '@server/helpers/core-utils'
|
import { peertubeTruncate } from '@server/helpers/core-utils'
|
||||||
@ -47,7 +47,21 @@ function isActorPrivateKeyValid (privateKey: string) {
|
|||||||
validator.isLength(privateKey, CONSTRAINTS_FIELDS.ACTORS.PRIVATE_KEY)
|
validator.isLength(privateKey, CONSTRAINTS_FIELDS.ACTORS.PRIVATE_KEY)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isActorObjectValid (actor: any) {
|
function isActorFollowingCountValid (value: string) {
|
||||||
|
return exists(value) && validator.isInt('' + value, { min: 0 })
|
||||||
|
}
|
||||||
|
|
||||||
|
function isActorFollowersCountValid (value: string) {
|
||||||
|
return exists(value) && validator.isInt('' + value, { min: 0 })
|
||||||
|
}
|
||||||
|
|
||||||
|
function isActorDeleteActivityValid (activity: any) {
|
||||||
|
return isBaseActivityValid(activity, 'Delete')
|
||||||
|
}
|
||||||
|
|
||||||
|
function sanitizeAndCheckActorObject (actor: any) {
|
||||||
|
normalizeActor(actor)
|
||||||
|
|
||||||
return exists(actor) &&
|
return exists(actor) &&
|
||||||
isActivityPubUrlValid(actor.id) &&
|
isActivityPubUrlValid(actor.id) &&
|
||||||
isActorTypeValid(actor.type) &&
|
isActorTypeValid(actor.type) &&
|
||||||
@ -68,24 +82,6 @@ function isActorObjectValid (actor: any) {
|
|||||||
(actor.type !== 'Group' || actor.attributedTo.length !== 0)
|
(actor.type !== 'Group' || actor.attributedTo.length !== 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isActorFollowingCountValid (value: string) {
|
|
||||||
return exists(value) && validator.isInt('' + value, { min: 0 })
|
|
||||||
}
|
|
||||||
|
|
||||||
function isActorFollowersCountValid (value: string) {
|
|
||||||
return exists(value) && validator.isInt('' + value, { min: 0 })
|
|
||||||
}
|
|
||||||
|
|
||||||
function isActorDeleteActivityValid (activity: any) {
|
|
||||||
return isBaseActivityValid(activity, 'Delete')
|
|
||||||
}
|
|
||||||
|
|
||||||
function sanitizeAndCheckActorObject (object: any) {
|
|
||||||
normalizeActor(object)
|
|
||||||
|
|
||||||
return isActorObjectValid(object)
|
|
||||||
}
|
|
||||||
|
|
||||||
function normalizeActor (actor: any) {
|
function normalizeActor (actor: any) {
|
||||||
if (!actor) return
|
if (!actor) return
|
||||||
|
|
||||||
@ -95,6 +91,8 @@ function normalizeActor (actor: any) {
|
|||||||
actor.url = actor.url.href || actor.url.url
|
actor.url = actor.url.href || actor.url.url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isDateValid(actor.published)) actor.published = undefined
|
||||||
|
|
||||||
if (actor.summary && typeof actor.summary === 'string') {
|
if (actor.summary && typeof actor.summary === 'string') {
|
||||||
actor.summary = peertubeTruncate(actor.summary, { length: CONSTRAINTS_FIELDS.USERS.DESCRIPTION.max })
|
actor.summary = peertubeTruncate(actor.summary, { length: CONSTRAINTS_FIELDS.USERS.DESCRIPTION.max })
|
||||||
|
|
||||||
@ -135,7 +133,6 @@ export {
|
|||||||
isActorPublicKeyValid,
|
isActorPublicKeyValid,
|
||||||
isActorPreferredUsernameValid,
|
isActorPreferredUsernameValid,
|
||||||
isActorPrivateKeyValid,
|
isActorPrivateKeyValid,
|
||||||
isActorObjectValid,
|
|
||||||
isActorFollowingCountValid,
|
isActorFollowingCountValid,
|
||||||
isActorFollowersCountValid,
|
isActorFollowersCountValid,
|
||||||
isActorDeleteActivityValid,
|
isActorDeleteActivityValid,
|
||||||
|
@ -24,7 +24,7 @@ import { CONFIG, registerConfigChangedHandler } from './config'
|
|||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
const LAST_MIGRATION_VERSION = 640
|
const LAST_MIGRATION_VERSION = 645
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
import * as Sequelize from 'sequelize'
|
||||||
|
|
||||||
|
async function up (utils: {
|
||||||
|
transaction: Sequelize.Transaction
|
||||||
|
queryInterface: Sequelize.QueryInterface
|
||||||
|
sequelize: Sequelize.Sequelize
|
||||||
|
db: any
|
||||||
|
}): Promise<void> {
|
||||||
|
{
|
||||||
|
const data = {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
defaultValue: null,
|
||||||
|
allowNull: true
|
||||||
|
}
|
||||||
|
await utils.queryInterface.addColumn('actor', 'remoteCreatedAt', data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function down (options) {
|
||||||
|
throw new Error('Not implemented.')
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
up,
|
||||||
|
down
|
||||||
|
}
|
@ -154,6 +154,8 @@ async function updateActorInstance (actorInstance: ActorModel, attributes: Activ
|
|||||||
const followersCount = await fetchActorTotalItems(attributes.followers)
|
const followersCount = await fetchActorTotalItems(attributes.followers)
|
||||||
const followingCount = await fetchActorTotalItems(attributes.following)
|
const followingCount = await fetchActorTotalItems(attributes.following)
|
||||||
|
|
||||||
|
logger.info('coucou', { attributes })
|
||||||
|
|
||||||
actorInstance.type = attributes.type
|
actorInstance.type = attributes.type
|
||||||
actorInstance.preferredUsername = attributes.preferredUsername
|
actorInstance.preferredUsername = attributes.preferredUsername
|
||||||
actorInstance.url = attributes.id
|
actorInstance.url = attributes.id
|
||||||
@ -165,6 +167,8 @@ async function updateActorInstance (actorInstance: ActorModel, attributes: Activ
|
|||||||
actorInstance.followersUrl = attributes.followers
|
actorInstance.followersUrl = attributes.followers
|
||||||
actorInstance.followingUrl = attributes.following
|
actorInstance.followingUrl = attributes.following
|
||||||
|
|
||||||
|
if (attributes.published) actorInstance.remoteCreatedAt = new Date(attributes.published)
|
||||||
|
|
||||||
if (attributes.endpoints?.sharedInbox) {
|
if (attributes.endpoints?.sharedInbox) {
|
||||||
actorInstance.sharedInboxUrl = attributes.endpoints.sharedInbox
|
actorInstance.sharedInboxUrl = attributes.endpoints.sharedInbox
|
||||||
}
|
}
|
||||||
|
@ -411,8 +411,6 @@ export class AccountModel extends Model {
|
|||||||
id: this.id,
|
id: this.id,
|
||||||
displayName: this.getDisplayName(),
|
displayName: this.getDisplayName(),
|
||||||
description: this.description,
|
description: this.description,
|
||||||
createdAt: this.createdAt,
|
|
||||||
updatedAt: this.updatedAt,
|
|
||||||
userId: this.userId ? this.userId : undefined
|
userId: this.userId ? this.userId : undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,9 +69,7 @@ export const unusedActorAttributesForAPI = [
|
|||||||
'outboxUrl',
|
'outboxUrl',
|
||||||
'sharedInboxUrl',
|
'sharedInboxUrl',
|
||||||
'followersUrl',
|
'followersUrl',
|
||||||
'followingUrl',
|
'followingUrl'
|
||||||
'createdAt',
|
|
||||||
'updatedAt'
|
|
||||||
]
|
]
|
||||||
|
|
||||||
@DefaultScope(() => ({
|
@DefaultScope(() => ({
|
||||||
@ -222,6 +220,10 @@ export class ActorModel extends Model {
|
|||||||
@Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.URL.max))
|
@Column(DataType.STRING(CONSTRAINTS_FIELDS.ACTORS.URL.max))
|
||||||
followingUrl: string
|
followingUrl: string
|
||||||
|
|
||||||
|
@AllowNull(true)
|
||||||
|
@Column
|
||||||
|
remoteCreatedAt: Date
|
||||||
|
|
||||||
@CreatedAt
|
@CreatedAt
|
||||||
createdAt: Date
|
createdAt: Date
|
||||||
|
|
||||||
@ -555,7 +557,7 @@ export class ActorModel extends Model {
|
|||||||
followingCount: this.followingCount,
|
followingCount: this.followingCount,
|
||||||
followersCount: this.followersCount,
|
followersCount: this.followersCount,
|
||||||
banner,
|
banner,
|
||||||
createdAt: this.createdAt,
|
createdAt: this.getCreatedAt(),
|
||||||
updatedAt: this.updatedAt
|
updatedAt: this.updatedAt
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -608,6 +610,7 @@ export class ActorModel extends Model {
|
|||||||
owner: this.url,
|
owner: this.url,
|
||||||
publicKeyPem: this.publicKey
|
publicKeyPem: this.publicKey
|
||||||
},
|
},
|
||||||
|
published: this.getCreatedAt().toISOString(),
|
||||||
icon,
|
icon,
|
||||||
image
|
image
|
||||||
}
|
}
|
||||||
@ -690,4 +693,8 @@ export class ActorModel extends Model {
|
|||||||
|
|
||||||
return isOutdated(this, ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL)
|
return isOutdated(this, ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCreatedAt (this: MActorAPChannel | MActorAPAccount | MActorFormattable) {
|
||||||
|
return this.remoteCreatedAt || this.createdAt
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -653,8 +653,6 @@ ON "Account->Actor"."serverId" = "Account->Actor->Server"."id"`
|
|||||||
description: this.description,
|
description: this.description,
|
||||||
support: this.support,
|
support: this.support,
|
||||||
isLocal: this.Actor.isOwned(),
|
isLocal: this.Actor.isOwned(),
|
||||||
createdAt: this.createdAt,
|
|
||||||
updatedAt: this.updatedAt,
|
|
||||||
ownerAccount: undefined,
|
ownerAccount: undefined,
|
||||||
videosCount,
|
videosCount,
|
||||||
viewsPerDay
|
viewsPerDay
|
||||||
|
@ -130,26 +130,32 @@ describe('Test users with multiple servers', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('Should have updated my profile on other servers too', async function () {
|
it('Should have updated my profile on other servers too', async function () {
|
||||||
|
let createdAt: string | Date
|
||||||
|
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
const resAccounts = await getAccountsList(server.url, '-createdAt')
|
const resAccounts = await getAccountsList(server.url, '-createdAt')
|
||||||
|
|
||||||
const rootServer1List = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) as Account
|
const resList = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) as Account
|
||||||
expect(rootServer1List).not.to.be.undefined
|
expect(resList).not.to.be.undefined
|
||||||
|
|
||||||
const resAccount = await getAccount(server.url, rootServer1List.name + '@' + rootServer1List.host)
|
const resAccount = await getAccount(server.url, resList.name + '@' + resList.host)
|
||||||
const rootServer1Get = resAccount.body as Account
|
const account = resAccount.body as Account
|
||||||
expect(rootServer1Get.name).to.equal('root')
|
|
||||||
expect(rootServer1Get.host).to.equal('localhost:' + servers[0].port)
|
if (!createdAt) createdAt = account.createdAt
|
||||||
expect(rootServer1Get.displayName).to.equal('my super display name')
|
|
||||||
expect(rootServer1Get.description).to.equal('my super description updated')
|
expect(account.name).to.equal('root')
|
||||||
|
expect(account.host).to.equal('localhost:' + servers[0].port)
|
||||||
|
expect(account.displayName).to.equal('my super display name')
|
||||||
|
expect(account.description).to.equal('my super description updated')
|
||||||
|
expect(createdAt).to.equal(account.createdAt)
|
||||||
|
|
||||||
if (server.serverNumber === 1) {
|
if (server.serverNumber === 1) {
|
||||||
expect(rootServer1Get.userId).to.be.a('number')
|
expect(account.userId).to.be.a('number')
|
||||||
} else {
|
} else {
|
||||||
expect(rootServer1Get.userId).to.be.undefined
|
expect(account.userId).to.be.undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
await testImage(server.url, 'avatar2-resized', rootServer1Get.avatar.path, '.png')
|
await testImage(server.url, 'avatar2-resized', account.avatar.path, '.png')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ export type MActorSummaryFormattable =
|
|||||||
|
|
||||||
export type MActorFormattable =
|
export type MActorFormattable =
|
||||||
MActorSummaryFormattable &
|
MActorSummaryFormattable &
|
||||||
Pick<MActor, 'id' | 'followingCount' | 'followersCount' | 'createdAt' | 'updatedAt' | 'bannerId' | 'avatarId'> &
|
Pick<MActor, 'id' | 'followingCount' | 'followersCount' | 'createdAt' | 'updatedAt' | 'remoteCreatedAt' | 'bannerId' | 'avatarId'> &
|
||||||
Use<'Server', MServerHost & Partial<Pick<MServer, 'redundancyAllowed'>>> &
|
Use<'Server', MServerHost & Partial<Pick<MServer, 'redundancyAllowed'>>> &
|
||||||
UseOpt<'Banner', MActorImageFormattable>
|
UseOpt<'Banner', MActorImageFormattable>
|
||||||
|
|
||||||
|
@ -29,4 +29,6 @@ export interface ActivityPubActor {
|
|||||||
|
|
||||||
icon?: ActivityIconObject
|
icon?: ActivityIconObject
|
||||||
image?: ActivityIconObject
|
image?: ActivityIconObject
|
||||||
|
|
||||||
|
published?: string
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user