Skip to content

Instantly share code, notes, and snippets.

@acidsound
Created April 25, 2021 10:28
Show Gist options
  • Save acidsound/163a9bdbbdfe17582b10bd2f3dc5ddde to your computer and use it in GitHub Desktop.
Save acidsound/163a9bdbbdfe17582b10bd2f3dc5ddde to your computer and use it in GitHub Desktop.
pastebin node.js API
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