diff --git a/.eslintrc.cjs b/.eslintrc.cjs index ebc1958..4cfb1c1 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -26,5 +26,9 @@ module.exports = { parser: '@typescript-eslint/parser' } } - ] -}; + ], + rules: { + 'ts-expect-error': 'allow-with-description', + 'ts-ignore': 'allow-with-description' + } +}; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 5d1805a..11abf30 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index b35db00..7fa5ba3 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/routes/about/+page.svelte b/src/routes/about/+page.svelte index 981e2f5..bdb3910 100644 --- a/src/routes/about/+page.svelte +++ b/src/routes/about/+page.svelte @@ -1,23 +1,38 @@ Paste69 - About -
- goto('/')} /> +
+
-
+

Paste69

@@ -29,9 +44,36 @@

Code highlighting is handled with the help of highlight.js. - 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: +

+ {#if showLanguages} +
+ {#each languages as column} +
+ {#each column as { language, extensions }} +
+ {language} + ({extensions.join(', ')}) +
+ {/each} +
+ {/each} +
+ {/if} +

Usage

@@ -52,28 +94,31 @@

To make it easier to create pastes, a CLI script is available. The script can be found herehere. To use the script:

- -$ ./paste69.sh --help

+
- -Usage:
-paste69 <file> [options]
-cat <file> | paste69 [options]

- -Options:
--h, --help Show this help text
--r, --raw Return the raw JSON response
--c, --copy Copy the paste URL to the clipboard
`}>
+# Paste69 CLI script +# +# Usage: +# paste69 [options] +# cat | paste69 [options] +# +# Options: +# -h, --help Show this help text. +# -l, --language Set the language of the paste. +# -p, --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.`}>

To create a paste with the script, simply pipe the contents of a file to the script:

- -https://0x45.st/some-random-id.md`}> +

API

@@ -89,14 +134,23 @@ https://0x45.st/some-random-id.md`}> with the following JSON body:

- +

If the paste was successfully created, the API will respond with the following JSON:

@@ -111,8 +165,15 @@ https://0x45.st/some-random-id.md`}> +
+ +
+ goto('/')} />
\ No newline at end of file diff --git a/src/routes/api/pastes/+server.ts b/src/routes/api/pastes/+server.ts index 89e1946..3e4996b 100644 --- a/src/routes/api/pastes/+server.ts +++ b/src/routes/api/pastes/+server.ts @@ -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) { diff --git a/src/utils/hljs.ts b/src/utils/hljs.ts index 56b8626..50c66d4 100644 --- a/src/utils/hljs.ts +++ b/src/utils/hljs.ts @@ -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) { diff --git a/src/utils/languages.ts b/src/utils/languages.ts index 02cf745..9fa6a1d 100644 --- a/src/utils/languages.ts +++ b/src/utils/languages.ts @@ -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 = { - '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 = { 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 = { 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 diff --git a/static/paste69.sh b/static/paste69.sh new file mode 100755 index 0000000..a757ede --- /dev/null +++ b/static/paste69.sh @@ -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 [options]" + echo " cat | paste69 [options]" + echo "" + echo "Options:" + echo " -h, --help Show this help text." + echo " -l, --language Set the language of the paste." + echo " -p, --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 \ No newline at end of file