Skip to content

Commit

Permalink
#363 Support file_owner in webhook body. Include body for onFileDelete
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Apr 17, 2023
1 parent 253376b commit 3ccb3a0
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions API/Backend/Webhooks/processes/triggerwebhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,26 @@ function drawFileUpdate(webhook, payload) {
},
};

var response = {};
const response = {};
response.send = function (res) {
var webhookHeader = JSON.parse(webhook.header);
var webhookBody = JSON.parse(webhook.body);
var file_name = res.body?.file[0]?.file_name || null;
var geojson = res.body.geojson;
const webhookHeader = JSON.parse(webhook.header);
const webhookBody = JSON.parse(webhook.body);
const file_name = res.body?.file[0]?.file_name || null;
const file_owner = res.body?.file[0]?.file_owner || null;
const geojson = res.body.geojson;

const injectableVariables = {
file_id,
file_name,
file_owner,
geojson,
};

// Build the body
buildBody(webhookBody, injectableVariables);

// Build the url
var url = buildUrl(webhook.url, injectableVariables);
const url = buildUrl(webhook.url, injectableVariables);

// Push to the remote webhook
pushToRemote(url, webhook.type, webhookHeader, webhookBody);
Expand Down Expand Up @@ -128,8 +130,8 @@ function buildBody(webhookBody, injectableVariables) {
}

function drawFileDelete(webhook, payload) {
var file_id = payload.id;
var data = {
const file_id = payload.id;
const data = {
body: {
id: payload.id,
quick_published: false,
Expand All @@ -141,23 +143,29 @@ function drawFileDelete(webhook, payload) {
},
};

var response = {};
const response = {};
response.send = function (res) {
var webhookHeader = JSON.parse(webhook.header);
var geojson = res.body.geojson;
var file_name = res.body?.file[0]?.file_name || null;
const webhookHeader = JSON.parse(webhook.header);
const webhookBody = JSON.parse(webhook.body);
const geojson = res.body.geojson;
const file_name = res.body?.file[0]?.file_name || null;
const file_owner = res.body?.file[0]?.file_owner || null;

const injectableVariables = {
file_id,
file_name,
file_owner,
geojson,
};

// Build the body
buildBody(webhookBody, injectableVariables);

// Build the url
var url = buildUrl(webhook.url, injectableVariables);
const url = buildUrl(webhook.url, injectableVariables);

// Push to the remote webhook
pushToRemote(url, webhook.type, webhookHeader, {});
pushToRemote(url, webhook.type, webhookHeader, webhookBody);
};

getfile(data, response);
Expand Down

0 comments on commit 3ccb3a0

Please sign in to comment.