File size: 5,136 Bytes
f7d04cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import os
import platform
from fastapi import FastAPI
from fastapi.responses import HTMLResponse

app = FastAPI(
    title="Odoo Space API",
    description="This is a lightweight API serving for Odoo deployment on Hugging Face Spaces.",
    version="19.0"
)

@app.get("/health")
def health():
    """
    Mandatory endpoint returning HTTP 200 when the app is ready.
    """
    return {"status": "pass"}

@app.get("/api-docs", response_class=HTMLResponse)
def api_docs():
    """
    Mandatory endpoint that documents all available API endpoints.
    """
    html_content = """
    <!DOCTYPE html>
    <html>
    <head>
        <title>Odoo Space API Documentation</title>
        <style>
            body {
                font-family: Arial, sans-serif;
                margin: 40px;
                background-color: #f4f6f9;
                color: #333;
            }
            h1 {
                color: #7C5BBA;
            }
            .endpoint {
                background: white;
                padding: 20px;
                margin-bottom: 20px;
                border-radius: 8px;
                box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            }
            .method {
                font-weight: bold;
                padding: 4px 8px;
                border-radius: 4px;
                color: white;
                display: inline-block;
                margin-right: 10px;
            }
            .get { background-color: #61afff; }
            .post { background-color: #49cc90; }
            .path {
                font-family: monospace;
                font-size: 1.1em;
                font-weight: bold;
            }
            pre {
                background: #f8f8f8;
                padding: 10px;
                border: 1px solid #ddd;
                border-radius: 4px;
                overflow-x: auto;
            }
        </style>
    </head>
    <body>
        <h1>Odoo Space API Documentation</h1>
        <p>Welcome to the Odoo deployment Space. This lightweight API ensures the health and deployment status of the Odoo application environment.</p>

        <h2>Mandatory Endpoints</h2>

        <div class="endpoint">
            <span class="method get">GET</span><span class="path">/health</span>
            <p><strong>Purpose:</strong> Returns HTTP 200 when the app is ready. Required for Hugging Face to transition the Space from <em>starting</em> to <em>running</em>.</p>
            <p><strong>Response Example:</strong></p>
            <pre>{"status": "pass"}</pre>
        </div>

        <div class="endpoint">
            <span class="method get">GET</span><span class="path">/api-docs</span>
            <p><strong>Purpose:</strong> Documents all available API endpoints. Exposes this interactive documentation.</p>
        </div>

        <h2>Functional Endpoints</h2>

        <div class="endpoint">
            <span class="method get">GET</span><span class="path">/api/version</span>
            <p><strong>Purpose:</strong> Returns the application and Odoo version details.</p>
            <p><strong>Response Example:</strong></p>
            <pre>{"version": "19.0", "sdk": "docker"}</pre>
        </div>

        <div class="endpoint">
            <span class="method get">GET</span><span class="path">/api/modules</span>
            <p><strong>Purpose:</strong> Lists simulated or available Odoo modules.</p>
            <p><strong>Response Example:</strong></p>
            <pre>["base", "web", "crm", "website", "ecommerce", "inventory", "project"]</pre>
        </div>

        <div class="endpoint">
            <span class="method get">GET</span><span class="path">/api/sysinfo</span>
            <p><strong>Purpose:</strong> Returns OS, platform, and python execution environment info.</p>
            <p><strong>Response Example:</strong></p>
            <pre>{"os": "Linux", "python_version": "3.12.x", "arch": "x86_64"}</pre>
        </div>

        <div class="endpoint">
            <span class="method get">GET</span><span class="path">/api/ping</span>
            <p><strong>Purpose:</strong> Simple ping-pong endpoint to verify responsiveness.</p>
            <p><strong>Response Example:</strong></p>
            <pre>{"ping": "pong"}</pre>
        </div>
    </body>
    </html>
    """
    return HTMLResponse(content=html_content, status_code=200)

@app.get("/api/version")
def version():
    """
    Returns application and Odoo version details.
    """
    return {"version": "19.0", "sdk": "docker"}

@app.get("/api/modules")
def modules():
    """
    Lists Odoo modules in this repository.
    """
    return ["base", "web", "crm", "website", "ecommerce", "inventory", "project"]

@app.get("/api/sysinfo")
def sysinfo():
    """
    Returns platform environment details.
    """
    return {
        "system": platform.system(),
        "release": platform.release(),
        "version": platform.version(),
        "machine": platform.machine(),
        "python_version": platform.python_version()
    }

@app.get("/api/ping")
def ping():
    """
    Simple ping-pong endpoint to verify responsiveness.
    """
    return {"ping": "pong"}