• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

freqtrade / freqtrade / 9394559170

26 Apr 2024 06:36AM UTC coverage: 94.656% (-0.02%) from 94.674%
9394559170

push

github

xmatthias
Loader should be passed as kwarg for clarity

20280 of 21425 relevant lines covered (94.66%)

0.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.5
/freqtrade/rpc/api_server/web_ui.py
1
from pathlib import Path
1✔
2
from typing import Optional
1✔
3

4
from fastapi import APIRouter
1✔
5
from fastapi.exceptions import HTTPException
1✔
6
from starlette.responses import FileResponse
1✔
7

8

9
router_ui = APIRouter()
1✔
10

11

12
@router_ui.get('/favicon.ico', include_in_schema=False)
1✔
13
async def favicon():
1✔
14
    return FileResponse(str(Path(__file__).parent / 'ui/favicon.ico'))
1✔
15

16

17
@router_ui.get('/fallback_file.html', include_in_schema=False)
1✔
18
async def fallback():
1✔
19
    return FileResponse(str(Path(__file__).parent / 'ui/fallback_file.html'))
1✔
20

21

22
@router_ui.get('/ui_version', include_in_schema=False)
1✔
23
async def ui_version():
1✔
24
    from freqtrade.commands.deploy_commands import read_ui_version
1✔
25
    uibase = Path(__file__).parent / 'ui/installed/'
1✔
26
    version = read_ui_version(uibase)
1✔
27

28
    return {
1✔
29
        "version": version if version else "not_installed",
30
    }
31

32

33
def is_relative_to(path: Path, base: Path) -> bool:
1✔
34
    # Helper function simulating behaviour of is_relative_to, which was only added in python 3.9
35
    try:
1✔
36
        path.relative_to(base)
1✔
37
        return True
×
38
    except ValueError:
1✔
39
        pass
1✔
40
    return False
1✔
41

42

43
@router_ui.get('/{rest_of_path:path}', include_in_schema=False)
1✔
44
async def index_html(rest_of_path: str):
1✔
45
    """
46
    Emulate path fallback to index.html.
47
    """
48
    if rest_of_path.startswith('api') or rest_of_path.startswith('.'):
1✔
49
        raise HTTPException(status_code=404, detail="Not Found")
1✔
50
    uibase = Path(__file__).parent / 'ui/installed/'
1✔
51
    filename = uibase / rest_of_path
1✔
52
    # It's security relevant to check "relative_to".
53
    # Without this, Directory-traversal is possible.
54
    media_type: Optional[str] = None
1✔
55
    if filename.suffix == '.js':
1✔
56
        # Force text/javascript for .js files - Circumvent faulty system configuration
57
        media_type = 'application/javascript'
1✔
58
    if filename.is_file() and is_relative_to(filename, uibase):
1✔
59
        return FileResponse(str(filename), media_type=media_type)
×
60

61
    index_file = uibase / 'index.html'
1✔
62
    if not index_file.is_file():
1✔
63
        return FileResponse(str(uibase.parent / 'fallback_file.html'))
1✔
64
    # Fall back to index.html, as indicated by vue router docs
65
    return FileResponse(str(index_file))
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc