Last active
March 14, 2024 15:57
-
-
Save wajeht/e3a075c2550743329bbc370b6f795e08 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
// import cp from 'child_process'; | |
async function main() { | |
try { | |
const basedUrl = ''; | |
const username = ''; | |
const password = ''; | |
const loginResponse = await fetch(`${basedUrl}/api/v2/auth/login`, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded', | |
'Referer': basedUrl | |
}, | |
body: new URLSearchParams({ | |
username, | |
password, | |
}) | |
}); | |
// console.log(await loginResponse.text()); | |
const cookie = loginResponse.headers.get('Set-Cookie').split(';')[0]; | |
// console.log(cookie); | |
const torrentsInfoResponse = await fetch(`${basedUrl}/api/v2/torrents/info`, { | |
headers: { | |
'Cookie': cookie | |
} | |
}); | |
const torrentsList = await torrentsInfoResponse.json(); | |
for (const torrent of torrentsList) { | |
if (torrent.amount_left === 0) { | |
const response = await fetch(`${basedUrl}/api/v2/torrents/delete`, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/x-www-form-urlencoded', | |
'Cookie': cookie, | |
}, | |
body: new URLSearchParams({ | |
hashes: torrent.hash, | |
deleteFiles: 'true', | |
}), | |
}); | |
const responseData = await response.text(); | |
console.log(responseData); | |
// const output = cp.spawn(`curl -d "hashes=${torrent.hash}&deleteFiles=true" -X POST "${basedUrl}/api/v2/torrents/delete" --cookie "${cookie}"`, { shell: true, stdio: 'pipe', env: process.env }) | |
// if (output.stdout) { | |
// output.stdout.on('data', (data) => { | |
// console.log(data.toString()); | |
// }); | |
// } | |
// if (output.stderr) { | |
// output.stderr.on('data', (data) => { | |
// console.log(data.toString()); | |
// }); | |
// } | |
} | |
} | |
} catch (error) { | |
console.error(error.message); | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment