Skip to content

Commit

Permalink
Merge pull request #16 from JSPaste/dev
Browse files Browse the repository at this point in the history
Merge dev into stable
  • Loading branch information
tnfAngel committed Jan 11, 2024
2 parents 770f41b + d1f56a4 commit 6f0915a
Show file tree
Hide file tree
Showing 20 changed files with 510 additions and 181 deletions.
63 changes: 13 additions & 50 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,175 +1,138 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
# JSP specific
documents/

# Logs

logs
_.log
npm-debug.log_
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Caches
# IntelliJ based IDEs
.idea/

.cache
# Finder (MacOS) folder config
.DS_Store/

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data

pids
_.pid
_.seed
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.cache
.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store
7 changes: 5 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules/
pnpm-lock.yaml
**/documents/
**/node_modules/
.prettierrc.json
LICENSE
tsconfig.json
25 changes: 19 additions & 6 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
{
"tabWidth": 4,
"useTabs": true,
"semi": true,
"singleQuote": true,
"plugins": ["prettier-plugin-packagejson", "prettier-plugin-jsdoc"],

"arrowParens": "always",
"bracketSameLine": false,
"bracketSpacing": true,
"quoteProps": "consistent",
"embeddedLanguageFormatting": "auto",
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"arrowParens": "always"
"jsxSingleQuote": true,
"printWidth": 100,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleAttributePerLine": false,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "none",
"useTabs": true,
"vueIndentScriptAndStyle": false
}
Binary file modified bun.lockb
Binary file not shown.
6 changes: 6 additions & 0 deletions compileStructures.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@echo off

for /R %%i in (src\structures\*.proto) do (
echo Compiling '%%~ni'
npx protoc --proto_path=".\src\structures" --ts_out=".\src\structures" "%%~ni.proto"
)
6 changes: 6 additions & 0 deletions compileStructures.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

for i in $(find src/structures -name '*.proto'); do
echo "Compiling '${i%%.*}'"
npx protoc --proto_path="./src/structures" --ts_out="./src/structures" "${i}"
done
52 changes: 28 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
{
"private": true,
"name": "jspaste-backend",
"license": "EUPL-1.2-or-later",
"module": "src/index.ts",
"type": "module",
"scripts": {
"start": "NODE_ENV=production bun src/index.ts",
"dev": "NODE_ENV=development bun --hot src/index.ts",
"lint": "bun prettier --write ."
},
"devDependencies": {
"@types/bun": "latest",
"prettier": "^3.1.1"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"@elysiajs/cors": "^0.8.0",
"@elysiajs/swagger": "^0.8.3",
"elysia": "^0.8.8"
},
"packageManager": "bun@1.0.21"
}
"$schema": "https://json.schemastore.org/package.json",
"name": "jspaste-backend",
"private": true,
"license": "EUPL-1.2-or-later",
"type": "module",
"module": "src/index.ts",
"scripts": {
"dev": "NODE_ENV=development bun --hot ./src/index.ts",
"fix": "bun run prettier",
"prettier": "bunx prettier . --write",
"start": "NODE_ENV=production bun ./src/index.ts"
},
"dependencies": {
"@elysiajs/cors": "^0.8.0",
"@elysiajs/swagger": "^0.8.3",
"@protobuf-ts/plugin": "^2.9.3",
"@protobuf-ts/protoc": "^2.9.3",
"@protobuf-ts/runtime": "^2.9.3",
"elysia": "^0.8.9"
},
"devDependencies": {
"@types/bun": "latest",
"prettier": "^3.1.1",
"prettier-plugin-packagejson": "^2.4.9",
"prettier-plugin-jsdoc": "^1.3.0",
"typescript": "~5.3.3"
}
}
4 changes: 4 additions & 0 deletions src/classes/DataValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export class DataValidator {
);
}

static isLengthBetweenLimits(value: any, min: number, max: number) {
return value.length >= min && value.length <= max;
}

static isStringArrayLengthBetweenLimits(
min: number,
max: number,
Expand Down
17 changes: 17 additions & 0 deletions src/classes/DocumentManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { BunFile } from 'bun';
import { DocumentDataStruct } from '../structures/documentStruct';

export class DocumentManager {
static async read(file: BunFile): Promise<DocumentDataStruct> {
return DocumentDataStruct.fromBinary(
Bun.inflateSync(Buffer.from(await file.arrayBuffer())),
);
}

static async write(filePath: string, document: DocumentDataStruct) {
await Bun.write(
filePath,
Bun.deflateSync(DocumentDataStruct.toBinary(document)),
);
}
}
8 changes: 4 additions & 4 deletions src/classes/ErrorSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ export class ErrorSender {
this.context = context;
}

sendError(code: number, err: IError) {
return error(code, err);
}

static isError(error?: IError) {
return error?.type === 'error';
}
Expand All @@ -41,4 +37,8 @@ export class ErrorSender {
{ description: 'An object representing an error' },
);
}

sendError(code: number, err: IError) {
return error(code, err);
}
}
11 changes: 6 additions & 5 deletions src/classes/MainServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export class MainServer {

constructor() {
this.app = new Elysia();
this.port = process.env.PORT ?? 4000;
this.port = process.env['PORT'] ?? 4000;
}

async setup() {
this.app.use(cors({methods: ['GET', 'POST', 'DELETE'] })).use(
this.app.use(cors({ methods: ['GET', 'POST', 'DELETE'] })).use(
swagger({
documentation: {
servers: [{ url: 'https://jspaste.eu' }],
Expand Down Expand Up @@ -60,12 +60,13 @@ export class MainServer {
);

if (importedRoute) {
this.app.group(`/api/${apiVersion}/documents`, (groupApp) =>
groupApp.use(importedRoute),
this.app.group(
`/api/${apiVersion}/documents`,
(groupApp: any) => groupApp.use(importedRoute),
);

if (isLatestVersion)
this.app.group('/documents', (groupApp) =>
this.app.group('/documents', (groupApp: any) =>
groupApp.use(importedRoute),
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/constants/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const basePath = process.env['DOCUMENTS_PATH'] ?? 'documents/';
export const maxDocLength = parseInt(process.env['MAX_FILE_LENGTH'] ?? '50000');
Loading

0 comments on commit 6f0915a

Please sign in to comment.