feat: add webhook_headers and webhook_body to withdraws

This commit is contained in:
Vlad Stan 2022-12-21 15:03:22 +02:00
parent dd4a9f10cf
commit 8fae90bb9d
5 changed files with 68 additions and 13 deletions

View file

@ -27,9 +27,11 @@ async def create_withdraw_link(
open_time, open_time,
usescsv, usescsv,
webhook_url, webhook_url,
webhook_headers,
webhook_body,
custom_url custom_url
) )
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", """,
( (
link_id, link_id,
@ -45,6 +47,8 @@ async def create_withdraw_link(
int(datetime.now().timestamp()) + data.wait_time, int(datetime.now().timestamp()) + data.wait_time,
usescsv, usescsv,
data.webhook_url, data.webhook_url,
data.webhook_headers,
data.webhook_body,
data.custom_url, data.custom_url,
), ),
) )

View file

@ -122,3 +122,13 @@ async def m005_add_custom_print_design(db):
Adds custom print design Adds custom print design
""" """
await db.execute("ALTER TABLE withdraw.withdraw_link ADD COLUMN custom_url TEXT;") await db.execute("ALTER TABLE withdraw.withdraw_link ADD COLUMN custom_url TEXT;")
async def m006_webhook_headers_and_body(db):
"""
Add headers and body to webhooks
"""
await db.execute(
"ALTER TABLE withdraw.withdraw_link ADD COLUMN webhook_headers TEXT;"
)
await db.execute("ALTER TABLE withdraw.withdraw_link ADD COLUMN webhook_body TEXT;")

View file

@ -16,6 +16,8 @@ class CreateWithdrawData(BaseModel):
wait_time: int = Query(..., ge=1) wait_time: int = Query(..., ge=1)
is_unique: bool is_unique: bool
webhook_url: str = Query(None) webhook_url: str = Query(None)
webhook_headers: str = Query(None)
webhook_body: str = Query(None)
custom_url: str = Query(None) custom_url: str = Query(None)
@ -35,6 +37,8 @@ class WithdrawLink(BaseModel):
usescsv: str = Query(None) usescsv: str = Query(None)
number: int = Query(0) number: int = Query(0)
webhook_url: str = Query(None) webhook_url: str = Query(None)
webhook_headers: str = Query(None)
webhook_body: str = Query(None)
custom_url: str = Query(None) custom_url: str = Query(None)
@property @property

View file

@ -63,7 +63,8 @@ new Vue({
secondMultiplierOptions: ['seconds', 'minutes', 'hours'], secondMultiplierOptions: ['seconds', 'minutes', 'hours'],
data: { data: {
is_unique: false, is_unique: false,
use_custom: false use_custom: false,
has_webhook: false
} }
}, },
simpleformDialog: { simpleformDialog: {
@ -188,23 +189,35 @@ new Vue({
}, },
updateWithdrawLink: function (wallet, data) { updateWithdrawLink: function (wallet, data) {
var self = this var self = this
const body = _.pick(
data,
'title',
'min_withdrawable',
'max_withdrawable',
'uses',
'wait_time',
'is_unique',
'webhook_url',
'webhook_headers',
'webhook_body',
'custom_url'
)
if (data.has_webhook) {
body = {
...body,
webhook_url: data.webhook_url,
webhook_headers: data.webhook_headers,
webhook_body: data.webhook_body
}
}
LNbits.api LNbits.api
.request( .request(
'PUT', 'PUT',
'/withdraw/api/v1/links/' + data.id, '/withdraw/api/v1/links/' + data.id,
wallet.adminkey, wallet.adminkey,
_.pick( body
data,
'title',
'min_withdrawable',
'max_withdrawable',
'uses',
'wait_time',
'is_unique',
'webhook_url',
'custom_url'
)
) )
.then(function (response) { .then(function (response) {
self.withdrawLinks = _.reject(self.withdrawLinks, function (obj) { self.withdrawLinks = _.reject(self.withdrawLinks, function (obj) {

View file

@ -209,7 +209,13 @@
</q-select> </q-select>
</div> </div>
</div> </div>
<q-toggle
label="Webhook"
color="secodary"
v-model="formDialog.data.has_webhook"
></q-toggle>
<q-input <q-input
v-if="formDialog.data.has_webhook"
filled filled
dense dense
v-model="formDialog.data.webhook_url" v-model="formDialog.data.webhook_url"
@ -217,6 +223,24 @@
label="Webhook URL (optional)" label="Webhook URL (optional)"
hint="A URL to be called whenever this link gets used." hint="A URL to be called whenever this link gets used."
></q-input> ></q-input>
<q-input
v-if="formDialog.data.has_webhook"
filled
dense
v-model="formDialog.data.webhook_headers"
type="text"
label="Webhook Headers (optional)"
hint="Custom data as JSON string, send headers along with the webhook."
></q-input>
<q-input
v-if="formDialog.data.has_webhook"
filled
dense
v-model="formDialog.data.webhook_body"
type="text"
label="Webhook custom data (optional)"
hint="Custom data as JSON string, will get posted along with webhook 'body' field."
></q-input>
<q-list> <q-list>
<q-item tag="label" class="rounded-borders"> <q-item tag="label" class="rounded-borders">
<q-item-section avatar> <q-item-section avatar>