Drafts Action Directory

Pastebin Private

Posted by @mterhar, Last update 10 days ago

If you have a pro account on Pastebin, this will let you push your draft to Pastebin.

Requirements:

1. a Pastebin pro account
2. api key
3. username and password

Has a sanity check so you don’t automatically duplicate the note in Pastebin unless it’s intentional.

It appends the Pastebin link to the bottom of the note for reference. Does not archive or delete as-is.

Install

Steps

  • script

    if(draft.hasTag("pastebin")){
      var pcontinue = Prompt.create();
      pcontinue.title = "Already pasted";
      pcontinue.isCancellable = false;
      pcontinue.addButton("Make another", true);
      pcontinue.addButton("Nevermind", false);
      pcontinue.show();
      if(!pcontinue.buttonPressed){
        context.cancel("Nevermind button pressed");
      }
    }
    
    var credential = Credential.create("PastebinPrivate", "Insert Pastebin developer API key, username, and password.");
    
    credential.addTextField("devtoken", "Dev Token");
    credential.addTextField("username", "Username");
    credential.addPasswordField("password", "Password");
    credential.authorize();
    
    var pbToken = credential.getValue("devtoken");
    var pbUser = credential.getValue("username");
    var pbPass = credential.getValue("password");
    
    var endpoint = "https://pastebin.com/api/api_post.php";
    var content = draft.content;
    
    var http_getUserKey = HTTP.create();
    var pastebin_user_key = http_getUserKey.request({
      "url": "https://pastebin.com/api/api_login.php",
      "method": "POST",
      "encoding": "form",
      "data": {
        "api_dev_key": pbToken,
        "api_user_name": pbUser,
        "api_user_password": pbPass
      }
    });
    
    if (pastebin_user_key.statusCode != 200 && pastebin_user_key.statusCode != 202) {
      console.log("Pastebin authenticaton failure");
      context.fail();
    } 
    
    // create and post HTTP request
    var http = HTTP.create();
    var response = http.request({
      "url": endpoint,
      "method": "POST",
      "encoding": "form",
      "data": {
        "api_dev_key": pbToken,
        "api_option": "paste",
        "api_user_key": pastebin_user_key.responseText,
        "api_paste_private": "2",
        "api_paste_name": draft.title,
        "api_paste_code": content
      },
      "headers": {
        "Authorization": "Elsewhere"
      }
    });
    
    console.log("Response: " + response.statusCode);
    
    if (response.statusCode != 200 && response.statusCode != 202) {
      context.fail();
    } 
    else 
    { 
       var pasteURL = response.responseText;
       app.setClipboard(pasteURL);
       console.log("New paste: " + pasteURL);
       var ts = new Date(); 
       draft.content += "\r\n\r\nPrivate pastebin link: " + pasteURL + " created " + ts.toLocaleString();
       // ts.toISOString();
       draft.addTag("pastebin");
       draft.update();
       }

Options

  • After Success Default
    Notification Info
    Log Level Info

Comments

Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.