williammustaffa
8/5/2016 - 7:36 PM

slack-bulk-eraser.js

/**
 * Usage: 
 * Go to https://objectedge.slack.com/files/{username}
 * and run this code in the browser console
 */
(function() {
  var time = new Date().getTime();
  var url = {
    list: "/api/files.list?t=" + time,
    del: "/api/files.delete?t=" + time
  };
  var get_files_data = {
    user: boot_data.user_id,
    types: "all", // Or "images"
    token: boot_data.api_token,
    count: 1000
  };
  var delete_files = function(data) {
    if (data.files && data.files.length > 0) {
      var total = data.files.length;
      data.files.forEach(function(file, index) {
        var file_data = {
          file: file.id,
          token: boot_data.api_token
        };
        $.post(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(url.list, get_files_data, delete_files);
  }
  request_list();
})();