this.router.navigate([ '/my-account', 'video-channels' ])
},
- err => this.error = err.message
+ err => {
+ if (err.status === 409) {
+ this.error = this.i18n('This name already exists on this instance.')
+ return
+ }
+
+ this.error = err.message
+ }
)
}
usersVerifyEmailValidator
} from '../../../middlewares/validators'
import { UserModel } from '../../../models/account/user'
-import { OAuthTokenModel } from '../../../models/oauth/oauth-token'
import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger'
import { meRouter } from './me'
import { deleteUserToken } from '../../../lib/oauth-model'
videoChannelRouter.post('/',
authenticate,
- videoChannelsAddValidator,
+ asyncMiddleware(videoChannelsAddValidator),
asyncRetryTransactionMiddleware(addVideoChannel)
)
// We don't have this actor in our database, fetch it on remote
if (!actor) {
const { result } = await fetchRemoteActor(actorUrl)
- if (result === undefined) throw new Error('Cannot fetch remote actor.')
+ if (result === undefined) throw new Error('Cannot fetch remote actor ' + actorUrl)
// Create the attributed to actor
// In PeerTube a video channel is owned by an account
try {
actor = await getOrCreateActorAndServerAndModel(creator)
} catch (err) {
- logger.error('Cannot create remote actor and check signature.', { err })
+ logger.warn('Cannot create remote actor %s and check signature.', creator, { err })
return res.sendStatus(403)
}
import { VideoChannelModel } from '../../models/video/video-channel'
import { areValidationErrors } from './utils'
import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor'
+import { ActorModel } from '../../models/activitypub/actor'
const listVideoAccountChannelsValidator = [
param('accountName').exists().withMessage('Should have a valid account name'),
body('description').optional().custom(isVideoChannelDescriptionValid).withMessage('Should have a valid description'),
body('support').optional().custom(isVideoChannelSupportValid).withMessage('Should have a valid support text'),
- (req: express.Request, res: express.Response, next: express.NextFunction) => {
+ async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking videoChannelsAdd parameters', { parameters: req.body })
if (areValidationErrors(req, res)) return
+ const actor = await ActorModel.loadLocalByName(req.body.name)
+ if (actor) {
+ res.status(409)
+ .send({ error: 'Another actor (account/channel) with this name on this instance already exists or has already existed.' })
+ .end()
+ return false
+ }
+
return next()
}
]
statusCodeExpected: 200
})
})
+
+ it('Should fail when adding a channel with the same username', async function () {
+ await makePostBodyRequest({
+ url: server.url,
+ path: videoChannelPath,
+ token: server.accessToken,
+ fields: baseCorrectParams,
+ statusCodeExpected: 409
+ })
+ })
})
describe('When updating a video channel', function () {