Skip to content

Commit 1298228

Browse files
committed
Remove legacy routers for all API functions
1 parent 551d82e commit 1298228

17 files changed

Lines changed: 119 additions & 184 deletions

docs/index.html

Lines changed: 24 additions & 24 deletions
Large diffs are not rendered by default.

jarvis/api/logger.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
api_config = APIConfig()
2121
multiprocessing_logger(filename=api_config.DEFAULT_LOG_FILENAME)
2222

23-
2423
# Creates log files
2524
if not os.path.isfile(api_config.ACCESS_LOG_FILENAME):
2625
pathlib.Path(api_config.ACCESS_LOG_FILENAME).touch()

jarvis/api/routers/basics.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import os
22
from http import HTTPStatus
33

4-
from fastapi import APIRouter
5-
from fastapi.responses import FileResponse, RedirectResponse
4+
from fastapi.responses import FileResponse
65

76
from jarvis.api.logger import logger
8-
from jarvis.api.models import authenticator
97
from jarvis.modules.conditions import keywords as keywords_mod
108
from jarvis.modules.exceptions import APIResponse
119

12-
router = APIRouter()
1310

14-
15-
@router.get(path="/", response_class=RedirectResponse, include_in_schema=False)
1611
async def redirect_index():
1712
"""Redirect to docs in read-only mode.
1813
@@ -24,7 +19,6 @@ async def redirect_index():
2419
return "/redoc"
2520

2621

27-
@router.get(path="/health", include_in_schema=False)
2822
async def health():
2923
"""Health Check for OfflineCommunicator.
3024
@@ -35,7 +29,6 @@ async def health():
3529
raise APIResponse(status_code=HTTPStatus.OK, detail=HTTPStatus.OK.phrase)
3630

3731

38-
@router.get(path="/favicon.ico", include_in_schema=False)
3932
async def get_favicon():
4033
"""Gets the favicon.ico and adds to the API endpoint.
4134
@@ -57,7 +50,6 @@ async def get_favicon():
5750
)
5851

5952

60-
@router.get(path="/keywords", dependencies=authenticator.OFFLINE_PROTECTOR)
6153
async def keywords():
6254
"""Converts the keywords and conversations into a dictionary of key-value pairs.
6355

jarvis/api/routers/fileio.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@
22
from datetime import datetime
33
from http import HTTPStatus
44

5-
from fastapi import APIRouter, UploadFile
5+
from fastapi import UploadFile
66
from fastapi.responses import FileResponse
77

88
from jarvis.api.logger import logger
9-
from jarvis.api.models import authenticator
109
from jarvis.modules.exceptions import APIResponse
1110
from jarvis.modules.models import models
1211

13-
router = APIRouter()
1412

15-
16-
@router.get(path="/list-files", dependencies=authenticator.OFFLINE_PROTECTOR)
1713
async def list_files():
1814
"""Get all YAML files from fileio and all log files from logs directory.
1915
@@ -41,11 +37,6 @@ async def list_files():
4137
}
4238

4339

44-
@router.get(
45-
path="/get-file",
46-
response_class=FileResponse,
47-
dependencies=authenticator.OFFLINE_PROTECTOR,
48-
)
4940
async def get_file(filename: str):
5041
"""Download a particular YAML file from fileio or log file from logs directory.
5142
@@ -89,7 +80,6 @@ async def get_file(filename: str):
8980
)
9081

9182

