Skip to content

Commit

Permalink
Bumped Airshare to version 0.1.1
Browse files Browse the repository at this point in the history
* Removed python-magic dependency
* Added print to indicate clipboard copy for `-cr`
* Improved static files download.html and text.html
* Added text copy button for text.html
  • Loading branch information
nandahkrishna committed May 1, 2020
1 parent 8c5a7f1 commit 6c257fd
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 21 deletions.
1 change: 1 addition & 0 deletions airshare/cli.py
Expand Up @@ -58,6 +58,7 @@ def main(code, port, text, upload, clip_send, clip_receive, file_path, files):
if is_file_copyable(content):
with open(content, "r") as f:
pyperclip.copy(f.read())
print("File copied to clipboard!")
else:
print("This file cannot be copied to the clipboard!")
else:
Expand Down
8 changes: 3 additions & 5 deletions airshare/sender.py
Expand Up @@ -4,7 +4,6 @@
from aiohttp import web
import asyncio
import humanize
import magic
from multiprocessing import Process
import os
import pkgutil
Expand Down Expand Up @@ -68,8 +67,7 @@ async def _file_stream_sender(request):
file_name = request.app["file_name"]
file_size = str(request.app["file_size"])
header = "attachment; filename={}; size={}".format(file_name, file_size)
response.headers["content-type"] = magic.Magic(mime=True) \
.from_file(file_path)
response.headers["content-type"] = "application/octet-stream"
response.headers["content-length"] = str(request.app["file_size"])
response.headers["content-disposition"] = header
await response.prepare(request)
Expand Down Expand Up @@ -203,7 +201,7 @@ def send_server(*, code, text=None, file=None, compress=False, port=80):
app["file_path"] = os.path.realpath(content)
app["file_name"] = name or app["file_path"].split(os.path.sep)[-1]
app["file_size"] = os.stat(app["file_path"]).st_size
file_size = " (" + humanize.naturalsize(app["file_size"]) + ") "
file_size = " (" + humanize.naturalsize(app["file_size"]) + ")"
content = app["file_name"]
app.router.add_get(path="/", handler=_download_page)
app.router.add_get(path="/airshare", handler=_is_airshare_file_sender)
Expand All @@ -216,7 +214,7 @@ def send_server(*, code, text=None, file=None, compress=False, port=80):
if port != 80:
url_port = ":" + str(port)
ip = socket.inet_ntoa(addresses[0]) + url_port
print("`" + content + "`" + file_size + "available at " + ip
print("`" + content + "`" + file_size + " available at " + ip
+ " and `http://" + code + ".local" + url_port + "`, press CtrlC"
+ " to stop sharing...")
if platform.system() != "Windows":
Expand Down
3 changes: 2 additions & 1 deletion airshare/static/download.html
Expand Up @@ -32,6 +32,7 @@
backface-visibility: hidden;
text-decoration: none;
color: var(--text);
cursor: pointer;
}
.rocket-button:before {
content: '';
Expand Down Expand Up @@ -463,7 +464,7 @@
<div style="display: flex;">
<h1 style="text-align: center; justify-content: center;">Airshare</h1>
<div style="width: 16px"></div>
<svg width="40" height="40" style="margin-top: 16px" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<svg aria-hidden="true" width="40" height="40" style="margin-top: 16px" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M20 38.5H1.5V20C1.5 9.78273 9.78273 1.5 20 1.5C30.2173 1.5 38.5 9.78273 38.5 20C38.5 30.2173 30.2173 38.5 20 38.5Z" stroke="#450063" stroke-width="3"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M23.9929 31.8899C24.3465 31.8902 24.6492 31.6365 24.7106 31.2882C25.5639 26.8299 24.1571 22.238 20.9529 19.0227C17.744 15.793 13.1341 14.3792 8.66624 15.2544C8.38788 15.2819 8.14891 15.4642 8.04888 15.7254C7.94885 15.9867 8.00489 16.282 8.19367 16.4884C8.38246 16.6948 8.67159 16.7769 8.94069 16.7005C12.9259 15.9251 17.0354 17.1881 19.8973 20.0677C22.7775 22.9304 24.0541 27.033 23.3068 31.0244C23.2697 31.2176 23.3113 31.4177 23.4223 31.5801C23.5333 31.7426 23.7044 31.8541 23.8979 31.8899H23.9929ZM17.2268 22.7488C19.4848 25.0097 20.2732 28.3515 19.264 31.3832C19.1712 31.6666 18.9174 31.8664 18.6201 31.8899C18.5435 31.905 18.4646 31.905 18.3879 31.8899C18.0007 31.7641 17.7882 31.3486 17.9129 30.961C18.7778 28.4561 18.1419 25.6771 16.2736 23.7976C14.4053 21.9181 11.6303 21.2655 9.12013 22.1155C8.72976 22.2408 8.3112 22.0291 8.18068 21.6405C8.05604 21.2529 8.26846 20.8375 8.65569 20.7116C11.6677 19.7055 14.9896 20.4951 17.2268 22.7488ZM8.30825 29.9347C7.81859 28.7522 8.08897 27.3911 8.99346 26.4855C10.2412 25.3229 12.1855 25.3572 13.3914 26.5631C14.5973 27.769 14.6316 29.7134 13.469 30.961C12.8757 31.5551 12.0708 31.8892 11.2312 31.8899C9.95131 31.8889 8.7979 31.1173 8.30825 29.9347ZM10.3057 30.1177C10.9696 30.5639 11.8562 30.4796 12.424 29.916C12.7419 29.6006 12.9205 29.1711 12.9201 28.7232C12.9194 27.9233 12.3542 27.235 11.5697 27.0788C10.7852 26.9225 9.99936 27.3416 9.69216 28.0802C9.38495 28.8189 9.64172 29.6716 10.3057 30.1177Z" fill="#1DA1F2"/>
</svg>
Expand Down
23 changes: 20 additions & 3 deletions airshare/static/text.html
Expand Up @@ -56,14 +56,20 @@
<div style="display: flex;">
<h1 style="text-align: center; justify-content: center;">Airshare</h1>
<div style="width: 16px"></div>
<svg width="40" height="40" style="margin-top: 16px" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<svg aria-hidden="true" width="40" height="40" style="margin-top: 16px;" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M20 38.5H1.5V20C1.5 9.78273 9.78273 1.5 20 1.5C30.2173 1.5 38.5 9.78273 38.5 20C38.5 30.2173 30.2173 38.5 20 38.5Z" stroke="#450063" stroke-width="3"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M23.9929 31.8899C24.3465 31.8902 24.6492 31.6365 24.7106 31.2882C25.5639 26.8299 24.1571 22.238 20.9529 19.0227C17.744 15.793 13.1341 14.3792 8.66624 15.2544C8.38788 15.2819 8.14891 15.4642 8.04888 15.7254C7.94885 15.9867 8.00489 16.282 8.19367 16.4884C8.38246 16.6948 8.67159 16.7769 8.94069 16.7005C12.9259 15.9251 17.0354 17.1881 19.8973 20.0677C22.7775 22.9304 24.0541 27.033 23.3068 31.0244C23.2697 31.2176 23.3113 31.4177 23.4223 31.5801C23.5333 31.7426 23.7044 31.8541 23.8979 31.8899H23.9929ZM17.2268 22.7488C19.4848 25.0097 20.2732 28.3515 19.264 31.3832C19.1712 31.6666 18.9174 31.8664 18.6201 31.8899C18.5435 31.905 18.4646 31.905 18.3879 31.8899C18.0007 31.7641 17.7882 31.3486 17.9129 30.961C18.7778 28.4561 18.1419 25.6771 16.2736 23.7976C14.4053 21.9181 11.6303 21.2655 9.12013 22.1155C8.72976 22.2408 8.3112 22.0291 8.18068 21.6405C8.05604 21.2529 8.26846 20.8375 8.65569 20.7116C11.6677 19.7055 14.9896 20.4951 17.2268 22.7488ZM8.30825 29.9347C7.81859 28.7522 8.08897 27.3911 8.99346 26.4855C10.2412 25.3229 12.1855 25.3572 13.3914 26.5631C14.5973 27.769 14.6316 29.7134 13.469 30.961C12.8757 31.5551 12.0708 31.8892 11.2312 31.8899C9.95131 31.8889 8.7979 31.1173 8.30825 29.9347ZM10.3057 30.1177C10.9696 30.5639 11.8562 30.4796 12.424 29.916C12.7419 29.6006 12.9205 29.1711 12.9201 28.7232C12.9194 27.9233 12.3542 27.235 11.5697 27.0788C10.7852 26.9225 9.99936 27.3416 9.69216 28.0802C9.38495 28.8189 9.64172 29.6716 10.3057 30.1177Z" fill="#1DA1F2"/>
</svg>
<br>
</div>
<div id="airshare-text" class="textzone"></div>
<script>
<div style="display: flex; justify-content: center;">
<div id="airshare-text" class="textzone"></div>
<div style="width: 16px"></div>
<svg onclick="clipText();" width="20" height="20" aria-hidden="true" data-prefix="far" data-icon="copy" role="img" style="cursor: pointer;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">
<path d="M433.941 65.941l-51.882-51.882A48 48 0 0 0 348.118 0H176c-26.51 0-48 21.49-48 48v48H48c-26.51 0-48 21.49-48 48v320c0 26.51 21.49 48 48 48h224c26.51 0 48-21.49 48-48v-48h80c26.51 0 48-21.49 48-48V99.882a48 48 0 0 0-14.059-33.941zM266 464H54a6 6 0 0 1-6-6V150a6 6 0 0 1 6-6h74v224c0 26.51 21.49 48 48 48h96v42a6 6 0 0 1-6 6zm128-96H182a6 6 0 0 1-6-6V54a6 6 0 0 1 6-6h106v88c0 13.255 10.745 24 24 24h88v202a6 6 0 0 1-6 6zm6-256h-64V48h9.632c1.591 0 3.117.632 4.243 1.757l48.368 48.368a6 6 0 0 1 1.757 4.243V112z"></path>
</svg>
</div>
<script>
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).charming=e()}}(function(){return function(){return function e(n,t,r){function o(f,u){if(!t[f]){if(!n[f]){var c="function"==typeof require&&require;if(!u&&c)return c(f,!0);if(i)return i(f,!0);var a=new Error("Cannot find module '"+f+"'");throw a.code="MODULE_NOT_FOUND",a}var d=t[f]={exports:{}};n[f][0].call(d.exports,function(e){return o(n[f][1][e]||e)},d,d.exports,e,n,t,r)}return t[f].exports}for(var i="function"==typeof require&&require,f=0;f<r.length;f++)o(r[f]);return o}}()({1:[function(e,n,t){n.exports=function(e,{tagName:n="span",split:t,setClassName:r=function(e){return"char"+e}}={}){e.normalize();let o=1;function i(e){const i=e.parentNode,f=e.nodeValue;(t?t(f):f.split("")).forEach(function(t){const f=document.createElement(n),u=r(o++,t);u&&(f.className=u),f.appendChild(document.createTextNode(t)),f.setAttribute("aria-hidden","true"),i.insertBefore(f,e)}),""!==f.trim()&&i.setAttribute("aria-label",f),i.removeChild(e)}!function e(n){if(3===n.nodeType)return i(n);const t=Array.prototype.slice.call(n.childNodes);if(1===t.length&&3===t[0].nodeType)return i(t[0]);t.forEach(function(n){e(n)})}(e)}},{}]},{},[1])(1)});
window.addEventListener('load',
function () {
Expand All @@ -75,6 +81,17 @@ <h1 style="text-align: center; justify-content: center;">Airshare</h1>
}
http.send();
}, false);
function clipText() {
var copyText = document.getElementById("airshare-text").innerHTML;
var temp = document.createElement("input");
var body = document.getElementsByTagName("body")[0]
body.appendChild(temp);
temp.setAttribute("value", copyText);
temp.select();
temp.setSelectionRange(0, 99999);
document.execCommand("copy");
body.removeChild(temp);
}
</script>
</body>
</html>
14 changes: 8 additions & 6 deletions airshare/utils.py
@@ -1,7 +1,7 @@
"""Utility functions for Airshare."""


import magic
import mimetypes
import os
import pyperclip
import re
Expand Down Expand Up @@ -191,9 +191,11 @@ def is_file_copyable(file_path):
copyable : boolean
True if the file can be copied to the clipboard, False otherwise.
"""
file_type = magic.Magic(mime=True).from_file(file_path)
if (re.findall("text|json", file_type, re.IGNORECASE)):
copyable = True
else:
copyable = False
file_type = mimetypes.guess_type(file_path)[0]
copyable = False
if file_type is not None:
if (re.findall("text|json", file_type, re.IGNORECASE)):
copyable = True
else:
copyable = False
return copyable
2 changes: 0 additions & 2 deletions docs/requirements.txt
Expand Up @@ -4,11 +4,9 @@ click==7.0
humanize==0.5.1
pyperclip==1.8.0
pyqrcode==1.2.1
python-magic==0.4.15
requests==2.20.0
requests-toolbelt==0.9.1
tqdm==4.36.1
zeroconf==0.25.0
python-magic-bin==0.4.14 ; sys_platform=='win32' or sys_platform=='darwin'
sphinxcontrib-fulltoc==1.2.0
python-docs-theme==2020.1
2 changes: 1 addition & 1 deletion docs/source/conf.py
Expand Up @@ -23,7 +23,7 @@
author = 'Kandavel A, Mohanasundar M, Nanda H Krishna'

# The full version, including alpha/beta/rc tags
release = '0.1.0'
release = '0.1.1'


# -- General configuration ---------------------------------------------------
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Expand Up @@ -6,7 +6,7 @@

setuptools.setup(
name="Airshare",
version="0.1.0",
version="0.1.1",
author="Kandavel A, Mohanasundar M, Nanda H Krishna",
author_email="kurolabs.org+airshare@gmail.com",
description="An easy way to share content in a local network.",
Expand Down Expand Up @@ -37,11 +37,10 @@
"humanize >= 0.5.1",
"pyperclip >= 1.8.0",
"pyqrcode >= 1.2.1",
"python-magic == 0.4.15",
"requests >= 2.20.0",
"requests-toolbelt >= 0.9.1",
"tqdm >= 4.36.1",
"zeroconf >= 0.25.0",
] + ["python-magic-bin == 0.4.14"] if "win" in sys.platform else [],
],
python_requires=">=3.6",
)

0 comments on commit 6c257fd

Please sign in to comment.