create-sia-app 0.1.12 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
2
|
-
import { PinnedObject, type ShardProgress } from 'sia-storage'
|
|
3
|
-
import { APP_KEY } from '../../lib/constants'
|
|
2
|
+
import { encodedSize, PinnedObject, type ShardProgress } from 'sia-storage'
|
|
3
|
+
import { APP_KEY, DATA_SHARDS, PARITY_SHARDS } from '../../lib/constants'
|
|
4
4
|
import { useAuthStore } from '../../stores/auth'
|
|
5
5
|
import { DevNote } from '../DevNote'
|
|
6
6
|
|
|
@@ -37,9 +37,10 @@ type UploadedFile = {
|
|
|
37
37
|
|
|
38
38
|
type UploadProgress = {
|
|
39
39
|
fileName: string
|
|
40
|
+
fileSize: number
|
|
40
41
|
shardsDone: number
|
|
41
42
|
bytesUploaded: number
|
|
42
|
-
|
|
43
|
+
encodedTotal: number
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
type DownloadProgress = {
|
|
@@ -88,11 +89,13 @@ export function UploadZone() {
|
|
|
88
89
|
if (!sdk) return
|
|
89
90
|
setUploading(true)
|
|
90
91
|
setError(null)
|
|
92
|
+
const encodedTotal = encodedSize(file.size, DATA_SHARDS, PARITY_SHARDS)
|
|
91
93
|
setActiveUpload({
|
|
92
94
|
fileName: file.name,
|
|
95
|
+
fileSize: file.size,
|
|
93
96
|
shardsDone: 0,
|
|
94
97
|
bytesUploaded: 0,
|
|
95
|
-
|
|
98
|
+
encodedTotal,
|
|
96
99
|
})
|
|
97
100
|
|
|
98
101
|
try {
|
|
@@ -107,14 +110,17 @@ export function UploadZone() {
|
|
|
107
110
|
let bytesUploaded = 0
|
|
108
111
|
const pinnedObject = await sdk.upload(object, file.stream(), {
|
|
109
112
|
maxInflight: 10,
|
|
113
|
+
dataShards: DATA_SHARDS,
|
|
114
|
+
parityShards: PARITY_SHARDS,
|
|
110
115
|
onShardUploaded: (progress: ShardProgress) => {
|
|
111
116
|
shardsDone++
|
|
112
117
|
bytesUploaded += progress.shardSize
|
|
113
118
|
setActiveUpload({
|
|
114
119
|
fileName: file.name,
|
|
120
|
+
fileSize: file.size,
|
|
115
121
|
shardsDone,
|
|
116
122
|
bytesUploaded,
|
|
117
|
-
|
|
123
|
+
encodedTotal,
|
|
118
124
|
})
|
|
119
125
|
},
|
|
120
126
|
})
|
|
@@ -215,7 +221,7 @@ export function UploadZone() {
|
|
|
215
221
|
? Math.min(
|
|
216
222
|
100,
|
|
217
223
|
Math.round(
|
|
218
|
-
(activeUpload.bytesUploaded / activeUpload.
|
|
224
|
+
(activeUpload.bytesUploaded / activeUpload.encodedTotal) * 100,
|
|
219
225
|
),
|
|
220
226
|
)
|
|
221
227
|
: 0
|
|
@@ -296,7 +302,10 @@ export function UploadZone() {
|
|
|
296
302
|
<div className="space-y-4">
|
|
297
303
|
<p className="text-neutral-300 text-sm">
|
|
298
304
|
Uploading{' '}
|
|
299
|
-
<span className="text-white">{activeUpload.fileName}</span>
|
|
305
|
+
<span className="text-white">{activeUpload.fileName}</span>{' '}
|
|
306
|
+
<span className="text-neutral-500">
|
|
307
|
+
({formatBytes(activeUpload.fileSize)})
|
|
308
|
+
</span>
|
|
300
309
|
</p>
|
|
301
310
|
<div className="w-full max-w-xs mx-auto bg-neutral-800 rounded-full h-1.5 overflow-hidden">
|
|
302
311
|
{activeUpload.shardsDone === 0 ? (
|
|
@@ -310,8 +319,11 @@ export function UploadZone() {
|
|
|
310
319
|
</div>
|
|
311
320
|
<p className="text-neutral-600 text-xs font-mono">
|
|
312
321
|
{activeUpload.shardsDone} shards ·{' '}
|
|
313
|
-
{formatBytes(
|
|
314
|
-
|
|
322
|
+
{formatBytes(
|
|
323
|
+
(activeUpload.bytesUploaded / activeUpload.encodedTotal) *
|
|
324
|
+
activeUpload.fileSize,
|
|
325
|
+
)}{' '}
|
|
326
|
+
/ {formatBytes(activeUpload.fileSize)}
|
|
315
327
|
</p>
|
|
316
328
|
</div>
|
|
317
329
|
) : (
|
package/template/vite.config.ts
CHANGED
|
@@ -4,4 +4,7 @@ import { defineConfig } from 'vite'
|
|
|
4
4
|
|
|
5
5
|
export default defineConfig({
|
|
6
6
|
plugins: [react(), tailwindcss()],
|
|
7
|
+
// sia-storage loads its WASM via `new URL(..., import.meta.url)`; excluding
|
|
8
|
+
// it from the deps pre-bundler keeps that URL pointing at the real file.
|
|
9
|
+
optimizeDeps: { exclude: ['sia-storage'] },
|
|
7
10
|
})
|