Format files

This commit is contained in:
oitsjustjose 2021-06-21 20:31:41 -05:00
commit 175f29eeb7
12 changed files with 1102 additions and 124 deletions

10
backend/.eslintignore Normal file
View file

@ -0,0 +1,10 @@
# /node_modules/* in the project root is ignored by default
# build artefacts
dist/*
coverage/*
# data definition files
**/*.d.ts
# 3rd party libs
/src/public/
# custom definition files
/src/types/

33
backend/.eslintrc Normal file
View file

@ -0,0 +1,33 @@
{
"parser": "@typescript-eslint/parser",
"extends": [
"plugin:@typescript-eslint/recommended"
],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"eol-last": [
"error",
"always"
],
"semi": [
"error",
"always"
],
"quotes": [
"error",
"double"
],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": 1,
"@typescript-eslint/no-inferrable-types": [
"warn",
{
"ignoreParameters": true
}
],
"@typescript-eslint/no-unused-vars": "warn"
}
}

File diff suppressed because it is too large Load diff

View file

@ -25,7 +25,10 @@
"mongoose": "^5.12.14",
"multer": "^1.4.2",
"request-ip": "^2.1.3",
"shortid": "^2.2.15"
"shortid": "^2.2.15",
"@typescript-eslint/eslint-plugin": "^2.3.1",
"@typescript-eslint/parser": "^2.3.1",
"eslint": "^6.4.0"
},
"devDependencies": {
"@types/body-parser": "^1.19.0",
@ -35,7 +38,8 @@
"@types/multer": "^1.4.4",
"@types/request-ip": "0.0.35",
"@types/shortid": "0.0.29",
"typescript": "^3.9.5"
"typescript": "^3.9.5",
"@types/eslint": "^6.1.1"
},
"keywords": [],
"author": "",

View file

@ -1,29 +1,29 @@
import { Request, Response } from 'express'
import Pastes from '../../db/txt.schema'
import moment from 'moment-timezone'
import { Request, Response } from "express";
import Pastes from "../../db/txt.schema";
import moment from "moment-timezone";
export default async (req: Request, res: Response) => {
try {
const paste = await Pastes.findById(req.params.slug)
try {
const paste = await Pastes.findById(req.params.slug);
if (paste) {
// Check for an expired link
if (moment().isAfter(moment(paste.expiresAt))) {
await Pastes.findByIdAndDelete(paste._id)
return res.status(404).send("PASTE EXPIRED")
}
if (paste) {
// Check for an expired link
if (moment().isAfter(moment(paste.expiresAt))) {
await Pastes.findByIdAndDelete(paste._id);
return res.status(404).send("PASTE EXPIRED");
}
return res.json({
paste: paste.paste,
syntax: paste.syntax
})
} else {
return res.status(404).end()
}
} catch (ex) {
console.error(ex)
return res.status(500).send({
error: ex
})
return res.json({
paste: paste.paste,
syntax: paste.syntax,
});
} else {
return res.status(404).end();
}
}
} catch (ex) {
console.error(ex);
return res.status(500).send({
error: ex,
});
}
};

View file

@ -1,20 +1,20 @@
import { Request, Response } from 'express'
import Pastes from '../../db/txt.schema'
import moment from 'moment-timezone'
import { Request, Response } from "express";
import Pastes from "../../db/txt.schema";
import moment from "moment-timezone";
export default async (req: Request, res: Response) => {
try {
const paste = new Pastes()
paste.paste = req.body.paste
paste.syntax = req.body.syntax
paste.expiresAt = moment(req.body.expiresAt).toDate();
await paste.save()
try {
const paste = new Pastes();
paste.paste = req.body.paste;
paste.syntax = req.body.syntax;
paste.expiresAt = moment(req.body.expiresAt).toDate();
await paste.save();
return res.status(200).send(paste._id)
} catch (ex) {
console.error(ex)
return res.status(500).send({
error: ex
})
}
}
return res.status(200).send(paste._id);
} catch (ex) {
console.error(ex);
return res.status(500).send({
error: ex,
});
}
};

View file

