Action

omg.lol pastebin

Posted by maique, Last update about 1 month ago

This action creates a new paste on omg.lol’s pastebin service, paste.lol.

First line will be “cleaned”, and used as paste title/filename, and the rest of the draft will be used as the paste.

The URL of the new paste will be on your clipboard when the action finishes.

You’ll need an omg.lol account, and the API key for that account. You’ll be asked for both during first run.

Thanks to:

mph https://directory.getdrafts.com/a/2Fh

podiboq https://actions.getdrafts.com/a/2DT

Steps

  • script

    // Storing the omg.lol credentials in Draft's Credential instead of the action code directly
    // Thank you podiboq: https://actions.getdrafts.com/a/2DT
    
    var credential = Credential.create("omg.lol pastebin", "Store your omg.lol API key username privately");
    credential.addTextField("omg_username", "Your username");
    credential.addPasswordField("omg_api_key", "API Key");
    credential.authorize();
    
    // Get the values and store them: 
    let omg_api_key = credential.getValue("omg_api_key")
    let omg_username = credential.getValue("omg_username")
    
    let safeTitle = draft.processTemplate("[[safe_title]]");
    let hyphenTitle = safeTitle.replaceAll(" ", "-");
    draft.setTemplateTag("hyphen_title", hyphenTitle);
    
    var post_title = hyphenTitle.toLowerCase();
    
    var content = draft.processTemplate("[[trimmed_body]]");
    
      var http = HTTP.create();
      var response = http.request({
    	"url": "https://api.omg.lol/address/" + omg_username + "/pastebin",
    	"method": "POST",
    	"data": {
    	  "title": post_title,
    	  "content": content,
    	},
    	"headers": {
    	  "Authorization": "Bearer " + omg_api_key
    	}
      });
    
    var final_url = "https://" + omg_username + ".paste.lol/" + post_title
    app.setClipboard(final_url);

Options

  • After Success Nothing , Tags: omg, pastebin
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.