Skip to content

Commit 37e3d04

Browse files
Refactor API URL handling to use a centralized variable and update README with port information
1 parent bdcfdf6 commit 37e3d04

9 files changed

+24
-7
lines changed

CLI/cas/cli.py

+5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@
1010
from .commands.group_privacy import group_privacy_command
1111
from .commands.group_list import group_list_command
1212
from .session_utils import load_session_details
13+
import os
1314

1415
# Initialize Rich Console
1516
console = Console()
1617

18+
API_URL = "https://api.cas.upayan.dev"
19+
if os.getenv("ENV") == "development":
20+
API_URL = "http://localhost:4000"
21+
1722
def is_user_authenticated():
1823
session_details = load_session_details()
1924
if not session_details:

CLI/cas/commands/group_create.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from rich.prompt import Prompt
33
import requests
44
from ..session_utils import load_session_details
5+
from ..cli import API_URL
56

67
console = Console()
78

@@ -14,7 +15,7 @@ def group_create_command():
1415
console.print("[bold red]❌ Error: User is not logged in. Please log in first.[/]")
1516
return
1617

17-
api_url = "https://api.cas.upayan.dev/auth/group/create"
18+
api_url = f"{API_URL}/auth/group/create"
1819
headers = {"Authorization": session_details["token"], "Content-Type": "application/json"}
1920

2021
# Prompt the user for group details

CLI/cas/commands/group_delete.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from rich.prompt import Prompt
33
import requests
44
from ..session_utils import load_session_details
5+
from ..cli import API_URL
56

67
console = Console()
78

@@ -14,7 +15,7 @@ def group_delete_command():
1415
console.print("[bold red]❌ Error: User is not logged in. Please log in first.[/]")
1516
return
1617

17-
api_url = "https://api.cas.upayan.dev/auth/group/delete"
18+
api_url = f"{API_URL}/auth/group/delete"
1819
headers = {"Authorization": session_details["token"], "Content-Type": "application/json"}
1920

2021
# Prompt the user for the group ID

CLI/cas/commands/group_list.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from rich.console import Console
22
import requests
33
from ..session_utils import load_session_details
4+
from ..cli import API_URL
45

56
console = Console()
67

@@ -13,7 +14,7 @@ def group_list_command():
1314
console.print("[bold red]❌ Error: User is not logged in. Please log in first.[/]")
1415
return
1516

16-
api_url = "https://api.cas.upayan.dev/auth/group/list"
17+
api_url = f"{API_URL}/auth/group/list"
1718
headers = {"Authorization": session_details["token"]}
1819

1920
try:

CLI/cas/commands/group_privacy.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from rich.prompt import Prompt
33
import requests
44
from ..session_utils import load_session_details
5+
from ..cli import API_URL
56

67
console = Console()
78

@@ -14,7 +15,7 @@ def group_privacy_command():
1415
console.print("[bold red]❌ Error: User is not logged in. Please log in first.[/]")
1516
return
1617

17-
api_url = "https://api.cas.upayan.dev/auth/group/privacy"
18+
api_url = f"{API_URL}/auth/group/privacy"
1819
headers = {"Authorization": session_details["token"], "Content-Type": "application/json"}
1920

2021
# Prompt the user for the group ID and privacy setting

CLI/cas/commands/pull.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from rich.table import Table
33
import requests
44
from ..session_utils import load_session_details
5+
from ..cli import API_URL
56

67
console = Console()
78

@@ -11,7 +12,7 @@ def pull_command():
1112
console.print("[bold red]❌ Error: User is not logged in. Please log in first.[/]")
1213
return
1314

14-
api_url = "https://api.cas.upayan.dev/pull"
15+
api_url = f"{API_URL}/pull"
1516
headers = {"Authorization": session_details["token"]}
1617

1718
try:

CLI/cas/commands/push.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from rich.console import Console
22
import requests
33
from ..session_utils import load_session_details, is_valid_url
4+
from ..cli import API_URL
45

56
console = Console()
67

@@ -28,7 +29,7 @@ def push_command(args):
2829
console.print("[bold red]❌ Error: User is not logged in. Please log in first.[/]")
2930
return
3031

31-
api_url = "https://api.cas.upayan.dev/push"
32+
api_url = f"{API_URL}/push"
3233
headers = {"Authorization": session_details["token"]}
3334
payload = {"article": article}
3435
if message:

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ pip install collaborative-article-sharing
2020
### Commands
2121

2222
For detailed instructions on using the CLI, please refer to [its specific README file](./CLI/README.md)
23+
24+
### Ports
25+
26+
APP : 3000
27+
API : 4000
28+
CLI Authentication : 8000

api/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,5 @@ def get_articles():
170170
return jsonify({"error": str(e)}), 500
171171

172172
if __name__ == '__main__':
173-
port = int(3000)
173+
port = int(4000)
174174
app.run(debug=True, port=port)

0 commit comments

Comments
 (0)