Skip to content

Instantly share code, notes, and snippets.

@gustavosf
Forked from williammustaffa/slack-bulk-eraser.js
Created December 13, 2016 19:28
Show Gist options
  • Save gustavosf/82ef90d13eae01acc3aa867db367dc5e to your computer and use it in GitHub Desktop.
Save gustavosf/82ef90d13eae01acc3aa867db367dc5e to your computer and use it in GitHub Desktop.
/**
* 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