diff --git a/backend/src/app/controllers/txt/getTxtHandler.ts b/backend/src/app/controllers/txt/getTxtHandler.ts index ddf69ab..0610047 100644 --- a/backend/src/app/controllers/txt/getTxtHandler.ts +++ b/backend/src/app/controllers/txt/getTxtHandler.ts @@ -13,11 +13,6 @@ export default async (req: Request, res: Response) => { return res.status(404).send("PASTE_EXPIRED") } - if (req.query && paste.syntax === null) { - paste.syntax = Object.keys(req.query)[0] - await paste.save() - } - return res.json({ paste: paste.paste, syntax: paste.syntax diff --git a/frontend/public/index.html b/frontend/public/index.html index aa069f2..6c8e3f9 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -2,42 +2,19 @@ - + - + - - + - - React App + oitsjustjo.se - Utils for Devs!
- diff --git a/frontend/public/manifest.json b/frontend/public/manifest.json index 080d6c7..5da8f92 100644 --- a/frontend/public/manifest.json +++ b/frontend/public/manifest.json @@ -1,25 +1,8 @@ { - "short_name": "React App", - "name": "Create React App Sample", - "icons": [ - { - "src": "favicon.ico", - "sizes": "64x64 32x32 24x24 16x16", - "type": "image/x-icon" - }, - { - "src": "logo192.png", - "type": "image/png", - "sizes": "192x192" - }, - { - "src": "logo512.png", - "type": "image/png", - "sizes": "512x512" - } - ], + "short_name": "oitsjustjo.se", + "name": "Utils for Devs!", "start_url": ".", "display": "standalone", - "theme_color": "#000000", - "background_color": "#ffffff" + "theme_color": "#17a2b8", + "background_color": "#252525" } diff --git a/frontend/src/components/TextRender.jsx b/frontend/src/components/TextRender.jsx index 8268c2f..cb36336 100644 --- a/frontend/src/components/TextRender.jsx +++ b/frontend/src/components/TextRender.jsx @@ -2,27 +2,32 @@ import 'ace-builds'; import 'ace-builds/src-noconflict/theme-github'; import React from 'react'; import AceEditor from 'react-ace'; +import { Container } from 'react-bootstrap'; +import Syntax from './paste/Syntax.json'; + +const reverseSearch = (syntax) => Object.keys(Syntax).filter((x) => Syntax[x] === syntax); export default ({ paste, syntax }) => ( -
- +
+

{`Viewing ${reverseSearch(syntax)} File`}

+ + +
); diff --git a/frontend/src/components/TextUpload.jsx b/frontend/src/components/TextUpload.jsx index 5edda45..95a44fa 100644 --- a/frontend/src/components/TextUpload.jsx +++ b/frontend/src/components/TextUpload.jsx @@ -31,17 +31,39 @@ export default () => { loading: false, result: null, }); + const [renderState, setRenderState] = useState({ + paste: null, + notFound: false, + }); + const query = new URLSearchParams(window.location.search); const isValid = state.paste && state.syntax && state.expiresAt; - const [render, setRender] = useState(null); + // Check if the user is _viewing_ a paste if (query.has('id')) { - if (!render) { + // If the paste isn't loaded: + if (!renderState.paste) { + // If the paste attempted to load but wasn't found + if (renderState.notFound) { + return

Paste Not Found

; + } + + // Grab the paste, and set it getTxtHandler(query.get('id')) - .then((d) => setRender(d)); - return (

Loading...

); + .then((paste) => setRenderState({ ...renderState, paste })) + .catch(() => setRenderState({ ...renderState, notFound: true })); + + // Render nice loading text :) + return

Loading...

