Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions assets/js/image.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ loadImageWithProgress = ->
$image.attr "src", URLObject.createObjectURL(new Blob([this.response], opts))
$progressBar.addClass "done"

# Add query parameter to make sure the new CORS headers are included
xhr.open "GET", imageSource + "?1"
xhr.open "GET", imageSource
xhr.send()

$image.on "load", ->
Expand Down
7 changes: 7 additions & 0 deletions auth/cloudflare.example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
CloudFlare credentials. Rename this file to cloudflare.js.
*/

exports.EMAIL = "YOUR CLOUDFLARE ACCOUNT EMAIL"
exports.KEY = "YOUR CLOUDFLARE KEY"
exports.ZONE_ID = "YOUR CLOUDFLARE ZONE ID"
3 changes: 2 additions & 1 deletion auth/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var authFiles = [
"amazon",
"google_analytics",
"hashing"
"hashing",
"cloudflare"
];

for(var i = 0; i < authFiles.length; i++) {
Expand Down
14 changes: 14 additions & 0 deletions controllers/images.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ post.delete = (req, res) ->
localPath = "#{req.app.get "localStorageFilePath"}#{req.params.image}"
require("fs").unlink localPath, (-> )

if auth.cloudflare
params =
url: "https://api.cloudflare.com/client/v4/zones/#{auth.cloudflare.ZONE_ID}/purge_cache"
json: true
headers:
"X-Auth-Email": auth.cloudflare.EMAIL
"X-Auth-Key": auth.cloudflare.KEY
body: {
files: [helpers.imageURL req, req.params.image]
}

request.del params, (error) ->
console.log("Cloudflare error", error) if error

helpers.removeImageOwner res, req.params.image
res.send "Success"

Expand Down