From 6bfe2a6306478ff86368557e9cfc5794329d1b22 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 25 Feb 2024 11:26:58 -0800 Subject: [PATCH] feat: latest release check api --- backend/main.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/backend/main.py b/backend/main.py index a432e9ed..3f971d39 100644 --- a/backend/main.py +++ b/backend/main.py @@ -4,8 +4,9 @@ import markdown import time import os import sys +import requests -from fastapi import FastAPI, Request, Depends +from fastapi import FastAPI, Request, Depends, status from fastapi.staticfiles import StaticFiles from fastapi import HTTPException from fastapi.responses import JSONResponse @@ -26,6 +27,8 @@ from apps.web.main import app as webui_app from config import WEBUI_NAME, ENV, VERSION, CHANGELOG, FRONTEND_BUILD_DIR +from constants import ERROR_MESSAGES + from utils.utils import get_http_authorization_cred, get_current_user @@ -127,6 +130,27 @@ async def get_app_changelog(): return CHANGELOG +@app.get("/api/version/updates") +async def get_app_latest_release_version(): + try: + response = requests.get( + f"https://api.github.com/repos/open-webui/open-webui/releases/latest" + ) + response.raise_for_status() + latest_version = response.json()["tag_name"] + + # Compare versions + return { + "current": VERSION, + "latest": latest_version[1:], + } + except Exception as e: + raise HTTPException( + status_code=status.HTTP_503_SERVICE_UNAVAILABLE, + detail=ERROR_MESSAGES.NOT_FOUND, + ) + + app.mount("/static", StaticFiles(directory="static"), name="static")