From ae126b977e59d9703773113da5d9aedf256ec2bf Mon Sep 17 00:00:00 2001 From: ogi <50716143+ogidevs@users.noreply.github.com> Date: Wed, 8 Feb 2023 21:42:51 +0100 Subject: [PATCH] Update main.ts For this to work you will need an account on Imgur. Create an application and get the Client-ID which has to be put in ui/src/main.ts line 204. THIS HAS TO BE DONE BEFORE RUNNING THE screenshot-basic for the first time! Also change webhook url on every other resource that is using screenshot-basic so for example in qb-phone change the webhook option so it looks like this: Config.Webhook = "imgur" --- ui/src/main.ts | 68 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/ui/src/main.ts b/ui/src/main.ts index 5d5adb1..a3d2d8b 100644 --- a/ui/src/main.ts +++ b/ui/src/main.ts @@ -195,29 +195,53 @@ class ScreenshotUI { return formData; }; - // upload the image somewhere - fetch(request.targetURL, { - method: 'POST', - mode: 'cors', - headers: request.headers, - body: (request.targetField) ? getFormData() : JSON.stringify({ - data: imageURL, - id: request.correlation + if (request.targetURL.includes('imgur')) { + const formdata = new FormData() + formdata.append("image", imageURL.split(',')[1]) + fetch('https://api.imgur.com/3/image/', { + method: 'POST', + headers: { + Authorization: "Client-ID YOURCLIENTIDHERE" + }, + body: formdata }) - }) - .then(response => response.text()) - .then(text => { - if (request.resultURL) { - fetch(request.resultURL, { - method: 'POST', - mode: 'cors', - body: JSON.stringify({ - data: text, - id: request.correlation - }) - }); - } - }); + .then(response => response.json()) + .then(response => { + if (request.resultURL) { + fetch(request.resultURL, { + method: 'POST', + mode: 'cors', + body: JSON.stringify({ + data: response, + id: request.correlation + }) + }); + } + }); + }else { + fetch(request.targetURL, { + method: 'POST', + mode: 'cors', + headers: request.headers, + body: (request.targetField) ? getFormData() : JSON.stringify({ + data: imageURL, + id: request.correlation + }) + }) + .then(response => response.text()) + .then(text => { + if (request.resultURL) { + fetch(request.resultURL, { + method: 'POST', + mode: 'cors', + body: JSON.stringify({ + data: text, + id: request.correlation + }) + }); + } + }); + } } }