-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.py
More file actions
94 lines (70 loc) · 2.85 KB
/
Copy pathcli.py
File metadata and controls
94 lines (70 loc) · 2.85 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import os
import typer
import stores.user_current_shared_path as shared_path
import stores.share_status as share_status
from server import create_app
from waitress import serve
from rich.console import Console
from helpers.tunnel import start_tunnel
from utils.network_ip import get_local_ip
from utils.secrets_filter import confirm_to_share_secrets_in_cwd
# Initialize Typer and Rich console for clean formatting
cli = typer.Typer(
name="WarpShare",
help="⚡ Instant file sharing CLI tool (Local Wi-Fi & Remote Internet) ⚡",
add_completion=False,
)
console = Console()
def start_server(host: str, port: int, path: str):
app = create_app()
shared_path.path = path
serve(app, host=host, port=port)
# app.run(debug=True)
# LOCAL SHARE
@cli.command(name="local")
def local_share(
path: str = typer.Argument(os.getcwd(), help="The directory path or file to share"),
port: int = typer.Option(3301, "--port", "-p", help="Port to run the local server on"),
):
"""
Share files instantly with anyone on your local Wi-Fi network.
"""
if not os.path.exists(path):
console.print(f"[bold red][Error][/bold red] Path '{path}' does not exist.")
raise typer.Exit(code=1)
ip = get_local_ip()
if ip is None:
console.print(f"[bold red][Error][/bold red] No Network IP found. Make sure you're connected to the same network with the receiver.")
raise typer.Exit(code=1)
console.print(f"[yellow]Port:[/yellow] {port}")
console.print(f"[yellow]Target Folder:[/yellow] {os.path.abspath(path)}")
confirm_to_share_secrets_in_cwd(path)
share_status.status = "Offline"
console.print(f"\n[bold green]Local Sharing Server started at http://{ip}:{port}[/bold green]")
start_server(ip, port, path)
# ONLINE SHARE
@cli.command(name="remote")
def remote_share(
path: str = typer.Argument(os.getcwd(), help="The directory path or file to share"),
port: int = typer.Option(3301, "--port", "-p", help="Internal port for the tunnel"),
):
import threading
"""
Share files over the public internet with a remote receiver.
"""
if not os.path.exists(path):
console.print(f"[bold red][Error][/bold red] Path '{path}' does not exist.")
raise typer.Exit(code=1)
console.print(f"[bold cyan]Initializing Secure Remote Connection...[/bold cyan]")
console.print(f"[yellow]Target Folder:[/yellow] {os.path.abspath(path)}")
confirm_to_share_secrets_in_cwd(path)
host = "127.0.0.1"
share_status.status = "Online"
t = threading.Thread(target=start_server, args=(host, port, path), daemon=True)
t.start()
console.print(f"[bold cyan]Server started, creating remote tunnel...[/bold cyan]")
def on_url(url):
console.print(f"\n[bold green]Remote Tunnel created at {url}[/bold green]")
start_tunnel(port, on_url=on_url) # blocks here, keeps process alive
if __name__ == "__main__":
cli()