mirror of
https://github.com/open-webui/open-webui
synced 2024-11-22 08:07:55 +00:00
feat: check for updates
This commit is contained in:
parent
6bfe2a6306
commit
759883a4c8
@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [0.1.104] - UNRELEASED
|
||||
|
||||
### Added
|
||||
|
||||
- Check for updates in Settings > About.
|
||||
|
||||
## [0.1.103] - 2024-02-25
|
||||
|
||||
### Added
|
||||
|
@ -47,3 +47,4 @@ class ERROR_MESSAGES(str, Enum):
|
||||
INCORRECT_FORMAT = (
|
||||
lambda err="": f"Invalid format. Please use the correct format{err if err else ''}"
|
||||
)
|
||||
RATE_LIMIT_EXCEEDED = "API rate limit exceeded"
|
||||
|
@ -139,15 +139,11 @@ async def get_app_latest_release_version():
|
||||
response.raise_for_status()
|
||||
latest_version = response.json()["tag_name"]
|
||||
|
||||
# Compare versions
|
||||
return {
|
||||
"current": VERSION,
|
||||
"latest": latest_version[1:],
|
||||
}
|
||||
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,
|
||||
detail=ERROR_MESSAGES.RATE_LIMIT_EXCEEDED,
|
||||
)
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "open-webui",
|
||||
"version": "0.1.103",
|
||||
"version": "0.1.104",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite dev --host",
|
||||
|
@ -19,6 +19,10 @@ export const getBackendConfig = async () => {
|
||||
return null;
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
@ -41,5 +45,35 @@ export const getChangelog = async () => {
|
||||
return null;
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
export const getVersionUpdates = async () => {
|
||||
let error = null;
|
||||
|
||||
const res = await fetch(`${WEBUI_BASE_URL}/api/version/updates`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (!res.ok) throw await res.json();
|
||||
return res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
error = err;
|
||||
return null;
|
||||
});
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
@ -1,14 +1,39 @@
|
||||
<script lang="ts">
|
||||
import { getVersionUpdates } from '$lib/apis';
|
||||
import { getOllamaVersion } from '$lib/apis/ollama';
|
||||
import { WEBUI_VERSION } from '$lib/constants';
|
||||
import { WEBUI_NAME, config, showChangelog } from '$lib/stores';
|
||||
import { compareVersion } from '$lib/utils';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let ollamaVersion = '';
|
||||
|
||||
let updateAvailable = false;
|
||||
let version = {
|
||||
current: '',
|
||||
latest: ''
|
||||
};
|
||||
|
||||
const checkForVersionUpdates = async () => {
|
||||
version = await getVersionUpdates(localStorage.token).catch((error) => {
|
||||
return {
|
||||
current: WEBUI_VERSION,
|
||||
latest: WEBUI_VERSION
|
||||
};
|
||||
});
|
||||
|
||||
console.log(version);
|
||||
|
||||
updateAvailable = compareVersion(version.latest, version.current);
|
||||
console.log(updateAvailable);
|
||||
};
|
||||
|
||||
onMount(async () => {
|
||||
ollamaVersion = await getOllamaVersion(localStorage.token).catch((error) => {
|
||||
return '';
|
||||
});
|
||||
|
||||
checkForVersionUpdates();
|
||||
});
|
||||
</script>
|
||||
|
||||
@ -20,10 +45,17 @@
|
||||
{$WEBUI_NAME} Version
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex w-full">
|
||||
<div class="flex-1 text-xs text-gray-700 dark:text-gray-200 flex space-x-1.5 items-center">
|
||||
<div class="flex w-full justify-between items-center">
|
||||
<div class="flex flex-col text-xs text-gray-700 dark:text-gray-200">
|
||||
<div>
|
||||
v{WEBUI_VERSION}
|
||||
|
||||
<a
|
||||
href="https://github.com/open-webui/open-webui/releases/tag/v{version.latest}"
|
||||
target="_blank"
|
||||
>
|
||||
{updateAvailable ? `(v${version.latest} available!)` : '(latest)'}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<button
|
||||
@ -35,6 +67,15 @@
|
||||
<div>See what's new</div>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button
|
||||
class=" text-xs px-3 py-1.5 bg-gray-100 hover:bg-gray-200 dark:bg-gray-850 dark:hover:bg-gray-800 transition rounded-lg font-medium"
|
||||
on:click={() => {
|
||||
checkForVersionUpdates();
|
||||
}}
|
||||
>
|
||||
Check for updates
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -101,11 +101,10 @@ export const copyToClipboard = (text) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const checkVersion = (required, current) => {
|
||||
// Returns true when current version is below required
|
||||
export const compareVersion = (latest, current) => {
|
||||
return current === '0.0.0'
|
||||
? false
|
||||
: current.localeCompare(required, undefined, {
|
||||
: current.localeCompare(latest, undefined, {
|
||||
numeric: true,
|
||||
sensitivity: 'case',
|
||||
caseFirst: 'upper'
|
||||
|
@ -28,7 +28,7 @@
|
||||
config
|
||||
} from '$lib/stores';
|
||||
import { REQUIRED_OLLAMA_VERSION, WEBUI_API_BASE_URL } from '$lib/constants';
|
||||
import { checkVersion } from '$lib/utils';
|
||||
import { compareVersion } from '$lib/utils';
|
||||
|
||||
import SettingsModal from '$lib/components/chat/SettingsModal.svelte';
|
||||
import Sidebar from '$lib/components/layout/Sidebar.svelte';
|
||||
@ -79,7 +79,7 @@
|
||||
ollamaVersion = version;
|
||||
|
||||
console.log(ollamaVersion);
|
||||
if (checkVersion(REQUIRED_OLLAMA_VERSION, ollamaVersion)) {
|
||||
if (compareVersion(REQUIRED_OLLAMA_VERSION, ollamaVersion)) {
|
||||
toast.error(`Ollama Version: ${ollamaVersion !== '' ? ollamaVersion : 'Not Detected'}`);
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user