-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from Pritam0077/main
uploaded the files
- Loading branch information
Showing
5 changed files
with
2,000 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Url Shortener</title> | ||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous"> | ||
<link | ||
rel="stylesheet" | ||
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" | ||
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" | ||
crossorigin="anonymous" | ||
/> | ||
<script | ||
src="https://code.jquery.com/jquery-3.2.1.slim.min.js" | ||
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" | ||
crossorigin="anonymous" | ||
></script> | ||
<script | ||
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" | ||
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" | ||
crossorigin="anonymous" | ||
></script> | ||
<script | ||
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" | ||
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" | ||
crossorigin="anonymous" | ||
></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.21.1/axios.min.js"></script> | ||
<script> | ||
function getShort(event){ | ||
event.preventDefault(); | ||
|
||
const email=document.getElementById("email").value; | ||
const password=document.getElementById("password").value; | ||
const short=document.getElementById("short").value; | ||
const Url=document.getElementById("Url").value; | ||
|
||
const data={email,password,short,Url} | ||
|
||
|
||
|
||
axios.post("/admin/urls/", data).then(response=>{ | ||
alert("Generated"); | ||
}).catch(err =>{ | ||
alert("Failed"); | ||
}) | ||
|
||
// console.log(data); | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<form onsubmit="genShort(event)"> | ||
<div class="form-group"> | ||
<label for="email">Email address</label> | ||
<input | ||
type="email" | ||
class="form-control" | ||
id="email" | ||
aria-describedby="emailHelp" | ||
placeholder="Enter email" | ||
/> | ||
<small id="emailHelp" class="form-text text-muted" | ||
>We'll never share your email with anyone else.</small | ||
> | ||
</div> | ||
<div class="form-group"> | ||
<label for="password">Password</label> | ||
<input | ||
type="password" | ||
class="form-control" | ||
id="password" | ||
placeholder="Enter password" | ||
/> | ||
</div> | ||
<div class="form-group"> | ||
<label for="short">Short</label> | ||
<input | ||
type="text" | ||
class="form-control" | ||
id="short" | ||
placeholder="Enter short url" | ||
/> | ||
</div> | ||
<div class="form-group"> | ||
<label for="Url">Complete Url</label> | ||
<input | ||
type="text" | ||
class="form-control" | ||
id="Url" | ||
placeholder="Enter complete url" | ||
/> | ||
</div> | ||
|
||
<button type="button" class="btn btn-warning"><i class="fas fa-heart"></i> Submit</button> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const express = require('express'); | ||
const bodyParser = require("body-parser"); | ||
const app = express(); | ||
const port = 3000; | ||
|
||
var admin = require("firebase-admin"); | ||
|
||
var serviceAccount = require("./urlshorten-690ae-firebase-adminsdk-w0usc-fc391b70eb.json"); | ||
|
||
admin.initializeApp({ | ||
credential: admin.credential.cert(serviceAccount) | ||
}); | ||
|
||
|
||
const static=express.static("public"); | ||
const urldb = admin.firestore().collection("urldb"); | ||
const usersdb = admin.firestore().collection("usersdb"); | ||
|
||
app.use(static); | ||
app.use(bodyParser.json()); | ||
|
||
// app.use((req,res,next)=>{ | ||
// res.send("We intercepted the req") | ||
// }) | ||
|
||
app.get("/:short", (req, res) => { | ||
console.log(req.params); | ||
const short=req.params.short; | ||
|
||
const doc=urldb.doc(short); | ||
|
||
doc.get().then(response => { | ||
const data = response.data(); | ||
// console.log(data); | ||
if(data && data.url){ | ||
res.redirect(301, data.url); | ||
} else { | ||
res.redirect(301, "https://www.codewithharry.com/"); | ||
} | ||
}) | ||
|
||
// res.send("We will redirect you to " + short) | ||
}); | ||
|
||
|
||
app.post("/admin/urls/", (req, res) => { | ||
const {email, password, short, url} = req.body; | ||
|
||
usersdb.doc(email).get().then(response=>{ | ||
const user = response.data(); | ||
// console.log(user); | ||
|
||
if(user && (user.email == email) && (user.password == password)){ | ||
const doc = urlsdb.doc(short); | ||
doc.set({url}); | ||
res.send("Done") | ||
} else { | ||
res.send(403, "Not possible") | ||
} | ||
}) | ||
|
||
// res.send("Hello from another!"); | ||
}); | ||
|
||
app.listen(port, () => { | ||
console.log(`Example app listening at http://localhost:${port}`); | ||
}); |
Oops, something went wrong.