92-
@router.post(path="/put-file", dependencies=authenticator.OFFLINE_PROTECTOR)
9383
async def put_file(file: UploadFile):
9484
"""Upload a particular YAML file to the fileio directory.
9585

jarvis/api/routers/investment.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,18 @@
77

88
import gmailconnector
99
import jinja2
10-
from fastapi import APIRouter, Request
10+
from fastapi import Request
1111
from fastapi.responses import HTMLResponse
1212

1313
from jarvis.api.logger import logger
14-
from jarvis.api.models import authenticator, settings
14+
from jarvis.api.models import settings
1515
from jarvis.api.squire import timeout_otp
1616
from jarvis.modules.exceptions import CONDITIONAL_ENDPOINT_RESTRICTION, APIResponse
1717
from jarvis.modules.models import models
1818
from jarvis.modules.templates import templates
1919
from jarvis.modules.utils import support, util
2020

21-
router = APIRouter()
2221

23-
24-
@router.post(
25-
path="/robinhood-authenticate", dependencies=authenticator.ROBINHOOD_PROTECTOR
26-
)
2722
async def authenticate_robinhood():
2823
"""Authenticates the request and generates single use token.
2924
@@ -90,7 +85,6 @@ async def authenticate_robinhood():
9085
)
9186

9287

93-
@router.get(path="/investment", response_class=HTMLResponse)
9488
async def robinhood_path(request: Request, token: str = None):
9589
"""Serves static file.
9690

jarvis/api/routers/offline.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from http import HTTPStatus
55
from threading import Thread
66

7-
from fastapi import APIRouter, Request
7+
from fastapi import Request
88
from fastapi.responses import FileResponse
99

1010
from jarvis.api.logger import logger
11-
from jarvis.api.models import authenticator, modals
11+
from jarvis.api.models import modals
1212
from jarvis.api.routers import speech_synthesis
1313
from jarvis.executors import commander, offline, others, restrictions, word_match
1414
from jarvis.modules.audio import tts_stt
@@ -18,7 +18,6 @@
1818
from jarvis.modules.models import models
1919
from jarvis.modules.utils import support
2020

21-
router = APIRouter()
2221
db = database.Database(database=models.fileio.base_db)
2322

2423

@@ -78,7 +77,6 @@ async def process_ok_response(
7877
raise APIResponse(status_code=HTTPStatus.OK.real, detail=response)
7978

8079

81-
@router.post(path="/offline-communicator", dependencies=authenticator.OFFLINE_PROTECTOR)
8280
async def offline_communicator_api(
8381
request: Request, input_data: modals.OfflineCommunicatorModal
8482
):

jarvis/api/routers/proxy_service.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
from http import HTTPStatus
33

44
import requests
5-
from fastapi import APIRouter, Request, Response
5+
from fastapi import Request, Response
66
from pydantic import HttpUrl
77

88
from jarvis.api.logger import logger
99
from jarvis.modules.exceptions import APIResponse, EgressErrors
1010

11-
router = APIRouter()
12-
1311

1412
def is_valid_media_type(media_type: str) -> bool:
1513
"""Regular expression to match valid media types.
@@ -25,7 +23,6 @@ def is_valid_media_type(media_type: str) -> bool:
2523
return bool(re.match(media_type_pattern, media_type))
2624

2725

28-
@router.get(path="/proxy")
2926
async def proxy_service_api(request: Request, origin: HttpUrl, output: str):
3027
"""API endpoint to act as a proxy for GET calls.
3128

jarvis/api/routers/secure_send.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
from http import HTTPStatus
33
from typing import Optional
44

5-
from fastapi import APIRouter, Header, Request
5+
from fastapi import Header, Request
66

77
from jarvis.api.logger import logger
88
from jarvis.executors import files
99
from jarvis.modules.exceptions import APIResponse
1010
from jarvis.modules.models import models
1111

12-
router = APIRouter()
1312

14-
15-
@router.post(path="/secure-send")
1613
async def secure_send_api(request: Request, access_token: Optional[str] = Header(None)):
1714
"""API endpoint to share/retrieve secrets.
1815

jarvis/api/routers/speech_synthesis.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,16 @@
55
from urllib.parse import urljoin
66

77
import requests
8-
from fastapi import APIRouter
98
from fastapi.responses import FileResponse
109

