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