; } - return (); + + // Return the actual paste with the data! + return ( + + ); } const submit = (evt) => { @@ -75,7 +97,9 @@ export default () => { onChange={(evt) => setState({ ...state, syntax: evt.target.value })} > {Object.keys(Syntax).map((name, idx) => ( - + ))} @@ -120,24 +144,27 @@ export default () => { onChange={(evt) => setState({ ...state, expiresAt: evt.target.value })} > {Object.keys(expirationOptions).map((name, idx) => ( - + ))} - + - {state.result && ( -
- - {state.result} - -
+
+ + {state.result} + +
)} diff --git a/frontend/src/components/paste/Syntax.json b/frontend/src/components/paste/Syntax.json index 8df95cc..532e6b5 100644 --- a/frontend/src/components/paste/Syntax.json +++ b/frontend/src/components/paste/Syntax.json @@ -1,174 +1,174 @@ - { - "PlainText": "plain_text", - "ABAP": "abap", - "ABC": "abc", - "ActionScript": "actionscript", - "ADA": "ada", - "ALDA": "alda", - "Apache Config": "apache_conf", - "Apex": "apex", - "AppleScript": "applescript", - "AQL": "aql", - "ASCII-Doc": "asciidoc", - "ASL": "asl", - "Assembly (x86)": "assembly_x86", - "AutoHotKey": "autohotkey", - "BatchFile": "batchfile", - "C9-Search": "c9search", - "C": "c_cpp", - "C++": "c_cpp", - "Cirru": "cirru", - "Clojure": "clojure", - "COBOL": "cobol", - "CoffeeScript": "coffee", - "Cold Fusion": "coldfusion", - "Crystal": "crystal", - "C#": "csharp", - "Csound (document)": "csound_document", - "Csound (Orchestra)": "csound_orchestra", - "Csound (Score)": "csound_score", - "CSP": "csp", - "CSS": "css", - "Curly": "curly", - "D": "d", - "Dart": "dart", - "Diff": "diff", - "Django": "django", - "DockerFile": "dockerfile", - "Dot": "dot", - "Drools": "drools", - "Edifact": "edifact", - "Eiffel": "eiffel", - "EJS": "ejs", - "Elixir": "elixir", - "Elm": "elm", - "Erlang": "erlang", - "Forth": "forth", - "Fortran": "fortran", - "F#": "fsharp", - "FSL": "fsl", - "FTL": "ftl", - "G-Code": "gcode", - "Gherkin": "gherkin", - ".gitignore": "gitignore", - "GLSL": "glsl", - "Gobstones": "gobstones", - "GoLang": "golang", - "GraphQL Schema": "graphqlschema", - "Groovy": "groovy", - "HAML": "haml", - "{{HandleBars}}": "handlebars", - "Haskell": "haskell", - "Haxe": "haxe", - "Human JSON": "hjson", - "HTML": "html", - "HTML (Elixir)": "html_elixir", - "HTML (Rails)": "rhtml", - "HTML (Ruby)": "html_ruby", - ".ini": "ini", - "IO": "io", - "Jack": "jack", - "Jade": "jade", - "Java": "java", - "JavaScript": "javascript", - "JSON": "json", - "JSON5": "json5", - "JSONiq": "jsoniq", - "JSP": "jsp", - "JSSM": "jssm", - "JSX": "jsx", - "Julia": "julia", - "Kotlin": "kotlin", - "LaTeX": "latex", - ".less": "less", - "Liquid": "liquid", - "LISP": "lisp", - "LiveScript": "livescript", - "LogIQL": "logiql", - "LogTalk": "logtalk", - "LSL": "lsl", - "LUA": "lua", - "LUApage": "luapage", - "Lucene": "lucene", - "MakeFile": "makefile", - "MarkDown": "markdown", - "Mask": "mask", - "MatLab": "matlab", - "Maze": "maze", - "MediaWiki": "mediawiki", - "Mel": "mel", - "Mixal": "mixal", - "Mushcode": "mushcode", - "MySQL": "mysql", - "NGINX": "nginx", - "Nim": "nim", - "Nix": "nix", - "NIS": "nsis", - "Nunjucks": "nunjucks", - "Objective-C": "objectivec", - "OCaml": "ocaml", - "Pascal": "pascal", - "Perl": "perl", - "Perl6": "perl6", - "PGSQL": "pgsql", - "PHP": "php", - "PHP (Laravel Blade)": "php_laravel_blade", - "Pig": "pig", - "PowerShell": "powershell", - "Praat": "praat", - "Prisma": "prisma", - "Prolog": "prolog", - ".properties": "properties", - "ProtoBuf": "protobuf", - "Puppet": "puppet", - "Python": "python", - "QML": "qml", - "R": "r", - "Razor": "razor", - "RDoc": "rdoc", - "Red": "red", - "Redshift": "redshift", - "RST": "rst", - "Ruby": "ruby", - "Rust": "rust", - "SASS": "sass", - "Scad": "scad", - "Scala": "scala", - "Scheme": "scheme", - "SCSS": "scss", - "sh": "sh", - "Shell Script": "sh", - "SJS": "sjs", - "Slim": "slim", - "Smarty": "smarty", - "Snippets": "snippets", - "Soy Template": "soy_template", - "Space": "space", - "SparQL": "sparql", - "SQL": "sql", - "SQL Server": "sqlserver", - "Stylus": "stylus", - "SVG": "svg", - "Swift": "swift", - "TCL": "tcl", - "Terraform": "terraform", - "TeX": "tex", - "Text": "text", - "Textile": "textile", - "TOML": "toml", - "TSX": "tsx", - "Turtle": "turtle", - "Twig": "twig", - "TypeScript": "typescript", - "Vala": "vala", - "VSCcript": "vbscript", - "Velocity": "velocity", - "Verilog": "verilog", - "VHDL": "vhdl", - "VisualForce": "visualforce", - "Wollok": "wollok", - "XML": "xml", - "XQuery": "xquery", - "YAML": "yaml", - "Zeek": "zeek" - } \ No newline at end of file +{ + "PlainText": "plain_text", + "ABAP": "abap", + "ABC": "abc", + "ActionScript": "actionscript", + "ADA": "ada", + "ALDA": "alda", + "Apache Config": "apache_conf", + "Apex": "apex", + "AppleScript": "applescript", + "AQL": "aql", + "ASCII-Doc": "asciidoc", + "ASL": "asl", + "Assembly (x86)": "assembly_x86", + "AutoHotKey": "autohotkey", + "BatchFile": "batchfile", + "C9-Search": "c9search", + "C": "c_cpp", + "C++": "c_cpp", + "Cirru": "cirru", + "Clojure": "clojure", + "COBOL": "cobol", + "CoffeeScript": "coffee", + "Cold Fusion": "coldfusion", + "Crystal": "crystal", + "C#": "csharp", + "Csound (document)": "csound_document", + "Csound (Orchestra)": "csound_orchestra", + "Csound (Score)": "csound_score", + "CSP": "csp", + "CSS": "css", + "Curly": "curly", + "D": "d", + "Dart": "dart", + "Diff": "diff", + "Django": "django", + "DockerFile": "dockerfile", + "Dot": "dot", + "Drools": "drools", + "Edifact": "edifact", + "Eiffel": "eiffel", + "EJS": "ejs", + "Elixir": "elixir", + "Elm": "elm", + "Erlang": "erlang", + "Forth": "forth", + "Fortran": "fortran", + "F#": "fsharp", + "FSL": "fsl", + "FTL": "ftl", + "G-Code": "gcode", + "Gherkin": "gherkin", + ".gitignore": "gitignore", + "GLSL": "glsl", + "Gobstones": "gobstones", + "GoLang": "golang", + "GraphQL Schema": "graphqlschema", + "Groovy": "groovy", + "HAML": "haml", + "{{HandleBars}}": "handlebars", + "Haskell": "haskell", + "Haxe": "haxe", + "Human JSON": "hjson", + "HTML": "html", + "HTML (Elixir)": "html_elixir", + "HTML (Rails)": "rhtml", + "HTML (Ruby)": "html_ruby", + ".ini": "ini", + "IO": "io", + "Jack": "jack", + "Jade": "jade", + "Java": "java", + "JavaScript": "javascript", + "JSON": "json", + "JSON5": "json5", + "JSONiq": "jsoniq", + "JSP": "jsp", + "JSSM": "jssm", + "JSX": "jsx", + "Julia": "julia", + "Kotlin": "kotlin", + "LaTeX": "latex", + ".less": "less", + "Liquid": "liquid", + "LISP": "lisp", + "LiveScript": "livescript", + "LogIQL": "logiql", + "LogTalk": "logtalk", + "LSL": "lsl", + "LUA": "lua", + "LUApage": "luapage", + "Lucene": "lucene", + "MakeFile": "makefile", + "MarkDown": "markdown", + "Mask": "mask", + "MatLab": "matlab", + "Maze": "maze", + "MediaWiki": "mediawiki", + "Mel": "mel", + "Mixal": "mixal", + "Mushcode": "mushcode", + "MySQL": "mysql", + "NGINX": "nginx", + "Nim": "nim", + "Nix": "nix", + "NIS": "nsis", + "Nunjucks": "nunjucks", + "Objective-C": "objectivec", + "OCaml": "ocaml", + "Pascal": "pascal", + "Perl": "perl", + "Perl6": "perl6", + "PGSQL": "pgsql", + "PHP": "php", + "PHP (Laravel Blade)": "php_laravel_blade", + "Pig": "pig", + "PowerShell": "powershell", + "Praat": "praat", + "Prisma": "prisma", + "Prolog": "prolog", + ".properties": "properties", + "ProtoBuf": "protobuf", + "Puppet": "puppet", + "Python": "python", + "QML": "qml", + "R": "r", + "Razor": "razor", + "RDoc": "rdoc", + "Red": "red", + "Redshift": "redshift", + "RST": "rst", + "Ruby": "ruby", + "Rust": "rust", + "SASS": "sass", + "Scad": "scad", + "Scala": "scala", + "Scheme": "scheme", + "SCSS": "scss", + "sh": "sh", + "Shell Script": "sh", + "SJS": "sjs", + "Slim": "slim", + "Smarty": "smarty", + "Snippets": "snippets", + "Soy Template": "soy_template", + "Space": "space", + "SparQL": "sparql", + "SQL": "sql", + "SQL Server": "sqlserver", + "Stylus": "stylus", + "SVG": "svg", + "Swift": "swift", + "TCL": "tcl", + "Terraform": "terraform", + "TeX": "tex", + "Text": "text", + "Textile": "textile", + "TOML": "toml", + "TSX": "tsx", + "Turtle": "turtle", + "Twig": "twig", + "TypeScript": "typescript", + "Vala": "vala", + "VSCcript": "vbscript", + "Velocity": "velocity", + "Verilog": "verilog", + "VHDL": "vhdl", + "VisualForce": "visualforce", + "Wollok": "wollok", + "XML": "xml", + "XQuery": "xquery", + "YAML": "yaml", + "Zeek": "zeek" +} \ No newline at end of file diff --git a/frontend/src/css/App.css b/frontend/src/css/App.css index 4f95c98..cd01099 100644 --- a/frontend/src/css/App.css +++ b/frontend/src/css/App.css @@ -45,3 +45,9 @@ .custom.custom-file *, input.custom-file-input { cursor: pointer; } + +.paste-view { + height: 75vh !important; + width: 100%; + max-width: 1024px; +}