update and lint
This commit is contained in:
parent
92ce142183
commit
c37c63cfe2
|
@ -4,9 +4,11 @@
|
|||
"es2021": true,
|
||||
"node": true
|
||||
},
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:react/recommended"
|
||||
"plugin:react/recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaFeatures": {
|
||||
|
@ -16,7 +18,8 @@
|
|||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"react"
|
||||
"react",
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"rules": {
|
||||
"semi": [
|
||||
|
|
23
api/index.ts
23
api/index.ts
|
@ -5,7 +5,7 @@ import URLModel from '../lib/schema'
|
|||
|
||||
export default async (request: VercelRequest, response: VercelResponse) => {
|
||||
const { method } = request
|
||||
const db = await dbConnect()
|
||||
await dbConnect()
|
||||
|
||||
switch (method) {
|
||||
case 'POST':
|
||||
|
@ -21,6 +21,7 @@ export default async (request: VercelRequest, response: VercelResponse) => {
|
|||
try {
|
||||
await axios.get(request.body.url)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
return response.status(400).json(
|
||||
{
|
||||
success: false,
|
||||
|
@ -43,7 +44,7 @@ export default async (request: VercelRequest, response: VercelResponse) => {
|
|||
}
|
||||
)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
console.error(err)
|
||||
return response.status(400).json(
|
||||
{
|
||||
success: false,
|
||||
|
@ -51,8 +52,6 @@ export default async (request: VercelRequest, response: VercelResponse) => {
|
|||
}
|
||||
)
|
||||
}
|
||||
|
||||
break
|
||||
case 'DELETE':
|
||||
if (!request.query.url) {
|
||||
return response.status(400).json(
|
||||
|
@ -66,7 +65,7 @@ export default async (request: VercelRequest, response: VercelResponse) => {
|
|||
try {
|
||||
const url = request.query.url
|
||||
|
||||
if (typeof url != "string") {
|
||||
if (typeof url != 'string') {
|
||||
return response.status(400).json(
|
||||
{
|
||||
success: false,
|
||||
|
@ -87,7 +86,7 @@ export default async (request: VercelRequest, response: VercelResponse) => {
|
|||
}
|
||||
)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
console.error(err)
|
||||
return response.status(400).json(
|
||||
{
|
||||
success: false,
|
||||
|
@ -95,16 +94,10 @@ export default async (request: VercelRequest, response: VercelResponse) => {
|
|||
}
|
||||
)
|
||||
}
|
||||
|
||||
break
|
||||
default:
|
||||
const urls = await URLModel.find()
|
||||
|
||||
response.status(200).json(
|
||||
{
|
||||
db: urls
|
||||
}
|
||||
)
|
||||
response.status(200).json({
|
||||
db: await URLModel.find()
|
||||
})
|
||||
|
||||
break
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { connect } from "mongoose"
|
||||
import { connect } from 'mongoose'
|
||||
|
||||
interface CachedMongo {
|
||||
conn: typeof import("mongoose")
|
||||
promise: Promise<typeof import("mongoose")>
|
||||
conn: typeof import('mongoose')
|
||||
promise: Promise<typeof import('mongoose')>
|
||||
}
|
||||
|
||||
const { MONGODB_URI, MONGODB_DB, MONGODB_COLLECTION } = process.env
|
||||
const { MONGODB_URI } = process.env
|
||||
|
||||
let cached: CachedMongo = global.mongo
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import { model, models, Schema } from "mongoose"
|
||||
import { model, models, Schema } from 'mongoose'
|
||||
|
||||
const { MONGODB_COLLECTION } = process.env
|
||||
|
||||
interface URL {
|
||||
url: string
|
||||
|
@ -12,12 +14,12 @@ const schema = new Schema<URL>({
|
|||
}
|
||||
})
|
||||
|
||||
schema.path('url').validate(async function(value) {
|
||||
schema.path(MONGODB_COLLECTION).validate(async function(value) {
|
||||
const count = await models.URL.countDocuments({ url: value })
|
||||
|
||||
return !count
|
||||
}, 'URL already exists')
|
||||
|
||||
const URLModel = model<URL>('url', schema)
|
||||
const URLModel = model<URL>(MONGODB_COLLECTION, schema)
|
||||
|
||||
export = URLModel
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/mongoose": "5.11.97",
|
||||
"@typescript-eslint/eslint-plugin": "^4.31.1",
|
||||
"@typescript-eslint/parser": "^4.31.1",
|
||||
"@vercel/node": "1.12.1",
|
||||
"eslint": "7.32.0",
|
||||
"eslint-plugin-react": "7.25.1"
|
||||
|
|
69
yarn.lock
69
yarn.lock
|
@ -1727,6 +1727,19 @@
|
|||
semver "^7.3.5"
|
||||
tsutils "^3.21.0"
|
||||
|
||||
"@typescript-eslint/eslint-plugin@^4.31.1":
|
||||
version "4.31.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.31.1.tgz#e938603a136f01dcabeece069da5fb2e331d4498"
|
||||
integrity sha512-UDqhWmd5i0TvPLmbK5xY3UZB0zEGseF+DHPghZ37Sb83Qd3p8ujhvAtkU4OF46Ka5Pm5kWvFIx0cCTBFKo0alA==
|
||||
dependencies:
|
||||
"@typescript-eslint/experimental-utils" "4.31.1"
|
||||
"@typescript-eslint/scope-manager" "4.31.1"
|
||||
debug "^4.3.1"
|
||||
functional-red-black-tree "^1.0.1"
|
||||
regexpp "^3.1.0"
|
||||
semver "^7.3.5"
|
||||
tsutils "^3.21.0"
|
||||
|
||||
"@typescript-eslint/experimental-utils@4.30.0":
|
||||
version "4.30.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.30.0.tgz#9e49704fef568432ae16fc0d6685c13d67db0fd5"
|
||||
|
@ -1739,6 +1752,18 @@
|
|||
eslint-scope "^5.1.1"
|
||||
eslint-utils "^3.0.0"
|
||||
|
||||
"@typescript-eslint/experimental-utils@4.31.1":
|
||||
version "4.31.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.31.1.tgz#0c900f832f270b88e13e51753647b02d08371ce5"
|
||||
integrity sha512-NtoPsqmcSsWty0mcL5nTZXMf7Ei0Xr2MT8jWjXMVgRK0/1qeQ2jZzLFUh4QtyJ4+/lPUyMw5cSfeeME+Zrtp9Q==
|
||||
dependencies:
|
||||
"@types/json-schema" "^7.0.7"
|
||||
"@typescript-eslint/scope-manager" "4.31.1"
|
||||
"@typescript-eslint/types" "4.31.1"
|
||||
"@typescript-eslint/typescript-estree" "4.31.1"
|
||||
eslint-scope "^5.1.1"
|
||||
eslint-utils "^3.0.0"
|
||||
|
||||
"@typescript-eslint/parser@^4.29.3":
|
||||
version "4.30.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.30.0.tgz#6abd720f66bd790f3e0e80c3be77180c8fcb192d"
|
||||
|
@ -1749,6 +1774,16 @@
|
|||
"@typescript-eslint/typescript-estree" "4.30.0"
|
||||
debug "^4.3.1"
|
||||
|
||||
"@typescript-eslint/parser@^4.31.1":
|
||||
version "4.31.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.31.1.tgz#8f9a2672033e6f6d33b1c0260eebdc0ddf539064"
|
||||
integrity sha512-dnVZDB6FhpIby6yVbHkwTKkn2ypjVIfAR9nh+kYsA/ZL0JlTsd22BiDjouotisY3Irmd3OW1qlk9EI5R8GrvRQ==
|
||||
dependencies:
|
||||
"@typescript-eslint/scope-manager" "4.31.1"
|
||||
"@typescript-eslint/types" "4.31.1"
|
||||
"@typescript-eslint/typescript-estree" "4.31.1"
|
||||
debug "^4.3.1"
|
||||
|
||||
"@typescript-eslint/scope-manager@4.30.0":
|
||||
version "4.30.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.30.0.tgz#1a3ffbb385b1a06be85cd5165a22324f069a85ee"
|
||||
|
@ -1757,11 +1792,24 @@
|
|||
"@typescript-eslint/types" "4.30.0"
|
||||
"@typescript-eslint/visitor-keys" "4.30.0"
|
||||
|
||||
"@typescript-eslint/scope-manager@4.31.1":
|
||||
version "4.31.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.31.1.tgz#0c21e8501f608d6a25c842fcf59541ef4f1ab561"
|
||||
integrity sha512-N1Uhn6SqNtU2XpFSkD4oA+F0PfKdWHyr4bTX0xTj8NRx1314gBDRL1LUuZd5+L3oP+wo6hCbZpaa1in6SwMcVQ==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "4.31.1"
|
||||
"@typescript-eslint/visitor-keys" "4.31.1"
|
||||
|
||||
"@typescript-eslint/types@4.30.0":
|
||||
version "4.30.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.30.0.tgz#fb9d9b0358426f18687fba82eb0b0f869780204f"
|
||||
integrity sha512-YKldqbNU9K4WpTNwBqtAerQKLLW/X2A/j4yw92e3ZJYLx+BpKLeheyzoPfzIXHfM8BXfoleTdiYwpsvVPvHrDw==
|
||||
|
||||
"@typescript-eslint/types@4.31.1":
|
||||
version "4.31.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.31.1.tgz#5f255b695627a13401d2fdba5f7138bc79450d66"
|
||||
integrity sha512-kixltt51ZJGKENNW88IY5MYqTBA8FR0Md8QdGbJD2pKZ+D5IvxjTYDNtJPDxFBiXmka2aJsITdB1BtO1fsgmsQ==
|
||||
|
||||
"@typescript-eslint/typescript-estree@4.30.0":
|
||||
version "4.30.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.30.0.tgz#ae57833da72a753f4846cd3053758c771670c2ac"
|
||||
|
@ -1775,6 +1823,19 @@
|
|||
semver "^7.3.5"
|
||||
tsutils "^3.21.0"
|
||||
|
||||
"@typescript-eslint/typescript-estree@4.31.1":
|
||||
version "4.31.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.31.1.tgz#4a04d5232cf1031232b7124a9c0310b577a62d17"
|
||||
integrity sha512-EGHkbsUvjFrvRnusk6yFGqrqMBTue5E5ROnS5puj3laGQPasVUgwhrxfcgkdHNFECHAewpvELE1Gjv0XO3mdWg==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "4.31.1"
|
||||
"@typescript-eslint/visitor-keys" "4.31.1"
|
||||
debug "^4.3.1"
|
||||
globby "^11.0.3"
|
||||
is-glob "^4.0.1"
|
||||
semver "^7.3.5"
|
||||
tsutils "^3.21.0"
|
||||
|
||||
"@typescript-eslint/visitor-keys@4.30.0":
|
||||
version "4.30.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.30.0.tgz#a47c6272fc71b0c627d1691f68eaecf4ad71445e"
|
||||
|
@ -1783,6 +1844,14 @@
|
|||
"@typescript-eslint/types" "4.30.0"
|
||||
eslint-visitor-keys "^2.0.0"
|
||||
|
||||
"@typescript-eslint/visitor-keys@4.31.1":
|
||||
version "4.31.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.31.1.tgz#f2e7a14c7f20c4ae07d7fc3c5878c4441a1da9cc"
|
||||
integrity sha512-PCncP8hEqKw6SOJY+3St4LVtoZpPPn+Zlpm7KW5xnviMhdqcsBty4Lsg4J/VECpJjw1CkROaZhH4B8M1OfnXTQ==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "4.31.1"
|
||||
eslint-visitor-keys "^2.0.0"
|
||||
|
||||
"@vercel/node@1.12.1":
|
||||
version "1.12.1"
|
||||
resolved "https://registry.yarnpkg.com/@vercel/node/-/node-1.12.1.tgz#15f42f64690f904f8a52a387123ce0958657060f"
|
||||
|
|
Loading…
Reference in New Issue