Cleanup of old code, moved Node class, many improvements on file handling

This commit is contained in:
Magnus Åhall 2026-06-29 10:43:21 +02:00
parent 65f8cd14a7
commit 16992db6b1
19 changed files with 485 additions and 3281 deletions

View file

@ -1,5 +1,5 @@
import { API } from 'api'
import { Node } from 'node'
import { Node } from 'node_store'
import { CustomHTMLElement } from './lib/custom_html_element.mjs'
export class Sync {
@ -169,18 +169,18 @@ export class Sync {
const BLOCKSIZE = 128 * 1024
let sentBytes = 0
const { file, metadata } = await nodeStore.nextFileToSync()
if (file === null)
const metadata = await nodeStore.nextFileToSync()
if (metadata === null)
return
const stream = file.stream()
const stream = await globalThis.nodeStore.fileSegments.getStream(metadata.UUID)
const reader = stream.getReader({ mode: 'byob' }) // Bring Your Own Buffer
let buffer = new Uint8Array(BLOCKSIZE)
while (true) {
const { value, done } = await reader.read(buffer)
await API.upload(metadata.UUID, value, sentBytes, file)
await API.upload(metadata.UUID, value, sentBytes, metadata)
metadata.setUploaded()
nodeStore.filesMetadata.add(metadata)
@ -189,6 +189,23 @@ export class Sync {
sentBytes += value.length
buffer = new Uint8Array(value.buffer)
}
reader.releaseLock()
} catch (e) {
console.error(e)
alert(e.message)
}
}// }}}
async filesFromServer() {// {{{
let offset = 0
let more = true
try {
while (more) {
const res = await API.query('GET', `/file/server_uuids/${offset}`)
more = res.MoreRowsExist
console.log(res)
}
} catch (e) {
console.error(e)
alert(e.message)