Paste Clipboard Image as Cloudinary Markdown URL

Open paste-image-as-url in Script Kit

// Name: Paste Clipboard Image as Cloudinary Markdown URL
// Shortcut: opt shift v
import "@johnlindquist/kit"
let buffer = await clipboard.readImage()
if (buffer && buffer.length) {
let { default: cloudinary } = await npm("cloudinary")
cloudinary.config({
cloud_name: await env("CLOUDINARY_CLOUD_NAME"),
api_key: await env("CLOUDINARY_API_KEY"),
api_secret: await env("CLOUDINARY_API_SECRET"),
})
let response = await new Promise((response, reject) => {
let cloudStream = cloudinary.v2.uploader.upload_stream(
{
folder: "clipboard",
},
(error, result) => {
if (error) {
reject(error)
} else {
response(result)
}
}
)
new Readable({
read() {
this.push(buffer)
this.push(null)
},
}).pipe(cloudStream)
})
log(response)
// format however you want
let markdown = `![${response.url}](${response.url})`
await setSelectedText(markdown)
} else {
await div(md(`# No Image in Clipboard`))
}