From c84f1d95e282a96c44527b29b1b2627850ee18f8 Mon Sep 17 00:00:00 2001 From: Soham Sen Date: Thu, 8 Jun 2023 05:02:35 +0530 Subject: [PATCH] Added dockerfile --- .dockerignore | 17 + .env.example | 3 +- Dockerfile | 31 ++ package.json | 6 +- process.yml | 6 + scripts/run.sh | 3 + src/app.css | 6 + src/lib/data.ts | 333 ++++++++++++++++++ .../20230607163329_init/migration.sql | 0 .../20230607202718_update_paste/migration.sql | 18 + .../prisma/migrations/migration_lock.toml | 0 src/lib/{ => server}/prisma/prisma.ts | 0 src/lib/{ => server}/prisma/schema.prisma | 3 +- src/lib/types.ts | 23 ++ src/routes/+layout.svelte | 4 +- src/routes/+page.svelte | 196 +++++++---- src/routes/[key]/+error.svelte | 5 + src/routes/[key]/+layout.svelte | 50 +++ src/routes/[key]/+page.server.ts | 26 ++ src/routes/[key]/+page.svelte | 19 + src/routes/api/create/+server.ts | 42 +++ src/routes/info/+page.svelte | 0 svelte.config.js | 4 +- tailwind.config.js | 6 +- yarn.lock | 165 ++++++++- 25 files changed, 888 insertions(+), 78 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 process.yml create mode 100755 scripts/run.sh create mode 100644 src/lib/data.ts rename src/lib/{ => server}/prisma/migrations/20230607163329_init/migration.sql (100%) create mode 100644 src/lib/server/prisma/migrations/20230607202718_update_paste/migration.sql rename src/lib/{ => server}/prisma/migrations/migration_lock.toml (100%) rename src/lib/{ => server}/prisma/prisma.ts (100%) rename src/lib/{ => server}/prisma/schema.prisma (86%) create mode 100644 src/lib/types.ts create mode 100644 src/routes/[key]/+error.svelte create mode 100644 src/routes/[key]/+layout.svelte create mode 100644 src/routes/[key]/+page.server.ts create mode 100644 src/routes/[key]/+page.svelte create mode 100644 src/routes/api/create/+server.ts create mode 100644 src/routes/info/+page.svelte diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..472cb97 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,17 @@ +Dockerfile +.dockerignore +.git +.gitignore +.gitattributes +README.md +.npmrc +.prettierrc +.eslintrc.cjs +.graphqlrc +.editorconfig +.svelte-kit +.vscode +node_modules +build +package +**/.env diff --git a/.env.example b/.env.example index 2ecfaf3..eb63ce6 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,2 @@ -DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public" \ No newline at end of file +DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public" +SALT="randomsalt" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2707399 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM node:18-alpine AS builder + +WORKDIR /app + +COPY package.json yarn.lock src/lib/server/prisma/schema.prisma ./ + +RUN yarn install --frozen-lockfile + +COPY . . + +RUN npm run build +RUN npm prune --production + +FROM node:18-alpine + +WORKDIR /app + +RUN npm install -g prisma pm2 + +COPY scripts/ scripts/ +COPY package.json yarn.lock process.yml src/lib/server/prisma/schema.prisma ./ + +RUN yarn install --frozen-lockfile --production + +COPY --from=builder /app/build build/ + +EXPOSE 3000 + +ENV NODE_ENV=production + +CMD [ "./scripts/run.sh" ] diff --git a/package.json b/package.json index 8500527..818f5c0 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,9 @@ }, "devDependencies": { "@sveltejs/adapter-auto": "^2.0.0", + "@sveltejs/adapter-node": "^1.2.4", "@sveltejs/kit": "^1.5.0", + "@types/prismjs": "^1.26.0", "@typescript-eslint/eslint-plugin": "^5.45.0", "@typescript-eslint/parser": "^5.45.0", "autoprefixer": "^10.4.14", @@ -24,8 +26,10 @@ "prettier": "^2.8.0", "prettier-plugin-svelte": "^2.8.1", "prisma": "^4.15.0", + "prismjs": "^1.29.0", "svelte": "^3.54.0", "svelte-check": "^3.0.1", + "svelte-select": "^5.6.1", "tailwindcss": "^3.3.2", "tslib": "^2.4.1", "typescript": "^5.0.0", @@ -33,6 +37,6 @@ }, "type": "module", "dependencies": { - "@prisma/client": "4.15.0" + "@prisma/client": "^4.15.0" } } diff --git a/process.yml b/process.yml new file mode 100644 index 0000000..8566e9c --- /dev/null +++ b/process.yml @@ -0,0 +1,6 @@ +apps: + - name: 'app' + script: './build/index.js' + instances: 'max' + env: + NODE_ENV: 'production' diff --git a/scripts/run.sh b/scripts/run.sh new file mode 100755 index 0000000..e6a2c21 --- /dev/null +++ b/scripts/run.sh @@ -0,0 +1,3 @@ +#!/bin/sh +prisma migrate deploy +pm2-runtime process.yml diff --git a/src/app.css b/src/app.css index caf1f58..850df0d 100644 --- a/src/app.css +++ b/src/app.css @@ -2,6 +2,12 @@ @tailwind components; @tailwind utilities; +:root { + --color-primary: #E5E1D1; + --color-background: #101419; + --color-dark: rgba(0, 0, 0, 0.4); +} + body { @apply bg-background; @apply text-primary; diff --git a/src/lib/data.ts b/src/lib/data.ts new file mode 100644 index 0000000..934f43b --- /dev/null +++ b/src/lib/data.ts @@ -0,0 +1,333 @@ +export const languageKeysByName = new Map([ + ['Plain text', 'plaintext'], + ['Markup', 'markup'], + ['HTML', 'html'], + ['XML', 'xml'], + ['SVG', 'svg'], + ['MathML', 'mathml'], + ['SSML', 'ssml'], + ['Atom', 'atom'], + ['RSS', 'rss'], + ['CSS', 'css'], + ['C-like', 'clike'], + ['JavaScript', 'javascript'], + ['ABAP', 'abap'], + ['ABNF', 'abnf'], + ['ActionScript', 'actionscript'], + ['Ada', 'ada'], + ['Agda', 'agda'], + ['AL', 'al'], + ['ANTLR4', 'antlr4'], + ['Apache Configuration', 'apacheconf'], + ['Apex', 'apex'], + ['APL', 'apl'], + ['AppleScript', 'applescript'], + ['AQL', 'aql'], + ['Arduino', 'arduino'], + ['ARFF', 'arff'], + ['ARM Assembly', 'armasm'], + ['Arturo', 'arturo'], + ['AsciiDoc', 'asciidoc'], + ['ASP.NET (C#)', 'aspnet'], + ['6502 Assembly', 'asm6502'], + ['Atmel AVR Assembly', 'asmatmel'], + ['AutoHotkey', 'autohotkey'], + ['AutoIt', 'autoit'], + ['AviSynth', 'avisynth'], + ['Avro IDL', 'avro-idl'], + ['AWK', 'awk'], + ['GAWK', 'gawk'], + ['Bash', 'bash'], + ['Shell', 'sh'], + ['Shell', 'shell'], + ['BASIC', 'basic'], + ['Batch', 'batch'], + ['BBcode', 'bbcode'], + ['Shortcode', 'shortcode'], + ['BBj', 'bbj'], + ['Bicep', 'bicep'], + ['Birb', 'birb'], + ['Bison', 'bison'], + ['BNF', 'bnf'], + ['RBNF', 'rbnf'], + ['BQN', 'bqn'], + ['Brainfuck', 'brainfuck'], + ['BrightScript', 'brightscript'], + ['Bro', 'bro'], + ['BSL (1C:Enterprise)', 'bsl'], + ['OneScript', 'oscript'], + ['C', 'c'], + ['C#', 'csharp'], + ['C++', 'cpp'], + ['CFScript', 'cfscript'], + ['ChaiScript', 'chaiscript'], + ['CIL', 'cil'], + ['Cilk/C', 'cilkc'], + ['Cilk/C++', 'cilkcpp'], + ['Clojure', 'clojure'], + ['CMake', 'cmake'], + ['COBOL', 'cobol'], + ['CoffeeScript', 'coffeescript'], + ['Concurnas', 'concurnas'], + ['Content-Security-Policy', 'csp'], + ['Cooklang', 'cooklang'], + ['Coq', 'coq'], + ['Crystal', 'crystal'], + ['CSS Extras', 'css-extras'], + ['CSV', 'csv'], + ['CUE', 'cue'], + ['Cypher', 'cypher'], + ['D', 'd'], + ['Dart', 'dart'], + ['DataWeave', 'dataweave'], + ['DAX', 'dax'], + ['Dhall', 'dhall'], + ['Diff', 'diff'], + ['Django/Jinja2', 'django'], + ['DNS zone file', 'dns-zone-file'], + ['Docker', 'docker'], + ['DOT (Graphviz)', 'dot'], + ['EBNF', 'ebnf'], + ['EditorConfig', 'editorconfig'], + ['Eiffel', 'eiffel'], + ['EJS', 'ejs'], + ['Eta', 'eta'], + ['Elixir', 'elixir'], + ['Elm', 'elm'], + ['Embedded Lua templating', 'etlua'], + ['ERB', 'erb'], + ['Erlang', 'erlang'], + ['Excel Formula', 'excel-formula'], + ['F#', 'fsharp'], + ['Factor', 'factor'], + ['False', 'false'], + ['Firestore security rules', 'firestore-security-rules'], + ['Flow', 'flow'], + ['Fortran', 'fortran'], + ['FreeMarker Template Language', 'ftl'], + ['GameMaker Language', 'gml'], + ['GAP (CAS)', 'gap'], + ['G-code', 'gcode'], + ['GDScript', 'gdscript'], + ['GEDCOM', 'gedcom'], + ['gettext', 'gettext'], + ['Gherkin', 'gherkin'], + ['Git', 'git'], + ['GLSL', 'glsl'], + ['GN', 'gn'], + ['GNU Linker Script', 'linker-script'], + ['Go', 'go'], + ['Go module', 'go-module'], + ['Gradle', 'gradle'], + ['GraphQL', 'graphql'], + ['Groovy', 'groovy'], + ['Haml', 'haml'], + ['Handlebars', 'handlebars'], + ['Mustache', 'mustache'], + ['Haskell', 'haskell'], + ['Haxe', 'haxe'], + ['HCL', 'hcl'], + ['HLSL', 'hlsl'], + ['Hoon', 'hoon'], + ['HTTP', 'http'], + ['HTTP Public-Key-Pins', 'hpkp'], + ['HTTP Strict-Transport-Security', 'hsts'], + ['IchigoJam', 'ichigojam'], + ['Icon', 'icon'], + ['ICU Message Format', 'icu-message-format'], + ['Idris', 'idris'], + ['.ignore', 'ignore'], + ['.gitignore', 'gitignore'], + ['.hgignore', 'hgignore'], + ['.npmignore', 'npmignore'], + ['Inform 7', 'inform7'], + ['Ini', 'ini'], + ['Io', 'io'], + ['J', 'j'], + ['Java', 'java'], + ['JavaDoc', 'javadoc'], + ['JavaDoc-like', 'javadoclike'], + ['Java stack trace', 'javastacktrace'], + ['Jexl', 'jexl'], + ['Jolie', 'jolie'], + ['JQ', 'jq'], + ['JSDoc', 'jsdoc'], + ['JS Extras', 'js-extras'], + ['JSON', 'json'], + ['Web App Manifest', 'webmanifest'], + ['JSON5', 'json5'], + ['JSONP', 'jsonp'], + ['JS stack trace', 'jsstacktrace'], + ['JS Templates', 'js-templates'], + ['Julia', 'julia'], + ['Keepalived Configure', 'keepalived'], + ['Keyman', 'keyman'], + ['Kotlin', 'kotlin'], + ['Kotlin Script', 'kts'], + ['KuMir (КуМир)', 'kumir'], + ['Kusto', 'kusto'], + ['LaTeX', 'latex'], + ['TeX', 'tex'], + ['ConTeXt', 'context'], + ['Latte', 'latte'], + ['Less', 'less'], + ['LilyPond', 'lilypond'], + ['Liquid', 'liquid'], + ['Lisp', 'lisp'], + ['LiveScript', 'livescript'], + ['LLVM IR', 'llvm'], + ['Log file', 'log'], + ['LOLCODE', 'lolcode'], + ['Lua', 'lua'], + ['Magma (CAS)', 'magma'], + ['Makefile', 'makefile'], + ['Markdown', 'markdown'], + ['Markup templating', 'markup-templating'], + ['Mata', 'mata'], + ['MATLAB', 'matlab'], + ['MAXScript', 'maxscript'], + ['MEL', 'mel'], + ['Mermaid', 'mermaid'], + ['METAFONT', 'metafont'], + ['Mizar', 'mizar'], + ['MongoDB', 'mongodb'], + ['Monkey', 'monkey'], + ['MoonScript', 'moonscript'], + ['N1QL', 'n1ql'], + ['N4JS', 'n4js'], + ['Nand To Tetris HDL', 'nand2tetris-hdl'], + ['Naninovel Script', 'naniscript'], + ['NASM', 'nasm'], + ['NEON', 'neon'], + ['Nevod', 'nevod'], + ['nginx', 'nginx'], + ['Nim', 'nim'], + ['Nix', 'nix'], + ['NSIS', 'nsis'], + ['Objective-C', 'objectivec'], + ['OCaml', 'ocaml'], + ['Odin', 'odin'], + ['OpenCL', 'opencl'], + ['OpenQasm', 'openqasm'], + ['Oz', 'oz'], + ['PARI/GP', 'parigp'], + ['Parser', 'parser'], + ['Pascal', 'pascal'], + ['Object Pascal', 'objectpascal'], + ['Pascaligo', 'pascaligo'], + ['PATROL Scripting Language', 'psl'], + ['PC-Axis', 'pcaxis'], + ['PeopleCode', 'peoplecode'], + ['Perl', 'perl'], + ['PHP', 'php'], + ['PHPDoc', 'phpdoc'], + ['PHP Extras', 'php-extras'], + ['PlantUML', 'plant-uml'], + ['PL/SQL', 'plsql'], + ['PowerQuery', 'powerquery'], + ['PowerShell', 'powershell'], + ['Processing', 'processing'], + ['Prolog', 'prolog'], + ['PromQL', 'promql'], + ['.properties', 'properties'], + ['Protocol Buffers', 'protobuf'], + ['Pug', 'pug'], + ['Puppet', 'puppet'], + ['Pure', 'pure'], + ['PureBasic', 'purebasic'], + ['PureScript', 'purescript'], + ['Python', 'python'], + ['Q#', 'qsharp'], + ['Q (kdb+ database)', 'q'], + ['QML', 'qml'], + ['Qore', 'qore'], + ['R', 'r'], + ['Racket', 'racket'], + ['Razor C#', 'cshtml'], + ['React JSX', 'jsx'], + ['React TSX', 'tsx'], + ['Reason', 'reason'], + ['Regex', 'regex'], + ['Rego', 'rego'], + ["Ren'py", 'renpy'], + ['ReScript', 'rescript'], + ['reST (reStructuredText)', 'rest'], + ['Rip', 'rip'], + ['Roboconf', 'roboconf'], + ['Robot Framework', 'robotframework'], + ['Ruby', 'ruby'], + ['Rust', 'rust'], + ['SAS', 'sas'], + ['Sass (Sass)', 'sass'], + ['Sass (SCSS)', 'scss'], + ['Scala', 'scala'], + ['Scheme', 'scheme'], + ['Shell session', 'shell-session'], + ['Smali', 'smali'], + ['Smalltalk', 'smalltalk'], + ['Smarty', 'smarty'], + ['SML', 'sml'], + ['SML/NJ', 'smlnj'], + ['Solidity (Ethereum)', 'solidity'], + ['Solution file', 'solution-file'], + ['Soy (Closure Template)', 'soy'], + ['SPARQL', 'sparql'], + ['Splunk SPL', 'splunk-spl'], + ['SQF: Status Quo Function (Arma 3)', 'sqf'], + ['SQL', 'sql'], + ['Squirrel', 'squirrel'], + ['Stan', 'stan'], + ['Stata Ado', 'stata'], + ['Structured Text (IEC 61131-3)', 'iecst'], + ['Stylus', 'stylus'], + ['SuperCollider', 'supercollider'], + ['Swift', 'swift'], + ['Systemd configuration file', 'systemd'], + ['T4 templating', 't4-templating'], + ['T4 Text Templates (C#)', 't4-cs'], + ['T4 Text Templates (VB)', 't4-vb'], + ['TAP', 'tap'], + ['Tcl', 'tcl'], + ['Template Toolkit 2', 'tt2'], + ['Textile', 'textile'], + ['TOML', 'toml'], + ['Tremor', 'tremor'], + ['trickle', 'trickle'], + ['troy', 'troy'], + ['Turtle', 'turtle'], + ['TriG', 'trig'], + ['Twig', 'twig'], + ['TypeScript', 'typescript'], + ['TypoScript', 'typoscript'], + ['TSConfig', 'tsconfig'], + ['UnrealScript', 'unrealscript'], + ['UO Razor Script', 'uorazor'], + ['URI', 'uri'], + ['URL', 'url'], + ['V', 'v'], + ['Vala', 'vala'], + ['VB.Net', 'vbnet'], + ['Velocity', 'velocity'], + ['Verilog', 'verilog'], + ['VHDL', 'vhdl'], + ['vim', 'vim'], + ['Visual Basic', 'visual-basic'], + ['VBA', 'vba'], + ['WarpScript', 'warpscript'], + ['WebAssembly', 'wasm'], + ['Web IDL', 'web-idl'], + ['WGSL', 'wgsl'], + ['Wiki markup', 'wiki'], + ['Wolfram language', 'wolfram'], + ['Mathematica', 'mathematica'], + ['Mathematica Notebook', 'nb'], + ['Wren', 'wren'], + ['Xeora', 'xeora'], + ['XeoraCube', 'xeoracube'], + ['XML doc (.net)', 'xml-doc'], + ['Xojo (REALbasic)', 'xojo'], + ['XQuery', 'xquery'], + ['YAML', 'yaml'], + ['YANG', 'yang'], + ['Zig', 'zig'] +]); diff --git a/src/lib/prisma/migrations/20230607163329_init/migration.sql b/src/lib/server/prisma/migrations/20230607163329_init/migration.sql similarity index 100% rename from src/lib/prisma/migrations/20230607163329_init/migration.sql rename to src/lib/server/prisma/migrations/20230607163329_init/migration.sql diff --git a/src/lib/server/prisma/migrations/20230607202718_update_paste/migration.sql b/src/lib/server/prisma/migrations/20230607202718_update_paste/migration.sql new file mode 100644 index 0000000..1a0cf31 --- /dev/null +++ b/src/lib/server/prisma/migrations/20230607202718_update_paste/migration.sql @@ -0,0 +1,18 @@ +/* + Warnings: + + - You are about to drop the column `uniqueId` on the `Paste` table. All the data in the column will be lost. + - A unique constraint covering the columns `[key]` on the table `Paste` will be added. If there are existing duplicate values, this will fail. + - Added the required column `key` to the `Paste` table without a default value. This is not possible if the table is not empty. + +*/ +-- DropIndex +DROP INDEX "Paste_uniqueId_key"; + +-- AlterTable +ALTER TABLE "Paste" DROP COLUMN "uniqueId", +ADD COLUMN "key" TEXT NOT NULL, +ADD COLUMN "readCount" INTEGER NOT NULL DEFAULT 0; + +-- CreateIndex +CREATE UNIQUE INDEX "Paste_key_key" ON "Paste"("key"); diff --git a/src/lib/prisma/migrations/migration_lock.toml b/src/lib/server/prisma/migrations/migration_lock.toml similarity index 100% rename from src/lib/prisma/migrations/migration_lock.toml rename to src/lib/server/prisma/migrations/migration_lock.toml diff --git a/src/lib/prisma/prisma.ts b/src/lib/server/prisma/prisma.ts similarity index 100% rename from src/lib/prisma/prisma.ts rename to src/lib/server/prisma/prisma.ts diff --git a/src/lib/prisma/schema.prisma b/src/lib/server/prisma/schema.prisma similarity index 86% rename from src/lib/prisma/schema.prisma rename to src/lib/server/prisma/schema.prisma index f2204fa..7aa3cc4 100644 --- a/src/lib/prisma/schema.prisma +++ b/src/lib/server/prisma/schema.prisma @@ -13,9 +13,10 @@ datasource db { model Paste { id BigInt @id @default(autoincrement()) createdAt DateTime @default(now()) - uniqueId String @unique + key String @unique authorIp String content String expiresAt DateTime? expiresCount Int? + readCount Int @default(0) } diff --git a/src/lib/types.ts b/src/lib/types.ts new file mode 100644 index 0000000..57a31f7 --- /dev/null +++ b/src/lib/types.ts @@ -0,0 +1,23 @@ +export interface PasteConfig { + type: string; + encrypted: boolean; + expiresAfter: string; + burn: boolean; + password: string; +} + +export interface Paste { + content: string; + config: PasteConfig; +} + +export interface PasteCreateResponse { + success: boolean; + data?: { + key: string; + }; + error?: { + message: string; + code: number; + }; +} diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 2e511e0..4f47ac8 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -2,4 +2,6 @@ import '../app.css'; - +
+ +
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 0869123..fa855d0 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,10 +1,14 @@ -
-
-
-

YAbin

- -
- - -
+
+
+

YAbin

-
- - -
- - - -
- - -
+
+ + +
- + + + + + + +
- - - + + +
+ +
-
-
-