Skip to content

Commit

Permalink
Add set hotlink protection setting
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-tymoshenko committed Aug 29, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent c0a0bee commit a9d6808
Showing 4 changed files with 27 additions and 2 deletions.
21 changes: 21 additions & 0 deletions cloudflare.js
Original file line number Diff line number Diff line change
@@ -598,6 +598,27 @@ class CloudFlare {

await this.createWorkerRoutes(workerRoutes)
}

async setHotlinkProtection (value) {
const url = CLOUDFLARE_API_URL + `zones/${this.zoneId}/settings/hotlink_protection`

const { statusCode, body } = await request(url, {
method: 'PATCH',
headers: {
...this.authorizationHeaders,
'Content-Type': 'application/json'
},
body: JSON.stringify({ value })
})

const response = await body.json()

if (statusCode !== 200) {
throw new Error(`Could not change hotlink protection: ${statusCode}, error: ${JSON.stringify(response)}`)
}

return response
}
}

module.exports = CloudFlare
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -19,7 +19,8 @@ const cloudflareSettingsHandlers = {
'0-RTT': CloudFlare.prototype.set0RTT,
argoSmartRouting: CloudFlare.prototype.setArgoSmartRouting,
workers: CloudFlare.prototype.rewriteWorkerRoutes,
pageRules: CloudFlare.prototype.rewritePageRules
pageRules: CloudFlare.prototype.rewritePageRules,
hotlinkProtection: CloudFlare.prototype.setHotlinkProtection
}

function substituteDomainName (settings, domainName) {
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nodeart/cloudflare-provisioning",
"version": "1.0.0",
"version": "1.0.1",
"description": "",
"main": "index.js",
"scripts": {
3 changes: 3 additions & 0 deletions template.js
Original file line number Diff line number Diff line change
@@ -124,5 +124,8 @@ module.exports = {
},
traffic: {
argoSmartRouting: 'on'
},
scrapeShield: {
hotlinkProtection: 'off'
}
}

0 comments on commit a9d6808

Please sign in to comment.