File sync

This commit is contained in:
Magnus Åhall 2026-07-10 06:32:31 +02:00
parent b76502c034
commit 47c4c99b66
7 changed files with 174 additions and 19 deletions

View file

@ -566,21 +566,32 @@ export class NodeStore {
})
}//}}}
async storeFile(file) {// {{{
async storeFile(file, reader, progressCallback) {// {{{
const metadata = new FileMetadata(file)
let processedBytes = 0
let stream
try {
// Do potentially larger blocks.
const BLOCKSIZE = 1048576
const stream = file.stream()
const reader = stream.getReader({ mode: 'byob' })
let buffer = new Uint8Array(BLOCKSIZE)
// Files from server got through fetch() will bring its own
// reader without going through a stream.
if (!reader) {
stream = file.stream()
reader = stream.getReader({ mode: 'byob' })
}
let seq = 0
while (true) {
const { done, value } = await reader.read(buffer)
if (done) break
processedBytes += value.length
if (progressCallback)
progressCallback(processedBytes)
// Block is added as a file segment.
await this.fileSegments.add({
data: {
@ -895,7 +906,6 @@ class FileNodesLinkStore extends SimpleNodeStore {
class FileMetadata {
constructor(data) {// {{{
console.log('md', data)
this.UUID = data.UUID || uuidv7()
this.uploaded = data.uploaded || 'only_on_device'