Skip to content

Commit

Permalink
query on pages, cleanfb api fix
Browse files Browse the repository at this point in the history
* now its possible to use send the url on /video and /cleanfb (ex: .../video?url=[url]); * fixed cleanfb api route and added /redirect, if used (.../apis/cleanfb/redirect?u=[url]), should follow the extracted link, keep in mind that cannot work as expected sometimes
  • Loading branch information
Matheus Cesar Carneiro committed Jul 19, 2020
1 parent 89dbbcc commit 88e2e19
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 30 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,19 @@ The name came from "Polaris", "Escape-pod" and a a bit of 'south/north pole sign

Extract original url from facebook links before redirect (any click redrects to facebook(dot)com/l.php, this extract)

### Page
```http
https://polarpod.herokuapp.com/cleanfb?url=[URL]
```

### API
```http
https://polarpod.herokuapp.com/apis/cleanfb?u=[URL]
```
OR with redirect after extract original url
```http
https://polarpod.herokuapp.com/apis/cleanfb/redirect?u=[URL]
```

parameters:

Expand All @@ -44,6 +54,13 @@ response:

## Og tag getter

### Page
``` http
https://polarpod.herokuapp.com/ogtags?url=[URL]
```


### API
``` http
https://polarpod.herokuapp.com/apis/ogtags?u=[URL]&enc=[true|false]
```
Expand Down Expand Up @@ -123,6 +140,12 @@ https://polarpod.herokuapp.com/apis/qr/file?u=[URL]&d=[true|false]&w=[width]&c=[

## Video URL parser

### Page
``` http
http://polarpod.herokuapp.com/video/meta?url=[URL]
```

