Skip to content

Commit 424e0be

Browse files
committed
add references for undocumented listed feat
1 parent d3d8a93 commit 424e0be

3 files changed

Lines changed: 112 additions & 0 deletions

File tree

reference-only/reference-list.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import fetch from 'node-fetch'
2+
import chalk from 'chalk'
3+
import data from '../../utils/data.js'
4+
import Colors from '../../utils/colors.js'
5+
6+
const list = async (options) => {
7+
const address = options.address || data.address()
8+
const path = `https://api.omg.lol/address/${address}/pastebin/`
9+
const fetchOptions = !options.address ? {
10+
method: 'GET',
11+
headers: {
12+
Authorization: `Bearer ${data.apikey()}`,
13+
"Content-Type": "application/json"
14+
},
15+
} : {}
16+
const response = await fetch(path, fetchOptions);
17+
const body = await response.json();
18+
19+
if (!body.response.pastebin.length) {
20+
console.log(chalk.red(`❌ No pastes found for ${address}`))
21+
return
22+
}
23+
24+
body.response.pastebin.forEach((paste) => {
25+
console.log(
26+
chalk[Colors.get()].bold(`https://${address}.paste.lol/${paste.title}`) +
27+
chalk.grey(` ${new Date(paste.modified_on * 1000).toDateString()} - ${paste.listed ? 'public' : 'private'}`)
28+
)
29+
});
30+
}
31+
32+
export default list

reference-only/reference-new.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import fetch from 'node-fetch'
2+
import chalk from 'chalk'
3+
import data from '../../utils/data.js'
4+
5+
const newPaste = async (title, content, options) => {
6+
const address = data.address()
7+
const response = await fetch(`https://api.omg.lol/address/${address}/pastebin/`, {
8+
method: 'POST',
9+
headers: {
10+
Authorization: `Bearer ${data.apikey()}`,
11+
"Content-Type": "application/json"
12+
},
13+
body: JSON.stringify({'title': title, 'content': content, listed: options.listed }),
14+
})
15+
const body = await response.json();
16+
17+
console.log(chalk.green(`✅ Purl created https://${address}.paste.lol/${body.response.title}`))
18+
}
19+
20+
export default newPaste
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Storing the omg.lol credentials in Draft's Credential instead of the action code directly
2+
var credential = Credential.create("omg.lol status", "Keep privately your omg.lol API key and your username");
3+
credential.addTextField("omg_username", "Your username");
4+
credential.addPasswordField("omg_api_key", "API Key");
5+
credential.authorize();
6+
7+
// We'll get the values and store them in our own variables
8+
let omg_api_key = credential.getValue("omg_api_key")
9+
let omg_username = credential.getValue("omg_username")
10+
11+
// Get the safe title of the current Draft and replace spaces with -
12+
var slugText = draft.processTemplate("Link content slug");
13+
var slug = slugText.toLowerCase()
14+
.replace(/["'=:!?@£#$%&\*\(\)\[\]_\+\|;~`<>,\.]+/g, '')
15+
.replace(/ +/g,'-');
16+
let title = slug
17+
18+
// Get the body of the of the current Draft removing empty line before and after
19+
let content = draft.processTemplate("[[trimmed_body]]")
20+
21+
// Create paste.lol direct link and copy to clipboard
22+
let link = "https://"+omg_username+".paste.lol/"+title
23+
let clipboard = app.setClipboard(link)
24+
25+
// Check if paste exists
26+
// API - https://api.omg.lol/#noauth-get-pastebin-retrieve-a-specific-paste
27+
28+
// var http = HTTP.create();
29+
// var response = http.request({
30+
// "url": "https://api.omg.lol/address/" + omg_username + "/pastebin",
31+
// "method": "GET"
32+
// });
33+
34+
// If above request.success = true
35+
// show title already exists error dialog
36+
// Click OK to return to your draft
37+
// else
38+
// continue with script
39+
40+
// use https://api.omg.lol/address/jomalo/pastebin/post-to-pastebin to verify
41+
42+
// Confirming there is more than one line in the current Draft then submit to the omg.lol pastebin :)
43+
// This creates a public paste - remove "listed": 1 for private
44+
// Should be made into a public Yes|No dialog
45+
if (title !== '' && content!== '') {
46+
var http = HTTP.create();
47+
var response = http.request({
48+
"url": "https://api.omg.lol/address/" + omg_username + "/pastebin",
49+
"method": "POST",
50+
"data": {
51+
"title": title,
52+
"content": content,
53+
"listed": 1
54+
},
55+
"headers": {
56+
"Authorization": "Bearer " + omg_api_key
57+
}
58+
});
59+
}
60+

0 commit comments

Comments
 (0)