sfiledl 2.2.3 → 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cli.mjs +1281 -0
- package/build/cli.mjs.map +1 -0
- package/build/lib.cjs +2 -969
- package/build/lib.cjs.map +1 -1
- package/build/lib.mjs +2 -919
- package/build/lib.mjs.map +1 -1
- package/build/licenses.txt +1 -0
- package/package.json +52 -15
- package/readme.md +206 -76
package/readme.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
# sfiledl
|
|
2
2
|
|
|
3
|
-
> Automate file downloads from [sfile.co](https://sfile.co
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
> **Automate file downloads from [sfile.co](https://sfile.co) — reliable, retry‑aware, and fully typed.**
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://www.npmjs.com/package/sfiledl"><img src="https://img.shields.io/npm/v/sfiledl.svg?style=flat-square&logo=npm" alt="npm version"></a>
|
|
7
|
+
<a href="https://www.npmjs.com/package/sfiledl"><img src="https://img.shields.io/npm/dm/sfiledl?style=flat-square&logo=npm" alt="npm downloads"></a>
|
|
8
|
+
<a href="https://github.com/neuxdotdev/sfiledl/blob/main/license"><img src="https://img.shields.io/github/license/neuxdotdev/sfiledl?style=flat-square" alt="license"></a>
|
|
9
|
+
<a href="https://github.com/neuxdotdev/sfiledl/actions"><img src="https://img.shields.io/github/actions/workflow/status/neuxdotdev/sfiledl/build.yml?branch=main&style=flat-square&logo=github" alt="build"></a>
|
|
10
|
+
<a href="https://www.typescriptlang.org"><img src="https://img.shields.io/badge/TypeScript-6.0-blue?style=flat-square&logo=typescript" alt="TypeScript"></a>
|
|
11
|
+
<a href="https://playwright.dev"><img src="https://img.shields.io/badge/Playwright-1.59-green?style=flat-square&logo=playwright" alt="Playwright"></a>
|
|
12
|
+
<a href="https://bun.sh"><img src="https://img.shields.io/badge/Bun-1.3+-black?style=flat-square&logo=bun" alt="Bun"></a>
|
|
13
|
+
<a href="https://nodejs.org"><img src="https://img.shields.io/badge/Node-%3E%3D18-green?style=flat-square&logo=node.js" alt="Node"></a>
|
|
14
|
+
<a href="https://prettier.io"><img src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square&logo=prettier" alt="code style"></a>
|
|
15
|
+
<a href="http://makeapullrequest.com"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square" alt="PRs welcome"></a>
|
|
16
|
+
</p>
|
|
17
17
|
|
|
18
18
|
---
|
|
19
19
|
|
|
@@ -21,12 +21,15 @@
|
|
|
21
21
|
|
|
22
22
|
- [Installation](#installation)
|
|
23
23
|
- [Quick Start](#quick-start)
|
|
24
|
-
- [
|
|
25
|
-
- [
|
|
26
|
-
- [
|
|
27
|
-
|
|
28
|
-
- [
|
|
29
|
-
- [
|
|
24
|
+
- [CLI Usage](#cli-usage)
|
|
25
|
+
- [Command Line Options](#command-line-options)
|
|
26
|
+
- [Configuration File](#configuration-file)
|
|
27
|
+
- [Library API](#library-api)
|
|
28
|
+
- [`downloadSfile`](#downloadsfile)
|
|
29
|
+
- [`downloadSfileSafe`](#downloadsfilesafe)
|
|
30
|
+
- [`createDownloader`](#createdownloader)
|
|
31
|
+
- [`DownloadOptions`](#downloadoptions)
|
|
32
|
+
- [`DownloadResult`](#downloadresult)
|
|
30
33
|
- [Error Handling](#error-handling)
|
|
31
34
|
- [Error Types](#error-types)
|
|
32
35
|
- [Retryable Errors](#retryable-errors)
|
|
@@ -38,7 +41,6 @@
|
|
|
38
41
|
- [Scripts](#scripts)
|
|
39
42
|
- [Contributing](#contributing)
|
|
40
43
|
- [License](#license)
|
|
41
|
-
>>>>>>> 91ae467 (docs: imrpoving documentation)
|
|
42
44
|
|
|
43
45
|
---
|
|
44
46
|
|
|
@@ -51,16 +53,18 @@ bun add sfiledl
|
|
|
51
53
|
# Using npm
|
|
52
54
|
npm install sfiledl
|
|
53
55
|
|
|
54
|
-
# Install Playwright browser (required)
|
|
56
|
+
# Install Playwright browser (required once)
|
|
55
57
|
bunx playwright install chromium # or npx playwright install chromium
|
|
56
58
|
```
|
|
57
59
|
|
|
58
|
-
**Prerequisites:** Node.js >=
|
|
60
|
+
**Prerequisites:** Node.js >=18 or Bun >=1.3.
|
|
59
61
|
|
|
60
62
|
---
|
|
61
63
|
|
|
62
64
|
## Quick Start
|
|
63
65
|
|
|
66
|
+
### As a library
|
|
67
|
+
|
|
64
68
|
```typescript
|
|
65
69
|
import { downloadSfile } from 'sfiledl'
|
|
66
70
|
|
|
@@ -77,25 +81,122 @@ console.log(result)
|
|
|
77
81
|
// }
|
|
78
82
|
```
|
|
79
83
|
|
|
84
|
+
### As a CLI tool
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# Basic usage
|
|
88
|
+
sfiledl https://sfile.co/abc123
|
|
89
|
+
|
|
90
|
+
# Specify output directory
|
|
91
|
+
sfiledl https://sfile.co/abc123 -o ~/Downloads
|
|
92
|
+
|
|
93
|
+
# Show browser window and enable debug
|
|
94
|
+
sfiledl https://sfile.co/abc123 --headed --debug
|
|
95
|
+
|
|
96
|
+
# Adjust retries and delays
|
|
97
|
+
sfiledl https://sfile.co/abc123 -r 5 -d 2000
|
|
98
|
+
|
|
99
|
+
# See help
|
|
100
|
+
sfiledl --help
|
|
101
|
+
```
|
|
102
|
+
|
|
80
103
|
---
|
|
81
104
|
|
|
82
|
-
##
|
|
105
|
+
## CLI Usage
|
|
106
|
+
|
|
107
|
+
The CLI provides a fully featured interface to the downloader.
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
sfiledl [options] <url>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Command Line Options
|
|
114
|
+
|
|
115
|
+
| Option | Alias | Type | Default | Description |
|
|
116
|
+
| -------------------------- | ----- | -------- | ----------------- | -------------------------------------- |
|
|
117
|
+
| `<url>` | – | required | – | sfile.co download URL |
|
|
118
|
+
| `--output <dir>` | `-o` | string | `./downloads` | Save directory |
|
|
119
|
+
| `--headed` | – | boolean | `false` | Show browser window (disable headless) |
|
|
120
|
+
| `--timeout <ms>` | `-t` | number | `60000` | Navigation timeout (ms, ≥1000) |
|
|
121
|
+
| `--button-timeout <ms>` | – | number | `30000` | Download button wait timeout (ms) |
|
|
122
|
+
| `--retries <n>` | `-r` | number | `3` | Maximum retry attempts |
|
|
123
|
+
| `--retry-delay <ms>` | `-d` | number | `1000` | Base retry delay (exponential backoff) |
|
|
124
|
+
| `--debug` | – | boolean | `false` | Enable debug logs and artifacts |
|
|
125
|
+
| `--ua, --user-agent <str>` | – | string | Chrome on Windows | Custom User‑Agent header |
|
|
126
|
+
| `--no-progress` | – | boolean | `false` | Disable progress spinner |
|
|
127
|
+
| `--log-file <path>` | – | string | – | Write structured logs to file |
|
|
128
|
+
| `--no-artifacts` | – | boolean | `true` | Skip saving debug artifacts on error |
|
|
129
|
+
| `-v, --version` | – | – | – | Show version |
|
|
130
|
+
| `-h, --help` | – | – | – | Show help |
|
|
131
|
+
|
|
132
|
+
### Configuration File
|
|
133
|
+
|
|
134
|
+
You can set default options using a JSON configuration file in the current working directory.
|
|
135
|
+
Supported files: `.sfiledlrc.json` or `.sfiledlrc` (`.json` takes precedence).
|
|
136
|
+
|
|
137
|
+
Example `.sfiledlrc.json`:
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"output": "./downloads",
|
|
142
|
+
"retries": 5,
|
|
143
|
+
"debug": true,
|
|
144
|
+
"headless": false,
|
|
145
|
+
"timeout": 120000,
|
|
146
|
+
"userAgent": "MyCustomAgent/1.0"
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
CLI options always override file configuration.
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Library API
|
|
155
|
+
|
|
156
|
+
The library exports several functions and types for programmatic usage.
|
|
157
|
+
|
|
158
|
+
### `downloadSfile`
|
|
159
|
+
|
|
160
|
+
Main download function. Throws errors on failure.
|
|
83
161
|
|
|
84
|
-
|
|
162
|
+
```typescript
|
|
163
|
+
function downloadSfile(
|
|
164
|
+
url: string,
|
|
165
|
+
saveDir: string,
|
|
166
|
+
options?: DownloadOptions,
|
|
167
|
+
): Promise<DownloadResult>
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**Example:**
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { downloadSfile } from 'sfiledl'
|
|
85
174
|
|
|
86
|
-
|
|
175
|
+
try {
|
|
176
|
+
const result = await downloadSfile('https://sfile.co/file/xyz', './out', {
|
|
177
|
+
headless: true,
|
|
178
|
+
retries: 2,
|
|
179
|
+
onProgress: (percent) => console.log(`${percent}%`),
|
|
180
|
+
})
|
|
181
|
+
console.log('Downloaded:', result.filePath)
|
|
182
|
+
} catch (err) {
|
|
183
|
+
console.error('Failed:', err.message)
|
|
184
|
+
}
|
|
185
|
+
```
|
|
87
186
|
|
|
88
|
-
|
|
89
|
-
| --------- | ----------------- | -------------------------------------- |
|
|
90
|
-
| `url` | `string` | sfile.co URL (must contain the domain) |
|
|
91
|
-
| `saveDir` | `string` | Directory where the file will be saved |
|
|
92
|
-
| `options` | `DownloadOptions` | Optional configuration |
|
|
187
|
+
### `downloadSfileSafe`
|
|
93
188
|
|
|
94
|
-
|
|
189
|
+
Same as `downloadSfile` but never throws – returns a `Result` object.
|
|
95
190
|
|
|
96
|
-
|
|
191
|
+
```typescript
|
|
192
|
+
function downloadSfileSafe(
|
|
193
|
+
url: string,
|
|
194
|
+
saveDir: string,
|
|
195
|
+
options?: DownloadOptions,
|
|
196
|
+
): Promise<Result<DownloadResult, Error>>
|
|
197
|
+
```
|
|
97
198
|
|
|
98
|
-
|
|
199
|
+
**Example:**
|
|
99
200
|
|
|
100
201
|
```typescript
|
|
101
202
|
import { downloadSfileSafe, isSuccess } from 'sfiledl'
|
|
@@ -108,19 +209,30 @@ if (isSuccess(res)) {
|
|
|
108
209
|
}
|
|
109
210
|
```
|
|
110
211
|
|
|
111
|
-
### `createDownloader
|
|
212
|
+
### `createDownloader`
|
|
112
213
|
|
|
113
214
|
Creates a reusable downloader with preset options.
|
|
114
215
|
|
|
115
216
|
```typescript
|
|
116
|
-
|
|
117
|
-
|
|
217
|
+
function createDownloader(defaultOptions?: DownloadOptions): {
|
|
218
|
+
download: (url: string, saveDir: string, options?: DownloadOptions) => Promise<DownloadResult>
|
|
219
|
+
downloadSafe: (
|
|
220
|
+
url: string,
|
|
221
|
+
saveDir: string,
|
|
222
|
+
options?: DownloadOptions,
|
|
223
|
+
) => Promise<Result<DownloadResult, Error>>
|
|
224
|
+
withOptions: (newDefaults: Partial<DownloadOptions>) => ReturnType<typeof createDownloader>
|
|
225
|
+
}
|
|
226
|
+
```
|
|
118
227
|
|
|
119
|
-
|
|
120
|
-
|
|
228
|
+
**Example:**
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
const dl = createDownloader({ headless: false, debug: true })
|
|
232
|
+
const result = await dl.download('https://sfile.co/file/abc', './downloads')
|
|
121
233
|
|
|
122
|
-
// chain new defaults
|
|
123
234
|
const quietDl = dl.withOptions({ debug: false })
|
|
235
|
+
await quietDl.download('https://sfile.co/file/xyz', './downloads')
|
|
124
236
|
```
|
|
125
237
|
|
|
126
238
|
### `DownloadOptions`
|
|
@@ -156,7 +268,7 @@ All options are optional.
|
|
|
156
268
|
|
|
157
269
|
## Error Handling
|
|
158
270
|
|
|
159
|
-
All errors extend `AppError` and include:
|
|
271
|
+
All errors thrown by the library extend `AppError` and include:
|
|
160
272
|
|
|
161
273
|
- `code` – unique string identifier
|
|
162
274
|
- `retryable` – `true` for network/browser issues, `false` for validation/file errors
|
|
@@ -206,6 +318,8 @@ Set `debug: true` in options to enable:
|
|
|
206
318
|
await downloadSfile(url, './out', { debug: true, saveDebugArtifacts: true })
|
|
207
319
|
```
|
|
208
320
|
|
|
321
|
+
In the CLI, use `--debug` and `--no-artifacts` to control behavior.
|
|
322
|
+
|
|
209
323
|
---
|
|
210
324
|
|
|
211
325
|
## Logging & Correlation
|
|
@@ -258,53 +372,65 @@ cd sfiledl
|
|
|
258
372
|
bun install
|
|
259
373
|
bunx playwright install chromium
|
|
260
374
|
|
|
261
|
-
# Full rebuild (clean, typecheck,
|
|
375
|
+
# Full rebuild (clean, typecheck, bundle, format)
|
|
262
376
|
bun run rebuild
|
|
263
377
|
|
|
264
|
-
# Run tests
|
|
378
|
+
# Run tests
|
|
265
379
|
bun run test
|
|
380
|
+
|
|
381
|
+
# Build only library (CJS, ESM, types)
|
|
382
|
+
bun run build:lib
|
|
383
|
+
|
|
384
|
+
# Build only CLI bundle
|
|
385
|
+
bun run build:cli
|
|
386
|
+
|
|
387
|
+
# Build everything (library + CLI)
|
|
388
|
+
bun run build:all
|
|
266
389
|
```
|
|
267
390
|
|
|
268
391
|
### Project Structure
|
|
269
392
|
|
|
270
393
|
```
|
|
271
394
|
.
|
|
272
|
-
├──
|
|
273
|
-
│ ├──
|
|
274
|
-
│
|
|
275
|
-
│
|
|
276
|
-
│ ├──
|
|
277
|
-
│
|
|
278
|
-
│
|
|
279
|
-
|
|
280
|
-
│
|
|
281
|
-
│
|
|
282
|
-
│ ├──
|
|
283
|
-
│
|
|
284
|
-
│
|
|
285
|
-
│
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
│ │ └── result.ts
|
|
290
|
-
│ └── lib.ts
|
|
291
|
-
├── build # generated output (CJS, ESM, types)
|
|
395
|
+
├── cli/ # CLI entry point and utilities
|
|
396
|
+
│ ├── cmd.ts # Commander setup and action
|
|
397
|
+
│ ├── config.ts # Config file loading + CLI/merge logic
|
|
398
|
+
│ ├── error.ts # Exit codes and pretty error formatting
|
|
399
|
+
│ ├── logger.ts # File logger for CLI
|
|
400
|
+
│ ├── main.ts # Entry shim
|
|
401
|
+
│ └── ui.ts # Spinner, result printing, formatting
|
|
402
|
+
├── lib/ # Core library
|
|
403
|
+
│ ├── browser/ # Playwright management & page interactions
|
|
404
|
+
│ ├── config/ # Defaults and schema validation
|
|
405
|
+
│ ├── core/ # Downloader logic & input validation
|
|
406
|
+
│ ├── errors/ # Custom error classes and guards
|
|
407
|
+
│ ├── utils/ # Helpers, logger, Result type
|
|
408
|
+
│ └── lib.ts # Public API barrel export
|
|
409
|
+
├── build/ # Generated output (CJS, ESM, types, CLI bundle)
|
|
410
|
+
├── scripts/ # Build helper scripts
|
|
411
|
+
├── docs/ # Documentation site (docsify)
|
|
292
412
|
├── package.json
|
|
293
|
-
|
|
413
|
+
├── tsconfig.json
|
|
414
|
+
└── rollup.config.mjs
|
|
294
415
|
```
|
|
295
416
|
|
|
296
417
|
### Scripts
|
|
297
418
|
|
|
298
|
-
| Command
|
|
299
|
-
|
|
|
300
|
-
| `bun run clean`
|
|
301
|
-
| `bun run typecheck`
|
|
302
|
-
| `bun run
|
|
303
|
-
| `bun run
|
|
304
|
-
| `bun run build`
|
|
305
|
-
| `bun run
|
|
306
|
-
| `bun run
|
|
307
|
-
| `bun run
|
|
419
|
+
| Command | Description |
|
|
420
|
+
| ------------------------ | ----------------------------------------------------------- |
|
|
421
|
+
| `bun run clean` | Remove `build/` and cache |
|
|
422
|
+
| `bun run typecheck` | Run `tsc --noEmit` |
|
|
423
|
+
| `bun run format` | Format all files with Prettier |
|
|
424
|
+
| `bun run clean-code` | Run `rmcm` to clean comments and format |
|
|
425
|
+
| `bun run build:ts` | Compile TypeScript to `build/` (without bundling) |
|
|
426
|
+
| `bun run build:bundle` | Bundle library with Rollup (development) |
|
|
427
|
+
| `bun run build:lib:prod` | Bundle library for production (minified) |
|
|
428
|
+
| `bun run build:cli:prod` | Bundle CLI executable for production |
|
|
429
|
+
| `bun run build:all:prod` | Bundle both library and CLI for production |
|
|
430
|
+
| `bun run rebuild` | Full rebuild pipeline (clean → clean-code → build → format) |
|
|
431
|
+
| `bun run test` | Run tests with Bun |
|
|
432
|
+
| `bun run version:patch` | Bump patch version |
|
|
433
|
+
| `bun run release` | Publish to npm (runs prepublishOnly) |
|
|
308
434
|
|
|
309
435
|
---
|
|
310
436
|
|
|
@@ -313,7 +439,10 @@ bun run test
|
|
|
313
439
|
1. Fork the repository
|
|
314
440
|
2. Create a feature branch (`git checkout -b feat/your-feature`)
|
|
315
441
|
3. Commit changes using [Conventional Commits](https://www.conventionalcommits.org/)
|
|
316
|
-
4.
|
|
442
|
+
4. Run `bun run rebuild` to ensure everything builds and is formatted
|
|
443
|
+
5. Push and open a Pull Request
|
|
444
|
+
|
|
445
|
+
Please ensure your code passes type checking, formatting, and all tests.
|
|
317
446
|
|
|
318
447
|
---
|
|
319
448
|
|
|
@@ -334,4 +463,5 @@ This license ensures that any network‑distributed modifications remain open so
|
|
|
334
463
|
|
|
335
464
|
> **Repository**: https://github.com/neuxdotdev/sfiledl
|
|
336
465
|
> **Issues**: https://github.com/neuxdotdev/sfiledl/issues
|
|
337
|
-
> **npm**: https://www.npmjs.com/package/sfiledl
|
|
466
|
+
> **npm**: https://www.npmjs.com/package/sfiledl
|
|
467
|
+
> **Documentation**: https://neuxdotdev.github.io/sfiledl/
|