### API
``` http
http://polarpod.herokuapp.com/apis/video/meta?u=[URL]
```
Expand Down
2 changes: 1 addition & 1 deletion public/face-cleaner/cleanfb.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<!-- konnichiwa sekai -->
<body class="dark" link="#03A9F4" vlink="#03A9F4">
<h1>Facebook url 'cleaner'</h1>
<h2>API link: <a href="/apis/cleanfb?u=">https://polarpod.herokuapp.com/apis/cleanfb?u=</a></h2>
<h2>API link: <a href="/apis/cleanfb?u=">https://polarpod.herokuapp.com/apis/cleanfb?u=[url]</a></h2>
<h3>Extract original link from facebook post <br>(facebook redirect any link to 'facebook.com/l.php' before <br> go to final link, this api extract the original <br> link from url and remove 'fb click id' <br> its a way to avoid trackers from clicks)</h3>
<br>
<br>
Expand Down
10 changes: 10 additions & 0 deletions public/face-cleaner/cleanfb.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ let app = new Vue({
timestamp: Date.now(),
}
},
created(){
if(window.location.search){
setTimeout(()=>{
let url = new URL(window.location.href).searchParams.get('url');
this.clearURLLocal(url)
this.dataIn = url
}, 100);

}
},
watch:{
dataIn(val){
if(this.urlPattern.test(val)){
Expand Down
12 changes: 7 additions & 5 deletions public/openGraph/ogs.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@
<!-- konnichiwa sekai -->
<body class="dark" link="#03A9F4" vlink="#03A9F4">
<h1>Open graph</h1>
<h2>API link: <a href="/apis/ogtags?u=">https://polarpod.herokuapp.com/apis/ogtags?u=[url]</a></h2>

<h3>Get Open Graph (og) tags from a website</h3>
<br>
<br>
<div id="polar">
<label for="dataIn" id="dataIn" v-if="dataIn.length > 0">{{dataLabel}}</label>
<input type="text" class="inputs" v-model="dataIn" placeholder="Any URL">

<label for="dataIn" id="dataIn" v-if="dataIn.length > 0 || true">{{dataLabel}}</label>
<input type="text" class="inputs" v-model="dataIn" placeholder="https://example.com">
<br>

<h2><a>Discovered:</a></h2>
<div id="responsed">
<p v-if="dataIn"><b>Your url:</b> <a target="blank" v-bind:href="dataIn">{{dataIn}}</a></p>
Expand All @@ -41,7 +43,7 @@ <h2><a>Discovered:</a></h2>
<p v-if="res.type"><b>Type:</b> {{res.type}}</p>
<!-- <p v-if="!res"><b warn>Nothing founded</b></p> -->

<button v-on:click="showRaw = !showRaw">Show raw response</button> <br>
<button v-on:click="showRaw = !showRaw">Show raw response (JSON)</button> <br>
<p raw v-if="showRaw">{{res}}</p>

<a target="blank" v-bind:href="res.img">
Expand Down
6 changes: 4 additions & 2 deletions public/openGraph/ogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let app = new Vue({
dataIn: '',
dataLabel: 'Any URL',
showRaw: false,
urlPattern: new RegExp('(http||https):\/\/[0-9a-zA-Z]*.'),
urlPattern: new RegExp('(http|https):\/\/[0-9a-zA-Z]*.'),
res:{
name:"",
title:"",
Expand All @@ -20,7 +20,9 @@ let app = new Vue({
created(){
if(window.location.search){
setTimeout(()=>{
this.getOgs(new URL(window.location.href).searchParams.get('url'))
let url = new URL(window.location.href).searchParams.get('url');
this.getOgs(url)
this.dataIn = url
}, 100);

}
Expand Down
2 changes: 2 additions & 0 deletions public/video/video.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<!-- konnichiwa sekai -->
<body class="dark" link="#03A9F4" vlink="#03A9F4">
<h1>Video metadata and url parser</h1>
<h2>API link: <a href="/apis/video/meta?u=">https://polarpod.herokuapp.com/apis/video/meta?u=[url]</a></h2>

<h3>Get metadata and parse URL from some video,<br> generally include id, channel, provider, media type and thumbnail</h3>
<br>
<br>
Expand Down
10 changes: 10 additions & 0 deletions public/video/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ let app = new Vue({
thumb:""
}
},
created(){
if(window.location.search){
setTimeout(()=>{
let url = new URL(window.location.href).searchParams.get('url');
this.getVideoMeta(url)
this.dataIn = url
}, 100);

}
},
watch:{
dataIn(val){
if(this.urlPattern.test(val)){
Expand Down
50 changes: 28 additions & 22 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,40 @@ module.exports = (app, dir) => {
// clean facebook url
app.get('/cleanfb', (req, res) => res.status(200).sendFile(`${dir}/public/face-cleaner/cleanfb.html`))

//* clean facebook url api
app.get('/apis/cleanfb/:redir', (req, res) => {
let url = req.query.u;
if(!url){return res.status(400).send('No params sended')}
// clean facebook url api
app.get('/apis/cleanfb', (req, res) => {
if(!req.query.u) return res.status(400).send("No params sended, please send url: .../cleanfb?u=[url]")
try {
return res.status(200).json({
original: url,
clean: fbCleanLink(url),
original: req.query.u,
clean: fbCleanLink(req.query.u),
timestamp: Date.now(),
success: true
});
if(req.params.redir){
res.redirect(fbCleanLink(url))
}
else{
return res.status(200).json({
original: url,
clean: fbCleanLink(url),
timestamp: Date.now(),
success: true
});
}
} catch (e) {
return res.status(500).send({
original: req.query.u,
clean: 'error',
timestamp: Date.now(),
success: false,
error: e
})
}
})

//* clean facebook url api with redirect
// ! this may not work sometimes
app.get('/apis/cleanfb/redirect', (req, res) => {
if(!req.query.u){return res.status(400).send('No params sended, please send url: .../cleanfb?u=[url]')}
try {
res.redirect(fbCleanLink(req.query.u))
} catch (e) {
return res.status(500).send({
original: url,
clean: '',
clean: fbCleanLink(req.query.u),
timestamp: Date.now(),
success: false
success: false,
error: 'error - cant redirect'
})
}
});
Expand All @@ -72,7 +78,7 @@ module.exports = (app, dir) => {
*/
app.get("/apis/ogtags", async(req, res) => {
let url = req.query.u;
if(!url){ return res.status(400).send('No params sended')}
if(!url){ return res.status(400).send('No params sended, please send url: .../ogtags?u=[url]')}
// if(!validUrl.isUri(url)){ return res.status(406).send('Not a URL')}

//* decode url, recomended but not necessary at most cases
Expand Down Expand Up @@ -119,7 +125,7 @@ module.exports = (app, dir) => {
*/
app.get('/apis/op', (req, res) => {
let url = req.query.u;
if(!url){ return res.status(400).send('No params sended')}
if(!url){ return res.status(400).send('No params sended, please send url: .../op?u=[url]')}
// if(!validUrl.isUri(url)){ return res.status(406).send('Not a URL')}

ops.fetch(url, function(err, meta){
Expand Down Expand Up @@ -192,7 +198,7 @@ module.exports = (app, dir) => {
}

// if(!validUrl.isUri(params.url)){ return res.status(406).send('Not a URL')}
if(params.url == undefined){ return res.status(400).send('no URL informed')}
if(params.url == undefined){ return res.status(400).send('no URL informed, please send url: .../meta?u=[url]')}
else{
vidMeta(params).then(r => {
try {
Expand Down

0 comments on commit 88e2e19

Please sign in to comment.