mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-05-10 19:16:57 +00:00
add README with usage and development instructions
This commit is contained in:
+71
-17
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user