-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
179 additions
and
44 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
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
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,65 @@ | ||
package apis | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
const index = `<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>QR Code Scanner For</title> | ||
</head> | ||
<body> | ||
<h1>Scan The QR Code to Log into whatsapp web account</h1> | ||
<img height="512" width="512" /> | ||
<script> | ||
// get host url for api calling | ||
const id = "%s"; | ||
// const url = window.location.href | ||
const url = ` + "`${window.location.protocol}//${window.location.host}/v1/qr_code/`;" + | ||
` function hexToBase64(str) { | ||
return btoa( | ||
String.fromCharCode.apply( | ||
null, | ||
str | ||
.replace(/\r|\n/g, '') | ||
.replace(/([\da-fA-F]{2}) ?/g, '0x$1 ') | ||
.replace(/ +$/, '') | ||
.split(' ') | ||
) | ||
); | ||
} | ||
async function CallAPIAndSetImage() { | ||
const res = await fetch(url, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-Api-Token': id, | ||
}, | ||
}); | ||
try { | ||
const data = await res.json(); | ||
if(data.qrCode){ | ||
const img = document.querySelector('img'); | ||
img.src = 'data:image/png;base64,' + data.qrCode; | ||
} | ||
} catch (error) {} | ||
} | ||
CallAPIAndSetImage(); | ||
setInterval(() => CallAPIAndSetImage(), 5000); | ||
// const img = document.querySelector('img') | ||
// const url = window.location.href | ||
</script> | ||
</body> | ||
</html>` | ||
|
||
func OpenBrowserWithQr(c *fiber.Ctx) error { | ||
id := c.Params("id") | ||
// println(c.Hostname()) | ||
c.Set("Content-Type", "text/html; charset=utf-8") | ||
return c.Send([]byte(fmt.Sprintf(index, id))) | ||
} |
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
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
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
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
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
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 |
---|---|---|
@@ -1,21 +1,51 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<script src="https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js"></script> | ||
<title>QR Code Scanner For </title> | ||
</head> | ||
<body> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>QR Code Scanner For</title> | ||
</head> | ||
<body> | ||
<h1>Scan The QR Code to Log into whatsapp web account</h1> | ||
<img height="512" width="512"> | ||
<img height="512" width="512" /> | ||
<script> | ||
// get host url for api calling | ||
const url = window.location.href | ||
|
||
// const img = document.querySelector('img') | ||
// const url = window.location.href | ||
|
||
// get host url for api calling | ||
const id = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; | ||
// const url = window.location.href | ||
const url = `${window.location.protocol}//${window.location.host}/v1/qr_code/`; | ||
function hexToBase64(str) { | ||
return btoa( | ||
String.fromCharCode.apply( | ||
null, | ||
str | ||
.replace(/\r|\n/g, '') | ||
.replace(/([\da-fA-F]{2}) ?/g, '0x$1 ') | ||
.replace(/ +$/, '') | ||
.split(' ') | ||
) | ||
); | ||
} | ||
async function CallAPIAndSetImage() { | ||
const res = await fetch(url, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-Api-Token': id, | ||
}, | ||
}); | ||
try { | ||
const data = await res.json(); | ||
if(data.qrCode){ | ||
const img = document.querySelector('img'); | ||
img.src = 'data:image/png;base64,' + hexToBase64(data.qrCode); | ||
} | ||
} catch (error) {} | ||
} | ||
CallAPIAndSetImage(); | ||
setInterval(() => CallAPIAndSetImage(), 5000); | ||
|
||
// const img = document.querySelector('img') | ||
// const url = window.location.href | ||
</script> | ||
</body> | ||
</html> | ||
</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
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
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