aboutsummaryrefslogtreecommitdiff
path: root/_www/rescached.js
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-05-15 13:27:28 +0700
committerShulhan <ms@kilabit.info>2022-05-15 13:27:28 +0700
commit188f8b7c0285dc0752113ecbb3af546697cba64d (patch)
treeccf4d674415c7fdd9ef2791f5b6e59053f98c82b /_www/rescached.js
parentfc042afcacfc105f354b8903837bf22a7169d12e (diff)
downloadrescached-188f8b7c0285dc0752113ecbb3af546697cba64d.tar.xz
all: refactoring the HTTP API for deleting zone record
Previously, the HTTP API for deleting a record is by passing the parameters as JSON in the body. This may cause issue if HTTP client does not support sending body in DELETE method. This changes the method to pass the parameters in the query, DELETE /zone.d/rr?zone=<string>&type=<string>&record=<base64 json> Parameters, - zone: the zone name, - type: the record type, - record: the content of record with its domain name and value.
Diffstat (limited to '_www/rescached.js')
-rw-r--r--_www/rescached.js29
1 files changed, 14 insertions, 15 deletions
diff --git a/_www/rescached.js b/_www/rescached.js
index a821081..0be344a 100644
--- a/_www/rescached.js
+++ b/_www/rescached.js
@@ -27,6 +27,7 @@ const contentTypeForm = "application/x-www-form-urlencoded"
const contentTypeJson = "application/json"
const paramNameName = "name"
+const paramNameZone = "zone"
const headerContentType = "Content-Type"
@@ -295,9 +296,9 @@ class Rescached {
async ZonedRecordAdd(name, rr) {
let req = {
- "zone": name,
- "type": getRRTypeName(rr.Type),
- "record": btoa(JSON.stringify(rr)),
+ zone: name,
+ type: getRRTypeName(rr.Type),
+ record: btoa(JSON.stringify(rr)),
}
const httpRes = await fetch(Rescached.apiZonedRR, {
@@ -322,23 +323,21 @@ class Rescached {
return res
}
- async ZoneFileRecordDelete(name, rr) {
- let api =
- this.server +
- Rescached.apiZoned +
- name +
- "/rr/" +
- rr.Type
+ async ZonedRecordDelete(zone, rr) {
+ let params = new URLSearchParams()
+ params.set(paramNameZone, zone)
+ params.set("type", getRRTypeName(rr.Type))
+ params.set("record", btoa(JSON.stringify(rr)))
+
+ let api = Rescached.apiZonedRR + "?" + params.toString()
+
const httpRes = await fetch(api, {
method: "DELETE",
- headers: {
- [headerContentType]: contentTypeJson,
- },
- body: JSON.stringify(rr),
})
+
let res = await httpRes.json()
if (httpRes.status === 200) {
- this.env.Zones[name].Records = res.data
+ this.env.Zones[zone].Records = res.data
}
return res
}