From 4cb02da415f058ace3c1445bcbd5c182c8a9b94a Mon Sep 17 00:00:00 2001 From: Alex Kern Date: Mon, 9 Sep 2024 17:15:01 -0700 Subject: [PATCH] checkpoint --- src/hooks/useUploaderConnections.ts | 17 ++++++++++++++++- src/utils/fs.ts | 17 ----------------- 2 files changed, 16 insertions(+), 18 deletions(-) delete mode 100644 src/utils/fs.ts diff --git a/src/hooks/useUploaderConnections.ts b/src/hooks/useUploaderConnections.ts index eaf7c30..c719018 100644 --- a/src/hooks/useUploaderConnections.ts +++ b/src/hooks/useUploaderConnections.ts @@ -6,12 +6,27 @@ import { UploaderConnectionStatus, } from '../types' import { decodeMessage, Message, MessageType } from '../messages' -import { validateOffset } from '../utils/fs' import * as t from 'io-ts' // TODO(@kern): Test for better values const MAX_CHUNK_SIZE = 10 * 1024 * 1024 // 10 Mi +function validateOffset( + files: UploadedFile[], + fullPath: string, + offset: number, +): UploadedFile { + const validFile = files.find( + (file) => + (file.fullPath === fullPath || file.name === fullPath) && + offset <= file.size, + ) + if (!validFile) { + throw new Error('invalid file offset') + } + return validFile +} + export function useUploaderConnections( peer: Peer, files: UploadedFile[], diff --git a/src/utils/fs.ts b/src/utils/fs.ts deleted file mode 100644 index 5479f5a..0000000 --- a/src/utils/fs.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { UploadedFile } from '../types' - -export function validateOffset( - files: UploadedFile[], - fullPath: string, - offset: number, -): UploadedFile { - const validFile = files.find( - (file) => - (file.fullPath === fullPath || file.name === fullPath) && - offset <= file.size, - ) - if (!validFile) { - throw new Error('invalid file offset') - } - return validFile -}