@ -1,19 +1,19 @@
import { Request, Response } from 'express'
import URLs from '../../db/url.schema'
import { Request, Response } from "express";
import URLs from "../../db/url.schema";
export default async (req: Request, res: Response) => {
try {
const url = await URLs.findById(req.params.slug)
try {
const url = await URLs.findById(req.params.slug);
if (url) {
res.redirect(url.url);
} else {
res.status(404).send()
}
} catch (ex) {
console.error(ex)
return res.status(500).send({
error: ex
})
if (url) {
res.redirect(url.url);
} else {
res.status(404).send();
}
}
} catch (ex) {
console.error(ex);
return res.status(500).send({
error: ex,
});
}
};

View file

@ -1,25 +1,25 @@
import { Request, Response } from 'express'
import URLs from '../../db/url.schema'
import { Request, Response } from "express";
import URLs from "../../db/url.schema";
const isUrlValid = (url: string) => {
return url.startsWith("http") || url.startsWith("www")
}
return url.startsWith("http") || url.startsWith("www");
};
export default async (req: Request, res: Response) => {
try {
if (!isUrlValid(req.body.url)) {
return res.status(422).send("INVALID URL")
}
const url = new URLs()
url.url = req.body.url
await url.save()
return res.status(200).send(url._id)
} catch (ex) {
console.error(ex)
return res.status(500).send({
error: ex
})
try {
if (!isUrlValid(req.body.url)) {
return res.status(422).send("INVALID URL");
}
}
const url = new URLs();
url.url = req.body.url;
await url.save();
return res.status(200).send(url._id);
} catch (ex) {
console.error(ex);
return res.status(500).send({
error: ex,
});
}
};

View file

@ -1,31 +1,34 @@
import { Schema, model, Document } from 'mongoose'
import shortid from 'shortid'
import { Schema, model, Document } from "mongoose";
import shortid from "shortid";
const PasteSchema = new Schema({
const PasteSchema = new Schema(
{
_id: {
type: String,
default: shortid.generate
type: String,
default: shortid.generate,
},
paste: { type: String },
syntax: {
type: String,
default: null
type: String,
default: null,
},
expiresAt: {
type: Date,
expires: 0,
default: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7)
type: Date,
expires: 0,
default: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
},
}, {
timestamps: true
})
},
{
timestamps: true,
}
);
export type PasteModel = Document & {
_id: string,
paste: string,
syntax: string,
expiresAt: Date,
timestamps: Date
}
_id: string;
paste: string;
syntax: string;
expiresAt: Date;
timestamps: Date;
};
export default model<PasteModel>('Paste', PasteSchema)
export default model<PasteModel>("Paste", PasteSchema);

View file

@ -1,17 +1,17 @@
import mongoose, { Document, Schema, Types } from 'mongoose'
import shortid from 'shortid'
import mongoose, { Document, Schema, Types } from "mongoose";
import shortid from "shortid";
const UrlSchema: Schema = new Schema({
_id: {
type: String,
default: shortid.generate
},
url: String
})
_id: {
type: String,
default: shortid.generate,
},
url: String,
});
export type UrlModel = Document & {
_id: string,
url: string
}
_id: string;
url: string;
};
export default mongoose.model<UrlModel>('urls', UrlSchema, 'urls')
export default mongoose.model<UrlModel>("urls", UrlSchema, "urls");

View file

@ -1,9 +1,9 @@
import mongoose from 'mongoose'
import mongoose from "mongoose";
export default async () => {
await mongoose.connect(`mongodb://${process.env.MONGO_URI}/Utils`, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true
})
}
await mongoose.connect(`mongodb://${process.env.MONGO_URI}/Utils`, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
});
};

View file

@ -1,13 +1,13 @@
import { config as LoadDotenv } from 'dotenv'
import app from './app'
import connectDB from './db'
import { config as LoadDotenv } from "dotenv";
import app from "./app";
import connectDB from "./db";
if(process.env.NODE_ENV !== "production") {
LoadDotenv()
if (process.env.NODE_ENV !== "production") {
LoadDotenv();
}
connectDB()
connectDB();
const port = process.env.PORT || 3000
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Listening at http://127.0.0.1:${port}`))
app.listen(port, () => console.log(`Listening at http://127.0.0.1:${port}`));