mirror of
https://github.com/FranP-code/shortly.git
synced 2025-10-13 00:43:28 +00:00
added metadata on url model
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
/* eslint-disable quotes */
|
||||
import getMetaData from 'metadata-scraper'
|
||||
import { decrypt } from '../../scripts/crypto'
|
||||
import generateId from '../../scripts/generateId'
|
||||
import isUrl from '../../scripts/isUrl'
|
||||
@@ -35,11 +36,13 @@ export async function createUrl(
|
||||
if (
|
||||
decrypt({ content: user.password, iv: user.crypto.iv }) === password
|
||||
) {
|
||||
const metaData = await getMetaData(url)
|
||||
const newUrl: IUrl = {
|
||||
id: generateId(5),
|
||||
url,
|
||||
dateCreated: new Date(),
|
||||
uploadedByUser: user.id,
|
||||
metaData,
|
||||
}
|
||||
return UrlModel.create(newUrl)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ export interface IUrl {
|
||||
url: string
|
||||
dateCreated: Date
|
||||
uploadedByUser: string
|
||||
metaData: Object
|
||||
}
|
||||
|
||||
export const urlSchema = new Schema<IUrl>(
|
||||
@@ -27,6 +28,10 @@ export const urlSchema = new Schema<IUrl>(
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
metaData: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
{ collection: 'url', timestamps: true }
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export default function (metaData: any) {
|
||||
export default function (metaData: any, url: string) {
|
||||
return `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
@@ -10,7 +10,7 @@ export default function (metaData: any) {
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
window.location.href = "${metaData.url}";
|
||||
window.location.href = "${url}";
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Router, Request, Response } from 'express'
|
||||
import getMetaData from 'metadata-scraper'
|
||||
import { getUrlById } from '../../models/queries/Url.queries'
|
||||
import generateGetUrlPage from '../../pages/getUrl/generateGetUrlPage'
|
||||
import mongoErrorService from '../../services/mongoErrorService'
|
||||
@@ -14,11 +13,10 @@ router.get('/:urlId', async (req: Request, res: Response) => {
|
||||
})
|
||||
}
|
||||
try {
|
||||
const { url } = await getUrlById({
|
||||
const { metaData, url } = await getUrlById({
|
||||
id: urlId,
|
||||
})
|
||||
const metaData = await getMetaData(url)
|
||||
res.send(generateGetUrlPage(metaData))
|
||||
res.send(generateGetUrlPage(metaData, url))
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
res.status(400).json({
|
||||
|
||||
Reference in New Issue
Block a user