Bunch more updates

This commit is contained in:
Daniel Legt 2022-05-18 01:36:18 +03:00
parent 1024c4abee
commit e6cc8a4bce
9 changed files with 90 additions and 12 deletions

View File

@ -10,7 +10,6 @@ MYDIR=`pwd`;
cd src; cd src;
# Build # Build
echo "Building..." echo "Building..."
export RELEASE_MODE=1; GIN_MODE=release CGO_ENABLED=0 GOOS=linux GIN_MODE=release go build -a -installsuffix cgo -o ../dist/freepad .
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o ../dist/freepad .
# Go back! # Go back!
cd $MYDIR; cd $MYDIR;

BIN
dist/freepad vendored

Binary file not shown.

View File

@ -80,3 +80,27 @@ function goToPost() {
} }
} }
} }
function getQr(link = `https://justkato.me/`) {
return new Promise((_r, _e) => {
let formData = new FormData();
formData.append('link', link);
// Send out a fetch request
fetch("/api/qr", {
method: "post",
body: formData,
})
.then( result => {
result.json()
.then( rez => {
return _r(rez);
})
})
.catch( error => {
console.error(error);
alert(error);
return _e(error);
})
})
}

View File

@ -1,9 +1,16 @@
{{ template "inc/header.html" .}} {{ template "inc/header.html" .}}
<style>
.qrImage[src=""] {
display: none;
}
</style>
<body> <body>
<div class="container is-fullhd p-4 mb-6" style="min-height: 35rem; height: calc(100vh - 18rem)"> <div class="container is-fullhd p-4 mb-6" style="min-height: 35rem; height: calc(100vh - 18rem)">
<h1 class="title">FreePad</h1> <h1 class="title">FreePad</h1>
<img class="qrImage" src="" alt="" style="position: fixed;top: 1rem;left: 1rem;max-width: 13vw;">
<h2 class="subtitle">Reading from <code>{{.domain_base}}/{{.title}}</code></h2> <h2 class="subtitle">Reading from <code>{{.domain_base}}/{{.title}}</code></h2>
<hr> <hr>
@ -11,7 +18,8 @@
<div class="content"> <div class="content">
<div class="block"> <div class="block">
<a href="/" class="button is-light">Back Home</a> <a href="/" class="button is-light">Back Home</a>
<a href="javascript:updateSelf()" class="button is-primary">Save</a> <a href="javascript:fetchMyQr()" class="button is-primary">QR</a>
<a href="javascript:updateSelf()" class="button is-success">Save</a>
<p class="mt-3">Status: <code class="has-text-primary" id="status-indicator">Loaded</code></p> <p class="mt-3">Status: <code class="has-text-primary" id="status-indicator">Loaded</code></p>
</div> </div>
<textarea class="input" name="post_content" id="post_content" onchange="updateSelf()">{{.post_content}}</textarea> <textarea class="input" name="post_content" id="post_content" onchange="updateSelf()">{{.post_content}}</textarea>
@ -19,10 +27,29 @@
</div> </div>
<script> <script>
async function fetchMyQr() {
let qrCode = await getQr(window.location.href)
.catch( err => {
console.error(err);
})
console.log(qrCode);
if ( !!qrCode.qr ) {
document.querySelectorAll(`.qrImage`).forEach( img => {
console.log(img);
console.log(qrCode.qr);
img.src = qrCode.qr;
})
}
}
function updateSelf() { function updateSelf() {
updatePost({{.title}}) updatePost({{.title}})
} }
</script> </script>
{{ template "inc/footer.html" .}} {{ template "inc/footer.html" .}}
</body> </body>
<script src="https://raw.githubusercontent.com/scotch-io/javascript-modal/master/Modal.js"></script>

View File

@ -3,8 +3,9 @@
echo "Removing old"; echo "Removing old";
rm dist/freepad; rm dist/freepad;
source ../.env
# Yeah, this is my solution # Yeah, this is my solution
export DOMAIN_BASE CACHE_MAP_LIMIT API_BAN_LIMIT DATABASE_DRIVER MYSQL_ROOT_PASSWORD MYSQL_DATABASE MYSQL_USER MYSQL_PASSWORD MYSQL_URL MYSQL_PORT export DOMAIN_BASE CACHE_MAP_LIMIT API_BAN_LIMIT DATABASE_DRIVER MYSQL_ROOT_PASSWORD MYSQL_DATABASE MYSQL_USER MYSQL_PASSWORD MYSQL_URL MYSQL_PORT IS_DEV
# Remember current path # Remember current path
MYDIR=`pwd`; MYDIR=`pwd`;
@ -12,14 +13,11 @@ MYDIR=`pwd`;
cd src; cd src;
# Build # Build
echo "Building..." echo "Building..."
unset RELEASE_MODE;
go build -o ../dist/freepad . go build -o ../dist/freepad .
# Go back! # Go back!
cd $MYDIR; cd $MYDIR;
MYPATH=`pwd`;
cd dist cd dist
source ../.env ./freepad && cd $MYDIR;
./freepad && cd $MYPATH;

View File

@ -7,5 +7,6 @@ require (
github.com/go-sql-driver/mysql v1.6.0 github.com/go-sql-driver/mysql v1.6.0
github.com/golang-migrate/migrate/v4 v4.15.2 github.com/golang-migrate/migrate/v4 v4.15.2
github.com/mattn/go-sqlite3 v1.14.13 github.com/mattn/go-sqlite3 v1.14.13
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
github.com/ulule/limiter/v3 v3.10.0 github.com/ulule/limiter/v3 v3.10.0
) )

View File

@ -1014,6 +1014,8 @@ github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrf
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=

View File

@ -10,8 +10,8 @@ import (
func main() { func main() {
_, isRelease := os.LookupEnv("RELEASE_MODE") _, isDevelopment := os.LookupEnv("IS_DEV")
if isRelease { if isDevelopment {
gin.SetMode(gin.ReleaseMode) gin.SetMode(gin.ReleaseMode)
} }

View File

@ -1,6 +1,7 @@
package routes package routes
import ( import (
"encoding/base64"
"fmt" "fmt"
"net/url" "net/url"
@ -8,6 +9,7 @@ import (
"github.com/JustKato/FreePad/helper" "github.com/JustKato/FreePad/helper"
"github.com/JustKato/FreePad/types" "github.com/JustKato/FreePad/types"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/skip2/go-qrcode"
) )
func ApiRoutes(route *gin.RouterGroup) { func ApiRoutes(route *gin.RouterGroup) {
@ -66,6 +68,31 @@ func ApiRoutes(route *gin.RouterGroup) {
// Add in health checks // Add in health checks
route.GET("/health", healthCheck) route.GET("/health", healthCheck)
route.POST("/qr", func(ctx *gin.Context) {
// Get the name of the post
link := ctx.PostForm("link")
// store the png somewhere
var png []byte
// Encode the link into a qr code
png, err := qrcode.Encode(link, qrcode.High, 512)
if err != nil {
ctx.JSON(200, types.FreeError{
Error: fmt.Sprint(err),
Message: "Failed to convert qr Code",
})
return
}
// Write the png to the response
ctx.JSON(200, gin.H{
"message": "Succesfully generated the QR",
"qr": "data:image/jpeg;base64," + base64.StdEncoding.EncodeToString(png),
})
})
} }
func healthCheck(ctx *gin.Context) { func healthCheck(ctx *gin.Context) {