mirror of
https://github.com/MedzikUser/gatsby-pingbot
synced 2024-08-15 03:20:27 +00:00
update
This commit is contained in:
parent
b5a205cad8
commit
8d0299499b
7 changed files with 545 additions and 1026 deletions
|
@ -1,12 +1,12 @@
|
|||
import { VercelResponse } from '@vercel/node'
|
||||
import axios from 'axios'
|
||||
|
||||
import blacklist from './blacklist.json'
|
||||
import dbConnect from '../dbConnect'
|
||||
import URLModel from '../schema'
|
||||
import blacklist from './blacklist.json'
|
||||
|
||||
export default async function addURL(url: string, response: VercelResponse) {
|
||||
blacklist.forEach(b=> {
|
||||
blacklist.forEach(b => {
|
||||
if (url.includes(b)) {
|
||||
return response.status(400).json({
|
||||
success: false,
|
||||
|
|
|
@ -8,8 +8,10 @@
|
|||
"google.bz",
|
||||
"youtube.com",
|
||||
"youtu.be",
|
||||
"twitch.tv",
|
||||
"twitter.com",
|
||||
"duckduckgo.com",
|
||||
"duck.com",
|
||||
"stackoverflow.com",
|
||||
"github.com",
|
||||
"gitlab.com",
|
||||
|
@ -45,6 +47,5 @@
|
|||
"ytimg.com",
|
||||
"bing.com",
|
||||
"bitly.com",
|
||||
"twitch.tv",
|
||||
"imgur.com"
|
||||
]
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
import { connect } from 'mongoose'
|
||||
|
||||
interface CachedMongo {
|
||||
conn: typeof import('mongoose')
|
||||
promise: Promise<typeof import('mongoose')>
|
||||
}
|
||||
import type { CachedMongo } from '../types/mongo'
|
||||
|
||||
const { MONGODB_URI } = process.env
|
||||
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
import { model, models, Schema } from 'mongoose'
|
||||
|
||||
interface URL {
|
||||
url: string
|
||||
}
|
||||
import type { URLSchema } from '../types/mongo'
|
||||
|
||||
const schema = new Schema<URL>({
|
||||
const schema = new Schema<URLSchema>({
|
||||
url: {
|
||||
type: String,
|
||||
required: true,
|
||||
|
@ -12,7 +10,7 @@ const schema = new Schema<URL>({
|
|||
}
|
||||
})
|
||||
|
||||
schema.path('url').validate(async function(value) {
|
||||
schema.path('url').validate(async function(value: string) {
|
||||
if (models.url) {
|
||||
return true
|
||||
}
|
||||
|
@ -22,6 +20,6 @@ schema.path('url').validate(async function(value) {
|
|||
return !count
|
||||
}, 'URL already exists')
|
||||
|
||||
const URLModel = model<URL>('url', schema)
|
||||
const URLModel = model<URLSchema>('url', schema)
|
||||
|
||||
export = URLModel
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/mongoose": "5.11.97",
|
||||
"@types/react-helmet": "^6.1.3",
|
||||
"@typescript-eslint/eslint-plugin": "4.32.0",
|
||||
"@typescript-eslint/parser": "4.32.0",
|
||||
"@vercel/node": "1.12.1",
|
||||
|
|
8
types/mongo.d.ts
vendored
Normal file
8
types/mongo.d.ts
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
export interface CachedMongo {
|
||||
conn: typeof import('mongoose')
|
||||
promise: Promise<typeof import('mongoose')>
|
||||
}
|
||||
|
||||
export interface URLSchema {
|
||||
url: string
|
||||
}
|
Loading…
Reference in a new issue