1110
from jarvis.api.logger import logger
12-
from jarvis.api.models import authenticator, modals
11+
from jarvis.api.models import modals
1312
from jarvis.modules.audio import speaker
1413
from jarvis.modules.exceptions import APIResponse, EgressErrors
1514
from jarvis.modules.models import models
1615
from jarvis.modules.utils import support
1716

18-
router = APIRouter()
1917

20-
21-
@router.get(
22-
path="/speech-synthesis-voices", dependencies=authenticator.OFFLINE_PROTECTOR
23-
)
2418
async def speech_synthesis_voices():
2519
"""Get all available voices in speech synthesis.
2620
@@ -61,11 +55,6 @@ async def speech_synthesis_voices():
6155
raise APIResponse(status_code=response.status_code, detail=response.content)
6256

6357

64-
@router.post(
65-
path="/speech-synthesis",
66-
response_class=FileResponse,
67-
dependencies=authenticator.OFFLINE_PROTECTOR,
68-
)
6958
async def speech_synthesis(
7059
input_data: modals.SpeechSynthesisModal, raise_for_status: bool = True
7160
):

jarvis/api/routers/stats.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from collections.abc import Generator
1919
from typing import List
2020

21-
from fastapi import APIRouter
2221
from fastapi.responses import RedirectResponse
2322
from pydantic import FilePath, PositiveInt
2423

@@ -35,8 +34,6 @@ class StrEnum(str, Enum):
3534
"""Override for python 3.10 due to lack of StrEnum."""
3635

3736

38-
router = APIRouter()
39-
4037
FILE_EXTENSIONS: List[str] = [".html", ".py", ".scpt", ".sh", ".xml"]
4138

4239

@@ -49,17 +46,17 @@ class ValidColors(StrEnum):
4946
https://github.com/badges/buckler/blob/master/README.md#valid-colours
5047
"""
5148

52-
brightgreen: str = "brightgreen"
53-
green: str = "green"
54-
yellowgreen: str = "yellowgreen"
55-
yellow: str = "yellow"
56-
orange: str = "orange"
57-
red: str = "red"
58-
grey: str = "grey"
59-
gray: str = "grey"
60-
lightgrey: str = "lightgrey"
61-
lightgray: str = "lightgray"
62-
blue: str = "blue"
49+
brightgreen = "brightgreen"
50+
green = "green"
51+
yellowgreen = "yellowgreen"
52+
yellow = "yellow"
53+
orange = "orange"
54+
red = "red"
55+
grey = "grey"
56+
gray = "grey"
57+
lightgrey = "lightgrey"
58+
lightgray = "lightgray"
59+
blue = "blue"
6360

6461

6562
def should_include(filepath: FilePath) -> bool:
@@ -89,7 +86,7 @@ def count_lines(filepath: FilePath) -> PositiveInt:
8986
return sum(1 for _ in file)
9087

9188

92-
def get_files() -> Generator[FilePath]:
89+
def get_files() -> Generator[str]:
9390
"""Walk through the directory and collect all relevant files.
9491
9592
Yields:
@@ -126,9 +123,10 @@ def total_files() -> PositiveInt:
126123
return len(list(get_files()))
127124

128125

129-
@router.get(path="/line-count", include_in_schema=True)
130126
async def line_count(
131-
badge: bool = False, color: ValidColors = "blue", text: str = "lines of code"
127+
badge: bool = False,
128+
color: ValidColors = ValidColors.blue,
129+
text: str = "lines of code",
132130
):
133131
"""Get total lines of code for Jarvis.
134132
@@ -151,9 +149,10 @@ async def line_count(
151149
return total_lines
152150

153151

154-
@router.get(path="/file-count", include_in_schema=True)
155152
async def file_count(
156-
badge: bool = False, color: ValidColors = "blue", text: str = "total files"
153+
badge: bool = False,
154+
color: ValidColors = ValidColors.blue,
155+
text: str = "total files",
157156
):
158157
"""Get total number of files for Jarvis.
159158

0 commit comments

Comments
 (0)