-
-
Save gustavosf/82ef90d13eae01acc3aa867db367dc5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Usage: | |
* Go to https://objectedge.slack.com/files/{username} | |
* and run this code in the browser console | |
* | |
* To remove only files older than a given date, configure "older_than" with appropriate value | |
* Ex: "2016-12-14", "2015-12-31 17:35:14" | |
* | |
* To delete only images, configure types as "image" | |
* To delete all kind of files, configure types as "all" | |
*/ | |
(function() { | |
var time = new Date().getTime(); | |
var config = { | |
older_than: "2020-12-31", | |
types: "all", // Or "images" | |
url: { | |
list: "/api/files.list?t=" + time, | |
del: "/api/files.delete?t=" + time | |
} | |
}; | |
var get_files_data = { | |
user: boot_data.user_id, | |
types: config.types, | |
token: boot_data.api_token, | |
count: 1000 | |
}; | |
var delete_files = function(data) { | |
if (data.files.length > 0) { | |
var total = data.files.length; | |
var limit_date = new Date(config.older_than).getTime() / 1000; | |
data.files.forEach(function(file, index) { | |
if (file.timestamp > limit_date) { | |
console.log("Kept:", file.name); | |
return; | |
} | |
var file_data = { | |
file: file.id, | |
token: boot_data.api_token | |
}; | |
$.post(config.url.del, file_data, function() { | |
console.log("Deleted:", file.name); | |
if (total == index + 1) request_list(); | |
}); | |
}); | |
} else { | |
console.log("Done!"); | |
} | |
}; | |
var request_list = function() { | |
$.post(config.url.list, get_files_data, delete_files); | |
} | |
request_list(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment