Skip to content

Commit

Permalink
allow sharing of urls
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Dec 4, 2020
1 parent c381cb1 commit 84151a3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="share-snootclub",
version="0.0.0",
version="0.0.1",
author="chee",
author_email="chee@snoot.club",
description="share to share.snoot.club",
Expand Down
17 changes: 14 additions & 3 deletions share/__main__.py
Expand Up @@ -9,7 +9,6 @@
from slugify import slugify
from .getseq import getseq


def main():
parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down Expand Up @@ -44,13 +43,22 @@ def main():
args = parser.parse_args()

mimetypes.init()
source = None

if args.file.startswith("/tmp/.psub") or args.file.startswith("/dev/fd"):
source = args.file
prefix = getseq()
head = open(args.file, "rb").read(2048)
ext = mimetypes.guess_extension(magic.from_buffer(head, True))
output_filename = f"{prefix}{ext}"
elif args.file.startswith("https://") or args.file.startswith("http://"):
source = f"/tmp/{getseq()}.html"
with open(source, "t+w") as file:
file.write(f"""<!doctype html><meta http-equiv="refresh" content="0;url={args.file}"><a href="{args.file}">{args.file}</a>""")

output_filename = "index.html"
else:
source = args.file
[name, ext] = os.path.splitext(os.path.basename(args.file))
output_filename = f"{slugify(name)}{ext}"

Expand All @@ -65,11 +73,14 @@ def main():
"-zL",
"--progress",
"--chmod=a+rw",
args.file,
source,
f"{ssh_target}:{destdir}/{output_filename}"
], stdout=PIPE)

print(f"{args.public_root}/{dirname}/{output_filename}")
output = f"{args.public_root}/{dirname}/"
if output_filename is not "index.html":
output += output_filename
print(output)


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions share_chee.egg-info/SOURCES.txt
@@ -1,4 +1,5 @@
setup.py
share
share/__init__.py
share/__main__.py
share/getseq.py
Expand Down

0 comments on commit 84151a3

Please sign in to comment.