add README with usage and development instructions

This commit is contained in:
shum
2026-02-18 13:42:08 +00:00
parent c85050c685
commit eaa81dcc5d
+71 -17
View File
@@ -2,13 +2,67 @@
Browser-compatible XFTP file transfer client in TypeScript.
## Prerequisites
## Installation
```bash
npm install xftp-web
```
## Usage
```typescript
import {
newXFTPAgent, closeXFTPAgent,
parseXFTPServer,
encryptFileForUpload, uploadFile, downloadFile, deleteFile,
decodeDescriptionURI, encodeDescriptionURI,
XFTPRetriableError, XFTPPermanentError, isRetriable,
} from "xftp-web"
// Create agent (manages connections)
const agent = newXFTPAgent()
// Upload
const server = parseXFTPServer("xftp://...")
const encrypted = encryptFileForUpload(fileBytes, "photo.jpg")
const {rcvDescription, sndDescription, uri} = await uploadFile(agent, server, encrypted, {
onProgress: (uploaded, total) => console.log(`${uploaded}/${total}`),
})
// Download (from URI or FileDescription)
const fd = decodeDescriptionURI(uri)
const {header, content} = await downloadFile(agent, fd)
// Delete (using sender description)
await deleteFile(agent, sndDescription)
// Cleanup
closeXFTPAgent(agent)
```
### Error handling
```typescript
try {
await uploadFile(agent, server, encrypted)
} catch (e) {
if (e instanceof XFTPRetriableError) {
// Network/timeout/session errors — safe to retry
} else if (e instanceof XFTPPermanentError) {
// AUTH, NO_FILE, BLOCKED, etc. — do not retry
}
// or use: isRetriable(e)
}
```
## Development
### Prerequisites
- Haskell toolchain with `cabal` (to build `xftp-server`)
- Node.js 20+
- Chromium system dependencies (see below)
## Setup
### Setup
```bash
# Build the XFTP server binary (from repo root)
@@ -17,31 +71,31 @@ cabal build xftp-server
# Install JS dependencies
cd xftp-web
npm install
# Install Chromium for Playwright (browser tests)
npx playwright install chromium
```
If Chromium fails to launch due to missing system libraries, install them with:
### Running tests
```bash
npm run test
```
The `pretest` script automatically installs Chromium and sets up the libsodium symlink. The browser test starts an `xftp-server` instance on port 7000 via `globalSetup`.
If Chromium fails to launch due to missing system libraries:
```bash
# Requires root
npx playwright install-deps chromium
```
## Running tests
```bash
# Browser round-trip test (vitest + Playwright headless Chromium)
npm run test
```
The browser test automatically starts an `xftp-server` instance on port 7000 via `globalSetup`, using certs from `tests/fixtures/`.
## Build
### Build
```bash
npm run build
```
Output goes to `dist/`.
## License
[AGPL-3.0-only](https://www.gnu.org/licenses/agpl-3.0.html)