mirror of https://github.com/Chocobozzz/PeerTube
Fix pending subscription deletion
parent
f530dde244
commit
d3fcf1c57a
|
@ -1,6 +1,7 @@
|
||||||
import express from 'express'
|
import express from 'express'
|
||||||
import { body, param, query } from 'express-validator'
|
import { body, param, query } from 'express-validator'
|
||||||
import { arrayify } from '@shared/core-utils'
|
import { arrayify } from '@shared/core-utils'
|
||||||
|
import { FollowState } from '@shared/models'
|
||||||
import { HttpStatusCode } from '../../../shared/models/http/http-error-codes'
|
import { HttpStatusCode } from '../../../shared/models/http/http-error-codes'
|
||||||
import { areValidActorHandles, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor'
|
import { areValidActorHandles, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor'
|
||||||
import { WEBSERVER } from '../../initializers/constants'
|
import { WEBSERVER } from '../../initializers/constants'
|
||||||
|
@ -48,26 +49,20 @@ const userSubscriptionGetValidator = [
|
||||||
|
|
||||||
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
if (areValidationErrors(req, res)) return
|
if (areValidationErrors(req, res)) return
|
||||||
|
if (!await doesSubscriptionExist({ uri: req.params.uri, res, state: 'accepted' })) return
|
||||||
|
|
||||||
let [ name, host ] = req.params.uri.split('@')
|
return next()
|
||||||
if (host === WEBSERVER.HOST) host = null
|
}
|
||||||
|
]
|
||||||
|
|
||||||
const user = res.locals.oauth.token.User
|
const userSubscriptionDeleteValidator = [
|
||||||
const subscription = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI({
|
param('uri')
|
||||||
actorId: user.Account.Actor.id,
|
.custom(isValidActorHandle),
|
||||||
targetName: name,
|
|
||||||
targetHost: host,
|
|
||||||
state: 'accepted'
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!subscription?.ActorFollowing.VideoChannel) {
|
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
return res.fail({
|
if (areValidationErrors(req, res)) return
|
||||||
status: HttpStatusCode.NOT_FOUND_404,
|
if (!await doesSubscriptionExist({ uri: req.params.uri, res })) return
|
||||||
message: `Subscription ${req.params.uri} not found.`
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
res.locals.subscription = subscription
|
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -78,5 +73,39 @@ export {
|
||||||
areSubscriptionsExistValidator,
|
areSubscriptionsExistValidator,
|
||||||
userSubscriptionListValidator,
|
userSubscriptionListValidator,
|
||||||
userSubscriptionAddValidator,
|
userSubscriptionAddValidator,
|
||||||
userSubscriptionGetValidator
|
userSubscriptionGetValidator,
|
||||||
|
userSubscriptionDeleteValidator
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
async function doesSubscriptionExist (options: {
|
||||||
|
uri: string
|
||||||
|
res: express.Response
|
||||||
|
state?: FollowState
|
||||||
|
}) {
|
||||||
|
const { uri, res, state } = options
|
||||||
|
|
||||||
|
let [ name, host ] = uri.split('@')
|
||||||
|
if (host === WEBSERVER.HOST) host = null
|
||||||
|
|
||||||
|
const user = res.locals.oauth.token.User
|
||||||
|
const subscription = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI({
|
||||||
|
actorId: user.Account.Actor.id,
|
||||||
|
targetName: name,
|
||||||
|
targetHost: host,
|
||||||
|
state
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!subscription?.ActorFollowing.VideoChannel) {
|
||||||
|
res.fail({
|
||||||
|
status: HttpStatusCode.NOT_FOUND_404,
|
||||||
|
message: `Subscription ${uri} not found.`
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
res.locals.subscription = subscription
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue