File size: 1,890 Bytes
075be5d
 
8d0e117
075be5d
0914da1
 
 
 
075be5d
 
 
73f1392
b5430db
075be5d
b5430db
0914da1
 
 
 
 
 
 
 
 
 
 
 
8d0e117
b5430db
 
 
 
73f1392
075be5d
8d0e117
 
075be5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8d0e117
 
 
 
 
075be5d
b5430db
 
 
 
0914da1
 
 
 
 
 
 
 
 
 
 
075be5d
 
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
<script lang="ts">
	import { checkDduf } from '$lib/check-dduf';
	import { tick } from 'svelte';

	let url = $state('https://huggingface.co/spaces/coyotte508/dduf-check/resolve/main/file.dduf');
	let output = $state('');
	let error = $state('');
	let files: Array<{ position: number; size: number; name: string }> = $state([]);

	async function handleSubmit(event: Event) {
		event.preventDefault();
		output = 'Checking...';
		error = '';

		try {
			for await (const file of checkDduf(url, {
				log: (s) => {
					output += '\n' + s;
					tick().then(() => {
						textarea.scrollTop = textarea.scrollHeight;
					});
				}
			})) {
				files.push({
					position: file.fileHeaderOffset,
					size: file.size,
					name: file.name
				});
			}
		} catch (e) {
			console.error(e);
			error = (e as Error).message;
		}
	}

	let textarea: HTMLTextAreaElement;
</script>

<div class="flex flex-col gap-4 p-4">
	<h1 class="text-xl font-bold">DDUF Check</h1>

	<form class="flex flex-col gap-4" onsubmit={handleSubmit}>
		<label class="flex flex-col gap-2">
			DDUF URL (resolved url)
			<input
				type="url"
				name="url"
				placeholder="https://huggingface.co/name/repo/main/resolve/file.dduf"
				bind:value={url}
				class="w-full rounded-md border border-gray-300 p-2"
			/>
		</label>

		<button type="submit" class="self-start rounded-md bg-blue-500 p-2 text-white">Check</button>

		<textarea
			bind:this={textarea}
			class="w-full rounded-md border border-gray-300 p-2"
			rows="10"
			readonly>{output}</textarea
		>

		{#if error}
			<p class="text-red-500">{error}</p>
		{/if}

		{#if files.length > 0}
			<h2 class="text-lg font-bold">Files</h2>
			<ul class="ml-4 list-disc">
				{#each files as file}
					<li style="margin-left: {file.name.slice(0, -1).split('/').length - 1}rem">
						{file.name} - {file.size} B
					</li>
				{/each}
			</ul>
		{/if}
	</form>
</div>