Merge branch 'main' of https://github.com/BRAVO68WEB/url-minify into bug/model
This commit is contained in:
commit
559a847d33
|
@ -7,6 +7,7 @@ on:
|
||||||
jobs:
|
jobs:
|
||||||
first-job:
|
first-job:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
if: ${{ github.actor != github.repository_owner }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@main
|
uses: actions/checkout@main
|
||||||
|
@ -16,4 +17,4 @@ jobs:
|
||||||
token: '${{ secrets.GITHUB_TOKEN }}'
|
token: '${{ secrets.GITHUB_TOKEN }}'
|
||||||
author: '${{github.actor}}'
|
author: '${{github.actor}}'
|
||||||
repo: BRAVO68WEB/url-minify
|
repo: BRAVO68WEB/url-minify
|
||||||
maxIssue: 2
|
maxIssue: 2
|
||||||
|
|
|
@ -1,13 +1,37 @@
|
||||||
const Minfy = require("../models/minifed_urls")
|
const Minfy = require("../models/minifed_urls")
|
||||||
|
const base_url = 'https://minfy.xyz/'
|
||||||
|
|
||||||
module.exports.getURLData = async (req,res) => {
|
module.exports.getURLData = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const {alias} = req.params;
|
const { alias } = req.params
|
||||||
const data = await Minfy.findOne({minifiedUrl: alias});
|
const data = await Minfy.findOne({ alias: alias })
|
||||||
|
data.minifiedUrl = base_url + data.alias
|
||||||
|
return res.send(data)
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
res.sendStatus(500)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return res.send( data);
|
module.exports.addURL = async (req, res) => {
|
||||||
}catch(err){
|
req.body.minifiedUrl = base_url + req.body.alias
|
||||||
console.error(err)
|
Minfy.create(req.body)
|
||||||
res.sendStatus(500)
|
.then((data)=>{
|
||||||
}
|
res.send(data)
|
||||||
|
})
|
||||||
|
.catch((err)=>{
|
||||||
|
console.error(err)
|
||||||
|
res.sendStaus(500)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.deleteUrlData = async (req,res) =>{
|
||||||
|
Minfy.findByIdAndRemove(req.params.id)
|
||||||
|
.then((data)=>{
|
||||||
|
res.send("Successfully Deleted")
|
||||||
|
})
|
||||||
|
.catch((err)=>{
|
||||||
|
console.error(err)
|
||||||
|
res.sendStaus(500)
|
||||||
|
})
|
||||||
}
|
}
|
|
@ -1,22 +1,26 @@
|
||||||
import mongoose from 'mongoose';
|
const mongoose = require('mongoose')
|
||||||
const { Schema } = mongoose;
|
const { Schema } = mongoose
|
||||||
|
|
||||||
//build a schema
|
//build a schema
|
||||||
const minifiedUrlSchema = new Schema({
|
const minifiedUrlSchema = new Schema(
|
||||||
originalUrl: {
|
{
|
||||||
type: String,
|
originalUrl: {
|
||||||
required: true
|
type: String,
|
||||||
},
|
required: true,
|
||||||
minifiedUrl: {
|
},
|
||||||
type: String,
|
alias: {
|
||||||
required: true
|
type: String,
|
||||||
},
|
required: true,
|
||||||
views: {
|
},
|
||||||
type: Number
|
minifiedUrl: {
|
||||||
},
|
type: String,
|
||||||
createdAt: Number,
|
required: true,
|
||||||
updatedAt: Number
|
},
|
||||||
|
views: {
|
||||||
});
|
type: Number,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ timestamp: true }
|
||||||
|
)
|
||||||
//make a model using this schema and export it
|
//make a model using this schema and export it
|
||||||
exports.default = mongoose.model('minified_url_model', minifiedUrlSchema);
|
module.exports = mongoose.model('minified_url_model', minifiedUrlSchema)
|
||||||
|
|
|
@ -5,4 +5,8 @@ const router = Router();
|
||||||
|
|
||||||
router.get("/alias/:alias", controller.getURLData)
|
router.get("/alias/:alias", controller.getURLData)
|
||||||
|
|
||||||
|
router.post("/add",controller.addURL)
|
||||||
|
|
||||||
|
router.delete('/delete/:id',controller.deleteUrlData)
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
2295
backend/yarn.lock
2295
backend/yarn.lock
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"lockfileVersion": 1
|
||||||
|
}
|
Loading…
Reference in New Issue