mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-26 07:11:00 -05:00
91 lines
2.6 KiB
Svelte
91 lines
2.6 KiB
Svelte
<script lang="ts">
|
|
import { getContext, onDestroy } from 'svelte';
|
|
import type { MachineTarget } from '$lib/apis/machines';
|
|
import { gitRequest, type GitFile } from '$lib/apis/machines/git';
|
|
import GitDiff from '../Tabs/GitDiff.svelte';
|
|
import Spinner from '../../common/Spinner.svelte';
|
|
|
|
export let target: MachineTarget | null;
|
|
|
|
export let root: string;
|
|
export let file: GitFile | null;
|
|
export let active = true;
|
|
export let mode: 'unified' | 'split' = 'unified';
|
|
export let hideWhitespace = false;
|
|
export let resourceVersion = 0;
|
|
const i18n = getContext<any>('i18n');
|
|
let diff = '';
|
|
let loading = false;
|
|
let error = '';
|
|
let generation = 0;
|
|
|
|
const load = async (
|
|
server: MachineTarget | null,
|
|
directory: string,
|
|
entry: GitFile | null,
|
|
enabled: boolean,
|
|
ignoreWhitespace: boolean,
|
|
_version: number
|
|
) => {
|
|
const current = ++generation;
|
|
if (!enabled || !server) return;
|
|
error = '';
|
|
if (!entry || entry.binary) {
|
|
diff = '';
|
|
loading = false;
|
|
return;
|
|
}
|
|
loading = true;
|
|
try {
|
|
const result = await gitRequest<{ diff: string }>(server, directory, 'diff', {
|
|
file: entry.path,
|
|
staged: String(entry.staged && !entry.unstaged),
|
|
untracked: String(entry.status === 'untracked'),
|
|
ignore_whitespace: String(ignoreWhitespace)
|
|
});
|
|
if (current === generation) diff = result.diff;
|
|
} catch (reason) {
|
|
if (current === generation) {
|
|
diff = '';
|
|
error = reason instanceof Error ? reason.message : String(reason);
|
|
}
|
|
} finally {
|
|
if (current === generation) loading = false;
|
|
}
|
|
};
|
|
$: void load(target, root, file, active, hideWhitespace, resourceVersion);
|
|
onDestroy(() => {
|
|
++generation;
|
|
});
|
|
</script>
|
|
|
|
<div
|
|
class="h-full min-h-0 overflow-auto scrollbar-hidden"
|
|
role="region"
|
|
aria-label={$i18n.t('File changes')}
|
|
aria-busy={loading}
|
|
>
|
|
{#if error}<div
|
|
role="alert"
|
|
class="flex h-full flex-col items-center justify-center gap-2 p-3 text-center text-xs text-base-500 dark:text-base-400"
|
|
>
|
|
{error}<button
|
|
class="underline"
|
|
on:click={() => load(target, root, file, active, hideWhitespace, resourceVersion)}
|
|
>{$i18n.t('Retry')}</button
|
|
>
|
|
</div>
|
|
{:else if loading && !diff}<div class="flex h-full items-center justify-center">
|
|
<Spinner className="size-4" />
|
|
</div>
|
|
{:else if file?.binary}<div
|
|
class="flex h-full items-center justify-center p-3 text-center text-xs text-base-400"
|
|
>
|
|
{$i18n.t('Binary file changed')}
|
|
</div>
|
|
{:else if diff}<GitDiff code={diff} {mode} {hideWhitespace} />
|
|
{:else}<div class="flex h-full items-center justify-center p-3 text-center text-xs text-base-400">
|
|
{$i18n.t('No changes')}
|
|
</div>{/if}
|
|
</div>
|