mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-07-23 20:42:16 +00:00
REST createCall must use absolute url in call_hook and call_status_hook
This commit is contained in:
@@ -131,8 +131,34 @@ async function validateCreateCall(logger, sid, req) {
|
||||
});
|
||||
}
|
||||
|
||||
if (!obj.call_hook || (typeof obj.call_hook === 'object' && !obj.call_hook.url)) {
|
||||
throw new DbErrorBadRequest('either url or application_sid required');
|
||||
if (!obj.call_hook && !obj.application_sid) {
|
||||
throw new DbErrorBadRequest('either call_hook or application_sid required');
|
||||
}
|
||||
if (typeof obj.call_hook === 'string') {
|
||||
const url = obj.call_hook;
|
||||
obj.call_hook = {
|
||||
url,
|
||||
method: 'POST'
|
||||
};
|
||||
}
|
||||
if (typeof obj.call_status_hook === 'string') {
|
||||
const url = obj.call_status_hook;
|
||||
obj.call_status_hook = {
|
||||
url,
|
||||
method: 'POST'
|
||||
};
|
||||
}
|
||||
if (typeof obj.call_hook === 'object' && typeof obj.call_hook.url != 'string') {
|
||||
throw new DbErrorBadRequest('call_hook must be string or an object containing a url property');
|
||||
}
|
||||
if (typeof obj.call_status_hook === 'object' && typeof obj.call_status_hook.url != 'string') {
|
||||
throw new DbErrorBadRequest('call_status_hook must be string or an object containing a url property');
|
||||
}
|
||||
if (obj.call_hook && !/^https?:/.test(obj.call_hook.url)) {
|
||||
throw new DbErrorBadRequest('call_hook url be an absolute url');
|
||||
}
|
||||
if (obj.call_status_hook && !/^https?:/.test(obj.call_status_hook.url)) {
|
||||
throw new DbErrorBadRequest('call_status_hook url be an absolute url');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user