diff --git a/main.py b/main.py index d20af8697f500e828701fd577cc1ab92872f48bd..23d26a51e9d6385285ffad94f008e2f2ef776ef8 100644 --- a/main.py +++ b/main.py @@ -379,10 +379,21 @@ def api(): 'INSERT INTO WEB_URL (LONG_URL, SHORT_URL, USERNAME) VALUES (?, ?, ?)', [longURL, short, username] ) - return jsonify( - status="0", - message="ok" - ) + + try: + request.form['qr'] + qr64 = "data:image/jpeg;base64," + makeQR(url_scheme + "://" + short) + + return jsonify( + status="0", + message="ok", + qr=qr64 + ) + except: + return jsonify( + status="0", + message="ok" + ) else: return jsonify( status="4", diff --git a/templates/apiDocs.html b/templates/apiDocs.html index 4d65600a7e13cfdc5eafe44878d6c150270ad58b..e33d0e9b6555c87efa537a9824c96295fe3542f9 100644 --- a/templates/apiDocs.html +++ b/templates/apiDocs.html @@ -23,15 +23,17 @@ <ul> <li>short: the short URL you want to get. example: {{domain}}/example</li> <li>long: the long URL you want to short</li> + <li>qr: if you add this parameter you will get an base64 encoded QR code image</li> <li>apikey: you can add this argument, if you want to assign this link to your account.</li> </ul> - <p>example API call with curl: <i>curl -d "apikey={{apikey}}&short={{domain}}/example&long=http://example.com" -X POST {{url_scheme}}://{{domain}}/user/api</i></p> + <p>example API call with curl: <i>curl -d "apikey={{apikey}}&short={{domain}}/example&long=http://example.com" -X POST {{url_scheme}}://{{domain}}/user/api</i> <h3>Responses from Server</h3> <p>The response from the server is always made in json format it includes the following arguments:</p> <ul> <li>status: The status code of the reponse. Down there is a table with the posible response codes</li> <li>message: This argument will do the same like the status code, but it is written out, for reading by human.</li> + <li>qr: If you enabled the QR code this will include a QR code of the shorten link as base64 coded jpeg image</li> </ul> <h4>Response codes:</h4> @@ -62,4 +64,15 @@ </tr> </table> + + <h2>Preview image</h2> + <p>Please paste your base64 image here: <input type="text" id="base64Input"> <button onclick="showBase64Image();">show</button></p> + <p style="font-size: 13px;">(this will not work very well in google Chrome)</p> + <img id="base64Image"> + + <script> + function showBase64Image(){ + document.getElementById("base64Image").src = document.getElementById("base64Input").value; + } + </script> </body> \ No newline at end of file