-
Notifications
You must be signed in to change notification settings - Fork 1
/
ipfs-share
executable file
·46 lines (32 loc) · 1015 Bytes
/
ipfs-share
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
from subprocess import run, Popen, PIPE
from sys import argv
from os import path
from urllib.parse import quote
add_cmd = 'ipfs add --cid-version=1 --nocopy --raw-leaves --fscache --wrap-with-directory --recursive'
urls = [
'http://127.0.0.1:8080/ipfs',
'https://ipfs.io/ipfs',
]
if len(argv) == 1:
print(
'''USAGE:
ipfs-share file.ext
ipfs-share path/to/dir
ipfs-share http://path.to/file.ext
\b'''
)
def run_cmd(cmd):
p = Popen(cmd, shell=True, text=True, stdout=PIPE)
return p.communicate(timeout=None)
if len(argv) > 1:
file_name = path.basename(argv[1])
file_name_quote = quote(file_name)
out, err = run_cmd(f"{add_cmd} '{argv[1]}'")
out_split = out.split()
for i, v in enumerate(urls):
urls[i] = f'{v}/{out_split[-1]}/{file_name_quote}'
print(out)
print(f'http://{out_split[-1]}.ipfs.localhost:8080/{file_name_quote}\n')
print('\n\n'.join(urls))
run(f"wl-copy '{urls[-1]}'", shell=True)