-
-
Save splex7/a5bc2050dd63181904ce66d7fb06f8e2 to your computer and use it in GitHub Desktop.
pastebin node.js API
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
const FormData = require('form-data') | |
const axios = require('axios') | |
const getUserKey = async ({ | |
api_dev_key, | |
api_user_name, | |
api_user_password, | |
}) => { | |
const formData = new FormData() | |
formData.append('api_dev_key', api_dev_key) | |
formData.append('api_user_name', api_user_name) | |
formData.append('api_user_password', api_user_password) | |
result = await axios.post( | |
'https://pastebin.com/api/api_login.php', | |
formData, | |
{ | |
headers: formData.getHeaders(), | |
}, | |
) | |
return result.data | |
} | |
const uploadFileToPastebin = async ({ | |
api_dev_key, | |
api_paste_private, | |
api_paste_name, | |
api_folder_key, | |
api_user_key, | |
api_paste_code, | |
}) => { | |
const formData = new FormData() | |
formData.append('api_dev_key', api_dev_key) | |
api_paste_private && formData.append('api_paste_private', api_paste_private) | |
api_paste_name && formData.append('api_paste_name', api_paste_name) | |
api_folder_key && formData.append('api_folder_key', api_folder_key) | |
api_user_key && formData.append('api_user_key', api_user_key) | |
formData.append('api_paste_code', api_paste_code) | |
formData.append('api_option', 'paste') | |
result = await axios.post('https://pastebin.com/api/api_post.php', formData, { | |
headers: formData.getHeaders(), | |
}) | |
return result.data | |
} | |
const main = async () => { | |
const api_user_key = await getUserKey({ | |
api_dev_key: process.env.PASTEBIN_API_DEV_KEY, | |
api_user_name: process.env.PASTEBIN_API_USER_NAME, | |
api_user_password: process.env.PASTEBIN_API_USER_PASSWORD, | |
}) | |
console.log(api_user_key) | |
const uploadedUrl = await uploadFileToPastebin({ | |
api_dev_key: process.env.PASTEBIN_API_DEV_KEY, | |
api_paste_private: '2', // private | |
api_paste_name: 'tiger.jpg', | |
api_user_key: api_user_key, | |
api_folder_key: '<YOUR PRIVATE FOLDER KEY>', | |
api_paste_code: fs.readFileSync('./tiger.jpg'), | |
}) | |
console.log('uploadedUrl', uploadedUrl) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment