upgraded API
This commit is contained in:
parent
59564cdbe6
commit
dff4d1adf1
|
@ -26,5 +26,9 @@ module.exports = {
|
|||
parser: '@typescript-eslint/parser'
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
rules: {
|
||||
'ts-expect-error': 'allow-with-description',
|
||||
'ts-ignore': 'allow-with-description'
|
||||
}
|
||||
};
|
|
@ -11,6 +11,7 @@
|
|||
"@sentry/node": "^7.73.0",
|
||||
"@ts-stack/markdown": "^1.5.0",
|
||||
"highlight.js": "^11.8.0",
|
||||
"highlightjs-zig": "^1.0.2",
|
||||
"mongodb": "^6.1.0",
|
||||
"random-words": "^2.0.0",
|
||||
"svelte-tabler": "^0.6.3"
|
||||
|
@ -23,6 +24,7 @@
|
|||
"@sveltejs/kit": "^1.20.4",
|
||||
"@tailwindcss/typography": "^0.5.10",
|
||||
"@types/node": "^20.8.2",
|
||||
"@types/prismjs": "^1.26.1",
|
||||
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
||||
"@typescript-eslint/parser": "^6.0.0",
|
||||
"autoprefixer": "^10.4.14",
|
||||
|
@ -690,6 +692,12 @@
|
|||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.2.tgz",
|
||||
"integrity": "sha512-Vvycsc9FQdwhxE3y3DzeIxuEJbWGDsnrxvMADzTDF/lcdR9/K+AQIeAghTQsHtotg/q0j3WEOYS/jQgSdWue3w=="
|
||||
},
|
||||
"node_modules/@types/prismjs": {
|
||||
"version": "1.26.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/prismjs/-/prismjs-1.26.1.tgz",
|
||||
"integrity": "sha512-Q7jDsRbzcNHIQje15CS/piKhu6lMLb9jwjxSfEIi4KcFKXW23GoJMkwQiJ8VObyfx+VmUaDcJxXaWN+cTCjVog==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/pug": {
|
||||
"version": "2.0.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/pug/-/pug-2.0.7.tgz",
|
||||
|
@ -708,11 +716,6 @@
|
|||
"integrity": "sha512-OxepLK9EuNEIPxWNME+C6WwbRAOOI2o2BaQEGzz5Lu2e4Z5eDnEo+/aVEDMIXywoJitJ7xWd641wrGLZdtwRyw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/unist": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.0.tgz",
|
||||
"integrity": "sha512-MFETx3tbTjE7Uk6vvnWINA/1iJ7LuMdO4fcq8UfF0pRbj01aGLduVvQcRyswuACJdpnHgg8E3rQLhaRdNEJS0w=="
|
||||
},
|
||||
"node_modules/@types/webidl-conversions": {
|
||||
"version": "7.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.1.tgz",
|
||||
|
@ -2010,12 +2013,6 @@
|
|||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/hast": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/hast/-/hast-1.0.0.tgz",
|
||||
"integrity": "sha512-vFUqlRV5C+xqP76Wwq2SrM0kipnmpxJm7OfvVXpB35Fp+Fn4MV+ozr+JZr5qFvyR1q/U+Foim2x+3P+x9S1PLA==",
|
||||
"deprecated": "Renamed to rehype"
|
||||
},
|
||||
"node_modules/highlight.js": {
|
||||
"version": "11.8.0",
|
||||
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-11.8.0.tgz",
|
||||
|
@ -2024,10 +2021,10 @@
|
|||
"node": ">=12.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/highlightjs-line-numbers.js": {
|
||||
"version": "2.8.0",
|
||||
"resolved": "https://registry.npmjs.org/highlightjs-line-numbers.js/-/highlightjs-line-numbers.js-2.8.0.tgz",
|
||||
"integrity": "sha512-TEf1gw0c8mb8nan0QwliqS7obT4cpUd9hzsGzsZLweteNnWea/VIqy5/aQqsa5wnz9lnvmtAkS1ZtDTjB/goYQ=="
|
||||
"node_modules/highlightjs-zig": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/highlightjs-zig/-/highlightjs-zig-1.0.2.tgz",
|
||||
"integrity": "sha512-ZPSQfyiUMmux685sTNzTXuvXAXH6Gqzc+WSRzhYiknCRELjma1FOdTJ/zs8L9KutmX+YOtdlkmS+NypOxInpqA=="
|
||||
},
|
||||
"node_modules/https-proxy-agent": {
|
||||
"version": "5.0.1",
|
||||
|
@ -3689,45 +3686,6 @@
|
|||
"node": ">=14.0"
|
||||
}
|
||||
},
|
||||
"node_modules/unist-util-is": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz",
|
||||
"integrity": "sha512-2qCTHimwdxLfz+YzdGfkqNlH0tLi9xjTnHddPmJwtIG9MGsdbutfTc4P+haPD7l7Cjxf/WZj+we5qfVPvvxfYw==",
|
||||
"dependencies": {
|
||||
"@types/unist": "^3.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
},
|
||||
"node_modules/unist-util-visit": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.0.0.tgz",
|
||||
"integrity": "sha512-MR04uvD+07cwl/yhVuVWAtw+3GOR/knlL55Nd/wAdblk27GCVt3lqpTivy/tkJcZoNPzTwS1Y+KMojlLDhoTzg==",
|
||||
"dependencies": {
|
||||
"@types/unist": "^3.0.0",
|
||||
"unist-util-is": "^6.0.0",
|
||||
"unist-util-visit-parents": "^6.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
},
|
||||
"node_modules/unist-util-visit-parents": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/unist-util-visit-parents/-/unist-util-visit-parents-6.0.1.tgz",
|
||||
"integrity": "sha512-L/PqWzfTP9lzzEa6CKs0k2nARxTdZduw3zyh8d2NVBnsyvHjSX4TWse388YrrQKbvI8w20fGjGlhgT96WwKykw==",
|
||||
"dependencies": {
|
||||
"@types/unist": "^3.0.0",
|
||||
"unist-util-is": "^6.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
}
|
||||
},
|
||||
"node_modules/update-browserslist-db": {
|
||||
"version": "1.0.13",
|
||||
"resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz",
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
"@sveltejs/kit": "^1.20.4",
|
||||
"@tailwindcss/typography": "^0.5.10",
|
||||
"@types/node": "^20.8.2",
|
||||
"@types/prismjs": "^1.26.1",
|
||||
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
||||
"@typescript-eslint/parser": "^6.0.0",
|
||||
"autoprefixer": "^10.4.14",
|
||||
|
@ -35,6 +36,7 @@
|
|||
"prettier-plugin-svelte": "^2.10.1",
|
||||
"svelte": "^4.0.5",
|
||||
"svelte-check": "^3.4.3",
|
||||
"svelte-tabler": "^0.6.3",
|
||||
"tailwindcss": "^3.3.2",
|
||||
"tslib": "^2.4.1",
|
||||
"typescript": "^5.0.0",
|
||||
|
@ -45,8 +47,8 @@
|
|||
"@sentry/node": "^7.73.0",
|
||||
"@ts-stack/markdown": "^1.5.0",
|
||||
"highlight.js": "^11.8.0",
|
||||
"highlightjs-zig": "^1.0.2",
|
||||
"mongodb": "^6.1.0",
|
||||
"random-words": "^2.0.0",
|
||||
"svelte-tabler": "^0.6.3"
|
||||
"random-words": "^2.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,38 @@
|
|||
<script lang="ts">
|
||||
import { Copy, DeviceFloppy, Moon, Sun, TextPlus } from 'svelte-tabler';
|
||||
import { ChevronDown, ChevronRight, ChevronUp, Copy, DeviceFloppy, Moon, Sun, TextPlus } from 'svelte-tabler';
|
||||
import { storeHighlightJs } from '@skeletonlabs/skeleton';
|
||||
import { CodeBlock } from '@skeletonlabs/skeleton';
|
||||
import ToolBox from '$lib/components/ToolBox.svelte';
|
||||
import hljs from '$utils/hljs';
|
||||
import { extensionMap } from '$utils/languages';
|
||||
import { goto } from '$app/navigation';
|
||||
|
||||
storeHighlightJs.set(hljs);
|
||||
|
||||
let showLanguages = false;
|
||||
|
||||
const toggleLanguages = () => {
|
||||
showLanguages = !showLanguages;
|
||||
};
|
||||
|
||||
// Split languages into four columns.
|
||||
const languages = Object.entries(extensionMap).reduce((acc, [language, extensions], i) => {
|
||||
const column = Math.floor(i / Math.ceil(Object.entries(extensionMap).length / 5));
|
||||
acc[column] = acc[column] || [] as { language: string, extensions: string[] }[];
|
||||
acc[column].push({ language, extensions: extensions.map(ext => `.${ext}`) });
|
||||
return acc;
|
||||
}, [] as { language: string, extensions: string[] }[][]);
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Paste69 - About</title>
|
||||
</svelte:head>
|
||||
|
||||
<div class="fixed bottom-0 right-0 w-full md:w-auto">
|
||||
<ToolBox disableSave={true} disableCopy={true} on:new={() => goto('/')} />
|
||||
<div class="absolute top-[23px] left-[5px]">
|
||||
<ChevronRight />
|
||||
</div>
|
||||
|
||||
<div class="pl-2 pr-2 max-w-[100ch] pb-24">
|
||||
<div class="pl-12 pt-4 pb-24 max-w-[100ch]">
|
||||
<h1 class="h1 mb-2">Paste69</h1>
|
||||
|
||||
<p class="mb-4 mt-4">
|
||||
|
@ -29,9 +44,36 @@
|
|||
|
||||
<p class="mb-4 mt-4">
|
||||
Code highlighting is handled with the help of <a class="underline hover:text-gray-300" href="https://highlightjs.org/">highlight.js</a>.
|
||||
So if you have any issues with language detection or missing languages, take it up with them.
|
||||
So if you have any issues with language detection or missing languages, take it up with them. Available languages (with their
|
||||
extensions) are as follows:
|
||||
<button
|
||||
class="inline-block ml-2 px-2"
|
||||
on:click={toggleLanguages}
|
||||
>
|
||||
{showLanguages ? 'Hide' : 'Show'} Languages
|
||||
{#if showLanguages}
|
||||
<ChevronUp class="inline-block w-4 h-4" />
|
||||
{:else}
|
||||
<ChevronDown class="inline-block w-4 h-4" />
|
||||
{/if}
|
||||
</button>
|
||||
</p>
|
||||
|
||||
{#if showLanguages}
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-x-4">
|
||||
{#each languages as column}
|
||||
<div>
|
||||
{#each column as { language, extensions }}
|
||||
<div class="mb-2">
|
||||
<span class="font-bold">{language}</span>
|
||||
<span class="text-gray-400"> ({extensions.join(', ')})</span>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<h2 id="usage" class="h2 mt-4 mb-2"><a class="underline hover:text-gray-300" href="#usage">Usage</a></h2>
|
||||
|
||||
<p class="mb-4 mt-4">
|
||||
|
@ -52,28 +94,31 @@
|
|||
|
||||
<p class="mb-4 mt-4">
|
||||
To make it easier to create pastes, a CLI script is available. The script can be found <a
|
||||
href="/paste69.sh">here</a
|
||||
class="underline hover:text-gray-300" href="/paste69.sh">here</a
|
||||
>. To use the script:
|
||||
</p>
|
||||
|
||||
<CodeBlock language="bash" code={`$ curl -O https://0x45.st/paste69.sh && chmod +x paste69.sh<br />
|
||||
$ ./paste69.sh --help<br /><br />
|
||||
<CodeBlock language="bash" code={`curl -O https://0x45.st/paste69.sh && chmod +x paste69.sh
|
||||
./paste69.sh --help
|
||||
|
||||
Paste69 CLI script<br /><br />
|
||||
|
||||
Usage:<br />
|
||||
paste69 <file> [options]<br />
|
||||
cat <file> | paste69 [options]<br /><br />
|
||||
|
||||
Options:<br />
|
||||
-h, --help Show this help text<br />
|
||||
-r, --raw Return the raw JSON response<br />
|
||||
-c, --copy Copy the paste URL to the clipboard<br />`}></CodeBlock>
|
||||
# Paste69 CLI script
|
||||
#
|
||||
# Usage:
|
||||
# paste69 <file> [options]
|
||||
# cat <file> | paste69 [options]
|
||||
#
|
||||
# Options:
|
||||
# -h, --help Show this help text.
|
||||
# -l, --language <language> Set the language of the paste.
|
||||
# -p, --password <password> Set a password for the paste. This enables encryption.
|
||||
# -x, --burn Burn the paste after it is viewed once.
|
||||
# -r, --raw Return the raw JSON response.
|
||||
# -c, --copy Copy the paste URL to the clipboard.`}></CodeBlock>
|
||||
|
||||
<p class="mb-4 mt-4">To create a paste with the script, simply pipe the contents of a file to the script:</p>
|
||||
|
||||
<CodeBlock language="bash" code={`$ cat file.md | ./paste69.sh<br />
|
||||
https://0x45.st/some-random-id.md`}></CodeBlock>
|
||||
<CodeBlock language="bash" code={`cat file.md | ./paste69.sh
|
||||
# https://0x45.st/some-random-id.md`}></CodeBlock>
|
||||
|
||||
<h2 id="api" class="h2 mt-4 mb-2"><a class="underline hover:text-gray-300" href="#api">API</a></h2>
|
||||
|
||||
|
@ -89,14 +134,23 @@ https://0x45.st/some-random-id.md`}></CodeBlock>
|
|||
with the following JSON body:
|
||||
</p>
|
||||
|
||||
<CodeBlock language="json" code={`{ "contents": "paste contents" }`}></CodeBlock>
|
||||
<CodeBlock language="json" code={`{
|
||||
"contents": "paste contents",
|
||||
"language": "txt",
|
||||
"encrypt": false,
|
||||
"password": "",
|
||||
"burnAfterReading": false,
|
||||
}`}></CodeBlock>
|
||||
|
||||
<p class="mb-4 mt-4">If the paste was successfully created, the API will respond with the following JSON:</p>
|
||||
|
||||
<CodeBlock language="json" code={`{
|
||||
"id": "paste id",
|
||||
"url": "https://0x45.st/some-random-id.md",
|
||||
"contents": "paste contents",
|
||||
"highlight": "txt",
|
||||
"encrypted": false,
|
||||
"burnAfterReading": false,
|
||||
"created_at": "2021-08-05T07:30:00.000Z",
|
||||
}`}></CodeBlock>
|
||||
|
||||
|
@ -111,8 +165,15 @@ https://0x45.st/some-random-id.md`}></CodeBlock>
|
|||
|
||||
<CodeBlock language="json" code={`{
|
||||
"id": "paste id",
|
||||
"url": "https://0x45.st/some-random-id.md",
|
||||
"contents": "paste contents",
|
||||
"highlight": "txt",
|
||||
"encrypted": false,
|
||||
"burnAfterReading": false,
|
||||
"created_at": "2021-08-05T07:30:00.000Z",
|
||||
}`}></CodeBlock>
|
||||
</div>
|
||||
|
||||
<div class="fixed bottom-0 right-0 w-full md:w-auto">
|
||||
<ToolBox disableSave={true} disableCopy={true} on:new={() => goto('/')} />
|
||||
</div>
|
|
@ -4,17 +4,29 @@ import { error, json, type RequestHandler } from "@sveltejs/kit";
|
|||
import { generate } from 'random-words';
|
||||
import { pastes } from "$db/index";
|
||||
import { SITE_URL } from "$env/static/private";
|
||||
import { extensionMap } from "$utils/languages";
|
||||
|
||||
export const POST: RequestHandler = async ({ request }) => {
|
||||
const { contents, encrypt, password, burnAfterReading } = await request.json();
|
||||
const { contents, language, encrypt, password, burnAfterReading } = await request.json();
|
||||
const id = generate({ exactly: 3, join: '-' });
|
||||
|
||||
if (!contents || contents.length === 0) {
|
||||
throw error(400, 'No contents provided');
|
||||
}
|
||||
|
||||
if (language && language.length > 0) {
|
||||
// Check the language names, as well as the extensions for each language.
|
||||
// Try to make it as efficient as possible.
|
||||
const lang = language.toLowerCase();
|
||||
const languages = Object.keys(extensionMap);
|
||||
const extensions = Object.values(extensionMap).flat();
|
||||
if (!languages.includes(lang) && !extensions.includes(lang)) {
|
||||
throw error(400, 'Invalid language');
|
||||
}
|
||||
}
|
||||
|
||||
let pasteContents: string = contents;
|
||||
const highlight = detectLanguage(contents) || 'txt';
|
||||
const highlight = language || detectLanguage(contents) || 'txt';
|
||||
|
||||
if (encrypt && !password) {
|
||||
throw error(400, 'No password provided for encryption.');
|
||||
|
@ -32,6 +44,8 @@ export const POST: RequestHandler = async ({ request }) => {
|
|||
createdAt: new Date(),
|
||||
};
|
||||
|
||||
console.log(data);
|
||||
|
||||
const res = await pastes.insertOne(data);
|
||||
|
||||
if (!res.acknowledged) {
|
||||
|
|
|
@ -4,7 +4,7 @@ import { extensionMap, languages } from './languages';
|
|||
// Theme
|
||||
import 'highlight.js/styles/github-dark.css';
|
||||
|
||||
const autoLanguages = ['js', 'ts', 'css', 'html', 'json', 'md', 'php', 'py', 'rb', 'rs', 'shell'];
|
||||
const autoLanguages = ['js', 'ts', 'css', 'go', 'html', 'json', 'md', 'php', 'py', 'rb', 'rs', 'bash'];
|
||||
|
||||
for (const [lang, exts] of Object.entries(extensionMap)) {
|
||||
if (exts.length > 0) {
|
||||
|
|
|
@ -1,41 +1,18 @@
|
|||
import _1c from 'highlight.js/lib/languages/1c';
|
||||
import abnf from 'highlight.js/lib/languages/abnf';
|
||||
import accesslog from 'highlight.js/lib/languages/accesslog';
|
||||
import actionscript from 'highlight.js/lib/languages/actionscript';
|
||||
import ada from 'highlight.js/lib/languages/ada';
|
||||
import angelscript from 'highlight.js/lib/languages/angelscript';
|
||||
import apache from 'highlight.js/lib/languages/apache';
|
||||
import applescript from 'highlight.js/lib/languages/applescript';
|
||||
import arcade from 'highlight.js/lib/languages/arcade';
|
||||
import arduino from 'highlight.js/lib/languages/arduino';
|
||||
import armasm from 'highlight.js/lib/languages/armasm';
|
||||
import asciidoc from 'highlight.js/lib/languages/asciidoc';
|
||||
import aspectj from 'highlight.js/lib/languages/aspectj';
|
||||
import autohotkey from 'highlight.js/lib/languages/autohotkey';
|
||||
import autoit from 'highlight.js/lib/languages/autoit';
|
||||
import avrasm from 'highlight.js/lib/languages/avrasm';
|
||||
import awk from 'highlight.js/lib/languages/awk';
|
||||
import axapta from 'highlight.js/lib/languages/axapta';
|
||||
import bash from 'highlight.js/lib/languages/bash';
|
||||
import basic from 'highlight.js/lib/languages/basic';
|
||||
import bnf from 'highlight.js/lib/languages/bnf';
|
||||
import brainfuck from 'highlight.js/lib/languages/brainfuck';
|
||||
import _c from 'highlight.js/lib/languages/c';
|
||||
import cal from 'highlight.js/lib/languages/cal';
|
||||
import capnproto from 'highlight.js/lib/languages/capnproto';
|
||||
import ceylon from 'highlight.js/lib/languages/ceylon';
|
||||
import clean from 'highlight.js/lib/languages/clean';
|
||||
import clojure_repl from 'highlight.js/lib/languages/clojure-repl';
|
||||
import c from 'highlight.js/lib/languages/c';
|
||||
import clojure from 'highlight.js/lib/languages/clojure';
|
||||
import cmake from 'highlight.js/lib/languages/cmake';
|
||||
import coffeescript from 'highlight.js/lib/languages/coffeescript';
|
||||
import coq from 'highlight.js/lib/languages/coq';
|
||||
import cos from 'highlight.js/lib/languages/cos';
|
||||
import cpp from 'highlight.js/lib/languages/cpp';
|
||||
import crmsh from 'highlight.js/lib/languages/crmsh';
|
||||
import crystal from 'highlight.js/lib/languages/crystal';
|
||||
import csharp from 'highlight.js/lib/languages/csharp';
|
||||
import csp from 'highlight.js/lib/languages/csp';
|
||||
import css from 'highlight.js/lib/languages/css';
|
||||
import d from 'highlight.js/lib/languages/d';
|
||||
import dart from 'highlight.js/lib/languages/dart';
|
||||
|
@ -44,29 +21,17 @@ import diff from 'highlight.js/lib/languages/diff';
|
|||
import django from 'highlight.js/lib/languages/django';
|
||||
import dns from 'highlight.js/lib/languages/dns';
|
||||
import dockerfile from 'highlight.js/lib/languages/dockerfile';
|
||||
import dos from 'highlight.js/lib/languages/dos';
|
||||
import dsconfig from 'highlight.js/lib/languages/dsconfig';
|
||||
import dts from 'highlight.js/lib/languages/dts';
|
||||
import dust from 'highlight.js/lib/languages/dust';
|
||||
import ebnf from 'highlight.js/lib/languages/ebnf';
|
||||
import elixir from 'highlight.js/lib/languages/elixir';
|
||||
import elm from 'highlight.js/lib/languages/elm';
|
||||
import erb from 'highlight.js/lib/languages/erb';
|
||||
import erlang_repl from 'highlight.js/lib/languages/erlang-repl';
|
||||
import erlang from 'highlight.js/lib/languages/erlang';
|
||||
import excel from 'highlight.js/lib/languages/excel';
|
||||
import fix from 'highlight.js/lib/languages/fix';
|
||||
import flix from 'highlight.js/lib/languages/flix';
|
||||
import fortran from 'highlight.js/lib/languages/fortran';
|
||||
import fsharp from 'highlight.js/lib/languages/fsharp';
|
||||
import gams from 'highlight.js/lib/languages/gams';
|
||||
import gauss from 'highlight.js/lib/languages/gauss';
|
||||
import gcode from 'highlight.js/lib/languages/gcode';
|
||||
import gherkin from 'highlight.js/lib/languages/gherkin';
|
||||
import glsl from 'highlight.js/lib/languages/glsl';
|
||||
import gml from 'highlight.js/lib/languages/gml';
|
||||
import go from 'highlight.js/lib/languages/go';
|
||||
import golo from 'highlight.js/lib/languages/golo';
|
||||
import gradle from 'highlight.js/lib/languages/gradle';
|
||||
import graphql from 'highlight.js/lib/languages/graphql';
|
||||
import groovy from 'highlight.js/lib/languages/groovy';
|
||||
|
@ -74,159 +39,76 @@ import haml from 'highlight.js/lib/languages/haml';
|
|||
import handlebars from 'highlight.js/lib/languages/handlebars';
|
||||
import haskell from 'highlight.js/lib/languages/haskell';
|
||||
import haxe from 'highlight.js/lib/languages/haxe';
|
||||
import hsp from 'highlight.js/lib/languages/hsp';
|
||||
import http from 'highlight.js/lib/languages/http';
|
||||
import hy from 'highlight.js/lib/languages/hy';
|
||||
import inform7 from 'highlight.js/lib/languages/inform7';
|
||||
import ini from 'highlight.js/lib/languages/ini';
|
||||
import irpf90 from 'highlight.js/lib/languages/irpf90';
|
||||
import isbl from 'highlight.js/lib/languages/isbl';
|
||||
import java from 'highlight.js/lib/languages/java';
|
||||
import javascript from 'highlight.js/lib/languages/javascript';
|
||||
import json from 'highlight.js/lib/languages/json';
|
||||
import julia_repl from 'highlight.js/lib/languages/julia-repl';
|
||||
import julia from 'highlight.js/lib/languages/julia';
|
||||
import kotlin from 'highlight.js/lib/languages/kotlin';
|
||||
import lasso from 'highlight.js/lib/languages/lasso';
|
||||
import latex from 'highlight.js/lib/languages/latex';
|
||||
import ldif from 'highlight.js/lib/languages/ldif';
|
||||
import leaf from 'highlight.js/lib/languages/leaf';
|
||||
import less from 'highlight.js/lib/languages/less';
|
||||
import lisp from 'highlight.js/lib/languages/lisp';
|
||||
import livecodeserver from 'highlight.js/lib/languages/livecodeserver';
|
||||
import livescript from 'highlight.js/lib/languages/livescript';
|
||||
import llvm from 'highlight.js/lib/languages/llvm';
|
||||
import lsl from 'highlight.js/lib/languages/lsl';
|
||||
import lua from 'highlight.js/lib/languages/lua';
|
||||
import makefile from 'highlight.js/lib/languages/makefile';
|
||||
import markdown from 'highlight.js/lib/languages/markdown';
|
||||
import mathematica from 'highlight.js/lib/languages/mathematica';
|
||||
import matlab from 'highlight.js/lib/languages/matlab';
|
||||
import maxima from 'highlight.js/lib/languages/maxima';
|
||||
import mel from 'highlight.js/lib/languages/mel';
|
||||
import mercury from 'highlight.js/lib/languages/mercury';
|
||||
import mipsasm from 'highlight.js/lib/languages/mipsasm';
|
||||
import mizar from 'highlight.js/lib/languages/mizar';
|
||||
import mojolicious from 'highlight.js/lib/languages/mojolicious';
|
||||
import monkey from 'highlight.js/lib/languages/monkey';
|
||||
import moonscript from 'highlight.js/lib/languages/moonscript';
|
||||
import n1ql from 'highlight.js/lib/languages/n1ql';
|
||||
import nestedtext from 'highlight.js/lib/languages/nestedtext';
|
||||
import nginx from 'highlight.js/lib/languages/nginx';
|
||||
import nim from 'highlight.js/lib/languages/nim';
|
||||
import nix from 'highlight.js/lib/languages/nix';
|
||||
import node_repl from 'highlight.js/lib/languages/node-repl';
|
||||
import nsis from 'highlight.js/lib/languages/nsis';
|
||||
import objectivec from 'highlight.js/lib/languages/objectivec';
|
||||
import ocaml from 'highlight.js/lib/languages/ocaml';
|
||||
import openscad from 'highlight.js/lib/languages/openscad';
|
||||
import oxygene from 'highlight.js/lib/languages/oxygene';
|
||||
import parser3 from 'highlight.js/lib/languages/parser3';
|
||||
import perl from 'highlight.js/lib/languages/perl';
|
||||
import pf from 'highlight.js/lib/languages/pf';
|
||||
import pgsql from 'highlight.js/lib/languages/pgsql';
|
||||
import php from 'highlight.js/lib/languages/php';
|
||||
import plaintext from 'highlight.js/lib/languages/plaintext';
|
||||
import pony from 'highlight.js/lib/languages/pony';
|
||||
import powershell from 'highlight.js/lib/languages/powershell';
|
||||
import processing from 'highlight.js/lib/languages/processing';
|
||||
import profile from 'highlight.js/lib/languages/profile';
|
||||
import prolog from 'highlight.js/lib/languages/prolog';
|
||||
import properties from 'highlight.js/lib/languages/properties';
|
||||
import protobuf from 'highlight.js/lib/languages/protobuf';
|
||||
import puppet from 'highlight.js/lib/languages/puppet';
|
||||
import purebasic from 'highlight.js/lib/languages/purebasic';
|
||||
import python_repl from 'highlight.js/lib/languages/python-repl';
|
||||
import python from 'highlight.js/lib/languages/python';
|
||||
import q from 'highlight.js/lib/languages/q';
|
||||
import qml from 'highlight.js/lib/languages/qml';
|
||||
import r from 'highlight.js/lib/languages/r';
|
||||
import reasonml from 'highlight.js/lib/languages/reasonml';
|
||||
import rib from 'highlight.js/lib/languages/rib';
|
||||
import roboconf from 'highlight.js/lib/languages/roboconf';
|
||||
import routeros from 'highlight.js/lib/languages/routeros';
|
||||
import rsl from 'highlight.js/lib/languages/rsl';
|
||||
import ruby from 'highlight.js/lib/languages/ruby';
|
||||
import ruleslanguage from 'highlight.js/lib/languages/ruleslanguage';
|
||||
import rust from 'highlight.js/lib/languages/rust';
|
||||
import sas from 'highlight.js/lib/languages/sas';
|
||||
import scala from 'highlight.js/lib/languages/scala';
|
||||
import scheme from 'highlight.js/lib/languages/scheme';
|
||||
import scilab from 'highlight.js/lib/languages/scilab';
|
||||
import scss from 'highlight.js/lib/languages/scss';
|
||||
import shell from 'highlight.js/lib/languages/shell';
|
||||
import smali from 'highlight.js/lib/languages/smali';
|
||||
import smalltalk from 'highlight.js/lib/languages/smalltalk';
|
||||
import sml from 'highlight.js/lib/languages/sml';
|
||||
import sqf from 'highlight.js/lib/languages/sqf';
|
||||
import sql from 'highlight.js/lib/languages/sql';
|
||||
import stan from 'highlight.js/lib/languages/stan';
|
||||
import stata from 'highlight.js/lib/languages/stata';
|
||||
import step21 from 'highlight.js/lib/languages/step21';
|
||||
import stylus from 'highlight.js/lib/languages/stylus';
|
||||
import subunit from 'highlight.js/lib/languages/subunit';
|
||||
import swift from 'highlight.js/lib/languages/swift';
|
||||
import taggerscript from 'highlight.js/lib/languages/taggerscript';
|
||||
import tap from 'highlight.js/lib/languages/tap';
|
||||
import tcl from 'highlight.js/lib/languages/tcl';
|
||||
import thrift from 'highlight.js/lib/languages/thrift';
|
||||
import tp from 'highlight.js/lib/languages/tp';
|
||||
import twig from 'highlight.js/lib/languages/twig';
|
||||
import typescript from 'highlight.js/lib/languages/typescript';
|
||||
import vala from 'highlight.js/lib/languages/vala';
|
||||
import vbnet from 'highlight.js/lib/languages/vbnet';
|
||||
import vbscript from 'highlight.js/lib/languages/vbscript';
|
||||
import verilog from 'highlight.js/lib/languages/verilog';
|
||||
import vhdl from 'highlight.js/lib/languages/vhdl';
|
||||
import vim from 'highlight.js/lib/languages/vim';
|
||||
import wasm from 'highlight.js/lib/languages/wasm';
|
||||
import wren from 'highlight.js/lib/languages/wren';
|
||||
import x86asm from 'highlight.js/lib/languages/x86asm';
|
||||
import xl from 'highlight.js/lib/languages/xl';
|
||||
import xml from 'highlight.js/lib/languages/xml';
|
||||
import xquery from 'highlight.js/lib/languages/xquery';
|
||||
import yaml from 'highlight.js/lib/languages/yaml';
|
||||
import zephir from 'highlight.js/lib/languages/zephir';
|
||||
|
||||
// @ts-ignore: No types available
|
||||
// import zig from 'highlightjs-zig';
|
||||
|
||||
export const languages = {
|
||||
'1c': _1c,
|
||||
abnf,
|
||||
accesslog,
|
||||
actionscript,
|
||||
ada,
|
||||
angelscript,
|
||||
apache,
|
||||
applescript,
|
||||
arcade,
|
||||
arduino,
|
||||
armasm,
|
||||
asciidoc,
|
||||
aspectj,
|
||||
autohotkey,
|
||||
autoit,
|
||||
avrasm,
|
||||
awk,
|
||||
axapta,
|
||||
bash,
|
||||
basic,
|
||||
bnf,
|
||||
brainfuck,
|
||||
c: _c,
|
||||
cal,
|
||||
capnproto,
|
||||
ceylon,
|
||||
clean,
|
||||
clojure_repl,
|
||||
c,
|
||||
clojure,
|
||||
cmake,
|
||||
coffeescript,
|
||||
coq,
|
||||
cos,
|
||||
cpp,
|
||||
crmsh,
|
||||
crystal,
|
||||
csharp,
|
||||
csp,
|
||||
css,
|
||||
d,
|
||||
dart,
|
||||
|
@ -235,29 +117,17 @@ export const languages = {
|
|||
django,
|
||||
dns,
|
||||
dockerfile,
|
||||
dos,
|
||||
dsconfig,
|
||||
dts,
|
||||
dust,
|
||||
ebnf,
|
||||
elixir,
|
||||
elm,
|
||||
erb,
|
||||
erlang_repl,
|
||||
erlang,
|
||||
excel,
|
||||
fix,
|
||||
flix,
|
||||
fortran,
|
||||
fsharp,
|
||||
gams,
|
||||
gauss,
|
||||
gcode,
|
||||
gherkin,
|
||||
glsl,
|
||||
gml,
|
||||
go,
|
||||
golo,
|
||||
gradle,
|
||||
graphql,
|
||||
groovy,
|
||||
|
@ -265,160 +135,75 @@ export const languages = {
|
|||
handlebars,
|
||||
haskell,
|
||||
haxe,
|
||||
hsp,
|
||||
http,
|
||||
hy,
|
||||
inform7,
|
||||
ini,
|
||||
irpf90,
|
||||
isbl,
|
||||
java,
|
||||
javascript,
|
||||
json,
|
||||
julia_repl,
|
||||
julia,
|
||||
kotlin,
|
||||
lasso,
|
||||
latex,
|
||||
ldif,
|
||||
leaf,
|
||||
less,
|
||||
lisp,
|
||||
livecodeserver,
|
||||
livescript,
|
||||
llvm,
|
||||
lsl,
|
||||
lua,
|
||||
makefile,
|
||||
markdown,
|
||||
mathematica,
|
||||
matlab,
|
||||
maxima,
|
||||
mel,
|
||||
mercury,
|
||||
mipsasm,
|
||||
mizar,
|
||||
mojolicious,
|
||||
monkey,
|
||||
moonscript,
|
||||
n1ql,
|
||||
nestedtext,
|
||||
nginx,
|
||||
nim,
|
||||
nix,
|
||||
node_repl,
|
||||
nsis,
|
||||
objectivec,
|
||||
ocaml,
|
||||
openscad,
|
||||
oxygene,
|
||||
parser3,
|
||||
perl,
|
||||
pf,
|
||||
pgsql,
|
||||
php,
|
||||
plaintext,
|
||||
pony,
|
||||
powershell,
|
||||
processing,
|
||||
profile,
|
||||
prolog,
|
||||
properties,
|
||||
protobuf,
|
||||
puppet,
|
||||
purebasic,
|
||||
python_repl,
|
||||
python,
|
||||
q,
|
||||
qml,
|
||||
r,
|
||||
reasonml,
|
||||
rib,
|
||||
roboconf,
|
||||
routeros,
|
||||
rsl,
|
||||
ruby,
|
||||
ruleslanguage,
|
||||
rust,
|
||||
sas,
|
||||
scala,
|
||||
scheme,
|
||||
scilab,
|
||||
scss,
|
||||
shell,
|
||||
smali,
|
||||
smalltalk,
|
||||
sml,
|
||||
sqf,
|
||||
sql,
|
||||
stan,
|
||||
stata,
|
||||
step21,
|
||||
stylus,
|
||||
subunit,
|
||||
swift,
|
||||
taggerscript,
|
||||
tap,
|
||||
tcl,
|
||||
thrift,
|
||||
tp,
|
||||
twig,
|
||||
typescript,
|
||||
vala,
|
||||
vbnet,
|
||||
vbscript,
|
||||
verilog,
|
||||
vhdl,
|
||||
vim,
|
||||
wasm,
|
||||
wren,
|
||||
x86asm,
|
||||
xl,
|
||||
xml,
|
||||
xquery,
|
||||
yaml,
|
||||
zephir
|
||||
// zig,
|
||||
};
|
||||
|
||||
export const extensionMap: Record<string, string[]> = {
|
||||
'1c': [],
|
||||
abnf: [],
|
||||
accesslog: [],
|
||||
actionscript: ['as'],
|
||||
ada: ['ada', 'adb', 'ads'],
|
||||
angelscript: ['angelscript'],
|
||||
apache: ['apache'],
|
||||
applescript: ['app'],
|
||||
arcade: ['arcade'],
|
||||
arduino: ['ino'],
|
||||
armasm: ['s'],
|
||||
asciidoc: ['adoc'],
|
||||
aspectj: ['aj'],
|
||||
autohotkey: ['ahk'],
|
||||
autoit: ['au3'],
|
||||
avrasm: ['s'],
|
||||
awk: ['awk'],
|
||||
axapta: ['ax'],
|
||||
bash: ['sh', 'bash'],
|
||||
basic: ['bas'],
|
||||
bnf: ['bnf'],
|
||||
brainfuck: ['b', 'bf'],
|
||||
c: ['c'],
|
||||
cal: ['cal'],
|
||||
capnproto: ['capnp'],
|
||||
ceylon: ['ceylon'],
|
||||
clean: ['icl', 'dcl'],
|
||||
'clojure-repl': [],
|
||||
clojure: ['clj', 'cljc', 'cljx', 'cljs'],
|
||||
cmake: ['CMakeLists.txt', 'cmake'],
|
||||
cmake: ['cmake'],
|
||||
coffeescript: ['coffee'],
|
||||
coq: ['v'],
|
||||
cos: ['cls', 'int'],
|
||||
cpp: ['cpp', 'cc', 'h', 'C', 'H', 'hpp'],
|
||||
crmsh: ['crm'],
|
||||
crystal: ['cr'],
|
||||
csharp: ['cs'],
|
||||
csp: ['csp'],
|
||||
css: ['css'],
|
||||
d: ['d'],
|
||||
dart: ['dart'],
|
||||
|
@ -427,29 +212,17 @@ export const extensionMap: Record<string, string[]> = {
|
|||
django: ['djhtml'],
|
||||
dns: ['zone', 'bind'],
|
||||
dockerfile: ['Dockerfile'],
|
||||
dos: ['bat', 'cmd'],
|
||||
dsconfig: ['dsconfig'],
|
||||
dts: ['dts'],
|
||||
dust: ['dust'],
|
||||
ebnf: ['ebnf'],
|
||||
elixir: ['ex', 'exs'],
|
||||
elm: ['elm'],
|
||||
erb: ['erb'],
|
||||
'erlang-repl': [],
|
||||
erlang: ['erl', 'hrl'],
|
||||
excel: ['xls', 'xlsx'],
|
||||
fix: ['fix'],
|
||||
flix: ['flix'],
|
||||
fortran: ['f', 'for', 'f90', 'f95'],
|
||||
fsharp: ['fs', 'fsi'],
|
||||
gams: ['gms'],
|
||||
gauss: ['gss', 'gms'],
|
||||
gcode: ['gcode'],
|
||||
gherkin: ['feature'],
|
||||
glsl: ['vert', 'frag', 'geom'],
|
||||
gml: ['gml'],
|
||||
go: ['go'],
|
||||
golo: ['golo'],
|
||||
gradle: ['gradle'],
|
||||
graphql: ['graphql', 'gql'],
|
||||
groovy: ['groovy'],
|
||||
|
@ -457,119 +230,57 @@ export const extensionMap: Record<string, string[]> = {
|
|||
handlebars: ['hbs'],
|
||||
haskell: ['hs'],
|
||||
haxe: ['hx'],
|
||||
hsp: ['hsp'],
|
||||
http: ['http'],
|
||||
hy: ['hy'],
|
||||
inform7: ['ni', 'n'],
|
||||
ini: ['ini'],
|
||||
irpf90: ['f', 'f90'],
|
||||
isbl: ['isbl'],
|
||||
java: ['java'],
|
||||
javascript: ['js'],
|
||||
json: ['json', 'json5'],
|
||||
'julia-repl': [],
|
||||
json: ['json', 'json5', 'jsonc'],
|
||||
julia: ['jl'],
|
||||
kotlin: ['kt', 'kts', 'ktm'],
|
||||
lasso: ['lasso', 'lassoapp'],
|
||||
latex: ['tex'],
|
||||
ldif: ['ldif'],
|
||||
leaf: ['leaf'],
|
||||
less: ['less'],
|
||||
lisp: ['lisp'],
|
||||
livecodeserver: ['lc', 'irev'],
|
||||
livescript: ['ls'],
|
||||
llvm: ['ll'],
|
||||
lsl: ['lsl'],
|
||||
lua: ['lua'],
|
||||
makefile: ['Makefile'],
|
||||
markdown: ['md', 'markdown'],
|
||||
mathematica: ['nb'],
|
||||
markdown: ['md', 'markdown', 'mkd'],
|
||||
matlab: ['m'],
|
||||
maxima: ['mac', 'mc'],
|
||||
mel: ['mel'],
|
||||
mercury: ['m', 'mh', 'pro'],
|
||||
mipsasm: ['s'],
|
||||
mizar: ['miz'],
|
||||
mojolicious: ['ep'],
|
||||
monkey: ['monkey'],
|
||||
moonscript: ['moon'],
|
||||
n1ql: ['n1ql'],
|
||||
nestedtext: ['nt'],
|
||||
nginx: ['nginx.conf'],
|
||||
nim: ['nim'],
|
||||
nix: ['nix'],
|
||||
'node-repl': [],
|
||||
nsis: ['nsi', 'nsh'],
|
||||
objectivec: ['m', 'mm'],
|
||||
ocaml: ['ml', 'mli'],
|
||||
openscad: ['scad'],
|
||||
oxygene: ['oxygene'],
|
||||
parser3: ['parser3'],
|
||||
perl: ['pl', 'pm'],
|
||||
pf: ['pf'],
|
||||
pgsql: ['pgsql'],
|
||||
php: ['php', 'php5', 'php7', 'php8'],
|
||||
plaintext: ['txt'],
|
||||
plaintext: ['txt', 'text', 'conf', 'def', 'list', 'log', 'in'],
|
||||
pony: ['pony'],
|
||||
powershell: ['ps1', 'psm1'],
|
||||
processing: ['pde'],
|
||||
profile: [],
|
||||
prolog: ['pl', 'pro', 'P'],
|
||||
properties: ['properties'],
|
||||
protobuf: ['proto'],
|
||||
puppet: ['pp'],
|
||||
purebasic: ['pb', 'pbi'],
|
||||
'python-repl': [],
|
||||
python: ['py'],
|
||||
q: ['q'],
|
||||
qml: ['qml'],
|
||||
r: ['R'],
|
||||
reasonml: ['re', 'rei'],
|
||||
rib: ['rib'],
|
||||
roboconf: ['rbcf'],
|
||||
routeros: ['rsc'],
|
||||
rsl: ['rsl'],
|
||||
ruby: ['rb'],
|
||||
ruleslanguage: ['ruleslanguage'],
|
||||
rust: ['rs'],
|
||||
sas: ['sas'],
|
||||
scala: ['scala'],
|
||||
scheme: ['scm'],
|
||||
scilab: ['sci'],
|
||||
scss: ['scss'],
|
||||
shell: ['sh', 'bash', 'dash', 'ksh', 'csh', 'tcsh', 'zsh', 'fish'],
|
||||
smali: ['smali'],
|
||||
smalltalk: ['st'],
|
||||
sml: ['sml', 'sig', 'fun'],
|
||||
sqf: ['sqf'],
|
||||
sql: ['sql'],
|
||||
stan: ['stan'],
|
||||
stata: ['do', 'ado'],
|
||||
step21: ['stp'],
|
||||
stylus: ['styl'],
|
||||
subunit: ['subunit'],
|
||||
swift: ['swift'],
|
||||
taggerscript: ['taggerscript'],
|
||||
tap: ['tap'],
|
||||
tcl: ['tcl'],
|
||||
thrift: ['thrift'],
|
||||
tp: ['tp'],
|
||||
twig: ['twig'],
|
||||
typescript: ['ts'],
|
||||
vala: ['vala'],
|
||||
vbnet: ['vb'],
|
||||
vbscript: ['vbs'],
|
||||
verilog: ['v'],
|
||||
vhdl: ['vhdl'],
|
||||
vim: ['vim'],
|
||||
wasm: [],
|
||||
wren: ['wren'],
|
||||
x86asm: ['s'],
|
||||
xl: ['xl', 'ilst'],
|
||||
xml: ['xml', 'svg', 'dtd'],
|
||||
xquery: ['xy', 'xquery'],
|
||||
yaml: ['yaml', 'yml'],
|
||||
zephir: ['zep']
|
||||
// zig: ['zig'],
|
||||
};
|
||||
|
||||
// Take a language (full name or extension) as input, and
|
||||
|
|
|
@ -0,0 +1,181 @@
|
|||
#!/bin/bash
|
||||
# Paste69 CLI script
|
||||
|
||||
PASTE69_URL=${PASTE69_URL:-"https://0x45.st"}
|
||||
|
||||
# Check if `curl` is installed
|
||||
if ! command -v curl &> /dev/null; then
|
||||
echo "Error: curl is not installed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if `jq` is installed
|
||||
if ! command -v jq &> /dev/null; then
|
||||
echo "Error: jq is not installed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for the presence of a clipboard program
|
||||
cliptools=("xclip" "xsel" "pbcopy")
|
||||
for tool in "${cliptools[@]}"; do
|
||||
if command -v $tool &> /dev/null; then
|
||||
case $tool in
|
||||
xclip)
|
||||
clipboard="xclip -selection clipboard"
|
||||
;;
|
||||
xsel)
|
||||
clipboard="xsel --clipboard"
|
||||
;;
|
||||
pbcopy)
|
||||
clipboard="pbcopy"
|
||||
;;
|
||||
esac
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Show help text
|
||||
function show_help {
|
||||
echo "Paste69 CLI script"
|
||||
echo ""
|
||||
echo "Usage:"
|
||||
echo " paste69 <file> [options]"
|
||||
echo " cat <file> | paste69 [options]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -h, --help Show this help text."
|
||||
echo " -l, --language <language> Set the language of the paste."
|
||||
echo " -p, --password <password> Set a password for the paste. This enables encryption."
|
||||
echo " -x, --burn Burn the paste after it is viewed once."
|
||||
echo " -r, --raw Return the raw JSON response."
|
||||
echo " -c, --copy Copy the paste URL to the clipboard."
|
||||
}
|
||||
|
||||
burn=false
|
||||
encrypt=false
|
||||
|
||||
# Parse arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
key="$1"
|
||||
case $key in
|
||||
-h|--help)
|
||||
show_help
|
||||
exit 0
|
||||
;;
|
||||
-l|--language)
|
||||
language="$2"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
-p|--password)
|
||||
password="$2"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
-x|--burn)
|
||||
burn=true
|
||||
shift
|
||||
;;
|
||||
-r|--raw)
|
||||
raw=true
|
||||
shift
|
||||
;;
|
||||
-c|--copy)
|
||||
copy=true
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
if [ -z "$file" ]; then
|
||||
file=$1
|
||||
extension="${file##*.}"
|
||||
else
|
||||
echo "Error: too many arguments"
|
||||
show_help
|
||||
exit 1
|
||||
fi
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check if data or a file was provided, otherwise error out
|
||||
if [ -z "$file" ] && ! [ -p /dev/stdin ]; then
|
||||
echo "Error: no data or file provided"
|
||||
show_help
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Build the URL
|
||||
url="$PASTE69_URL/api/pastes"
|
||||
|
||||
# Make the request
|
||||
if [ ! -z "$file" ]; then
|
||||
contents=$(/usr/bin/cat $file)
|
||||
else
|
||||
data=$(/usr/bin/cat)
|
||||
# Check if the data is too large
|
||||
if [ ${#data} -gt 10000 ]; then
|
||||
echo "Error: stdin input too large. Use a file instead."
|
||||
exit 1
|
||||
fi
|
||||
contents=$data
|
||||
fi
|
||||
|
||||
# If password is set, we need to set the `encrypt` flag
|
||||
if [ ! -z "$password" ]; then
|
||||
encrypt=true
|
||||
fi
|
||||
|
||||
# Create the JSON payload, and then clean it up
|
||||
json=$(jq -n \
|
||||
--arg contents "$contents" \
|
||||
--arg extension "$extension" \
|
||||
--arg language "$language" \
|
||||
--arg password "$password" \
|
||||
--argjson encrypt $encrypt \
|
||||
--argjson burn $burn \
|
||||
'{"contents": $contents, "extension": $extension, "language": $language, "password": $password, "encrypt": $encrypt, "burnAfterReading": $burn}')
|
||||
|
||||
response=$(
|
||||
curl -s -X POST $url \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$json"
|
||||
)
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "An error occurred while making the request"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if there is an error
|
||||
error=$(echo $response | jq -r '.error')
|
||||
if [ "$error" != "null" ]; then
|
||||
echo "Error: $error"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# If raw is set, return the raw JSON response
|
||||
if [ ! -z "$raw" ]; then
|
||||
echo $response
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Get the paste URL from the response
|
||||
paste_url=$(echo $response | jq -r '.url')
|
||||
|
||||
# Print the paste URL
|
||||
echo $paste_url
|
||||
|
||||
# If copy is set, copy the paste URL to the clipboard
|
||||
if [ ! -z "$copy" ]; then
|
||||
if [ ! -z "$clipboard" ]; then
|
||||
echo $paste_url | $clipboard
|
||||
else
|
||||
echo "Error: the --copy flag requires a clipboard program to be installed"
|
||||
echo "Install one of the following:"
|
||||
for tool in "${cliptools[@]}"; do
|
||||
echo " $tool"
|
||||
done
|
||||
exit 1
|
||||
fi
|
||||
fi
|
Loading…
Reference in New Issue