feat: add public config and health endpoints
This commit is contained in:
@@ -25,6 +25,47 @@ from core.settings import settings, BASE_DIR, DEFAULT_CONFIG
|
|||||||
from core.tasks import delete_expire_files, clean_incomplete_uploads
|
from core.tasks import delete_expire_files, clean_incomplete_uploads
|
||||||
from core.utils import hash_password, is_password_hashed
|
from core.utils import hash_password, is_password_hashed
|
||||||
|
|
||||||
|
APP_VERSION = "2.0.0-dev"
|
||||||
|
|
||||||
|
|
||||||
|
def build_public_config() -> dict:
|
||||||
|
return {
|
||||||
|
"name": settings.name,
|
||||||
|
"description": settings.description,
|
||||||
|
"explain": settings.page_explain,
|
||||||
|
"uploadSize": settings.uploadSize,
|
||||||
|
"expireStyle": settings.expireStyle,
|
||||||
|
"enableChunk": settings.enableChunk,
|
||||||
|
"openUpload": settings.openUpload,
|
||||||
|
"notify_title": settings.notify_title,
|
||||||
|
"notify_content": settings.notify_content,
|
||||||
|
"show_admin_address": settings.showAdminAddr,
|
||||||
|
"max_save_seconds": settings.max_save_seconds,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def build_public_meta() -> dict:
|
||||||
|
return {
|
||||||
|
"version": APP_VERSION,
|
||||||
|
"api": {
|
||||||
|
"legacyConfig": "/",
|
||||||
|
"publicConfig": "/api/v1/config",
|
||||||
|
"health": "/health",
|
||||||
|
},
|
||||||
|
"features": {
|
||||||
|
"chunkUpload": bool(settings.enableChunk),
|
||||||
|
"guestUpload": bool(settings.openUpload),
|
||||||
|
"adminAddressVisible": bool(settings.showAdminAddr),
|
||||||
|
"expirationModes": settings.expireStyle,
|
||||||
|
},
|
||||||
|
"limits": {
|
||||||
|
"uploadSize": settings.uploadSize,
|
||||||
|
"maxSaveSeconds": settings.max_save_seconds,
|
||||||
|
"uploadWindowMinutes": settings.uploadMinute,
|
||||||
|
"uploadWindowCount": settings.uploadCount,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def lifespan(app: FastAPI):
|
async def lifespan(app: FastAPI):
|
||||||
@@ -139,19 +180,27 @@ async def robots():
|
|||||||
|
|
||||||
@app.post("/")
|
@app.post("/")
|
||||||
async def get_config():
|
async def get_config():
|
||||||
|
return APIResponse(detail=build_public_config())
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/api/v1/config")
|
||||||
|
async def get_public_config():
|
||||||
return APIResponse(
|
return APIResponse(
|
||||||
detail={
|
detail={
|
||||||
"name": settings.name,
|
"config": build_public_config(),
|
||||||
"description": settings.description,
|
"meta": build_public_meta(),
|
||||||
"explain": settings.page_explain,
|
}
|
||||||
"uploadSize": settings.uploadSize,
|
)
|
||||||
"expireStyle": settings.expireStyle,
|
|
||||||
"enableChunk": settings.enableChunk,
|
|
||||||
"openUpload": settings.openUpload,
|
@app.get("/health")
|
||||||
"notify_title": settings.notify_title,
|
async def health_check():
|
||||||
"notify_content": settings.notify_content,
|
return APIResponse(
|
||||||
"show_admin_address": settings.showAdminAddr,
|
detail={
|
||||||
"max_save_seconds": settings.max_save_seconds,
|
"status": "ok",
|
||||||
|
"version": APP_VERSION,
|
||||||
|
"storage": settings.file_storage,
|
||||||
|
"theme": settings.themesSelect,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user