sfiledl 2.0.1 → 2.1.1

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/readme.md ADDED
@@ -0,0 +1,170 @@
1
+ # sfiledl
2
+
3
+ > Implement and automate downloading of any file from https://sfile.co/ with javascripts library, written entirely in typescripts
4
+
5
+ [![npm version](https://img.shields.io/npm/v/sfiledl)](https://www.npmjs.com/package/sfiledl)
6
+ [![License](https://img.shields.io/npm/l/sfiledl)](https://github.com/neuxdotdev/sfiledl/blob/main/license)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0-blue)](https://www.typescriptlang.org)
8
+
9
+ ---
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ # Using Bun (recommended)
15
+ bun add sfiledl
16
+
17
+ # Using npm
18
+ npm install sfiledl
19
+
20
+ # Install Playwright browser (required)
21
+ bunx playwright install chromium
22
+ ```
23
+
24
+ ---
25
+
26
+ ## Quick Start
27
+
28
+ ```typescript
29
+ import { downloadSfile } from 'sfiledl'
30
+
31
+ const result = await downloadSfile(
32
+ 'https://sfile.co/file/abc123', // sfile.co URL
33
+ './downloads', // Save directory
34
+ { headless: true, debug: false }, // Optional options
35
+ )
36
+
37
+ console.log(result)
38
+ // {
39
+ // filePath: './downloads/file.zip',
40
+ // size: 1048576,
41
+ // method: 'direct' | 'fallback'
42
+ // }
43
+ ```
44
+
45
+ ---
46
+
47
+ ## API Reference
48
+
49
+ ### `downloadSfile(url, saveDir, options?)`
50
+
51
+ | Parameter | Type | Required | Description |
52
+ | --------- | ----------------- | -------- | -------------------------- |
53
+ | `url` | `string` | | sfile.co URL to download |
54
+ | `saveDir` | `string` | | Directory to save the file |
55
+ | `options` | `DownloadOptions` | | Optional configuration |
56
+
57
+ ### `DownloadOptions`
58
+
59
+ ```typescript
60
+ interface DownloadOptions {
61
+ headless?: boolean // Run browser headless (default: true)
62
+ debug?: boolean // Enable debug logging (default: false)
63
+ userAgent?: string // Custom user agent string
64
+ timeout?: number // Operation timeout in ms (default: 100000)
65
+ }
66
+ ```
67
+
68
+ ### `DownloadResult`
69
+
70
+ ```typescript
71
+ interface DownloadResult {
72
+ filePath: string // Full path to saved file
73
+ size: number // File size in bytes
74
+ method: 'direct' | 'fallback' // Download strategy used
75
+ }
76
+ ```
77
+
78
+ ---
79
+
80
+ ## Error Handling
81
+
82
+ ```typescript
83
+ import { downloadSfile, ValidationError, NetworkError } from 'sfiledl'
84
+
85
+ try {
86
+ await downloadSfile('https://sfile.co/file/xyz', './out')
87
+ } catch (err) {
88
+ if (err instanceof ValidationError) {
89
+ console.error('Invalid input:', err.message)
90
+ }
91
+ if (err instanceof NetworkError && err.retryable) {
92
+ console.log('Network issue, retry possible')
93
+ }
94
+ // All errors include: code, timestamp, context, retryable flag
95
+ }
96
+ ```
97
+
98
+ ### Error Types
99
+
100
+ | Error | Code | Retryable | When |
101
+ | ----------------- | ------------------ | --------- | -------------------------- |
102
+ | `ValidationError` | `VALIDATION_ERROR` | | Invalid URL or input |
103
+ | `NetworkError` | `NETWORK_ERROR` | | Navigation/fetch failures |
104
+ | `FileError` | `FILE_ERROR` | | File system issues |
105
+ | `BrowserError` | `BROWSER_ERROR` | | Playwright launch failures |
106
+
107
+ ---
108
+
109
+ ## Debug Mode
110
+
111
+ Enable `debug: true` for verbose logging:
112
+
113
+ ```typescript
114
+ await downloadSfile(url, './out', { debug: true })
115
+ ```
116
+
117
+ On error, debug artifacts are auto-saved to `/tmp/sfile_debug_<timestamp>/`:
118
+
119
+ - `error.png` — Full page screenshot
120
+ - `error.html` — Page source at failure
121
+ - `error.txt` — Error message
122
+
123
+ ---
124
+
125
+ ## Development
126
+
127
+ ```bash
128
+ # Clone & install
129
+ git clone https://github.com/neuxdotdev/sfiledl.git
130
+ cd sfiledl
131
+ bun install
132
+ bunx playwright install chromium
133
+ # Rebuild (clean + lint + build + format)
134
+ bun run rebuild
135
+
136
+ # Run tests
137
+ bun run test
138
+ ```
139
+
140
+ ---
141
+
142
+ ## Contributing
143
+
144
+ 1. Fork the repository
145
+ 2. Create a feature branch (`git checkout -b feat/your-feature`)
146
+ 3. Commit changes (`git commit -m 'feat: add your feature'`)
147
+ 4. Push to branch (`git push origin feat/your-feature`)
148
+ 5. Open a Pull Request
149
+
150
+ ---
151
+
152
+ ## License
153
+
154
+ **AGPL-3.0-only** — See [LICENSE](license) for details.
155
+
156
+ > This license ensures that any network-distributed modifications remain open source.
157
+
158
+ ---
159
+
160
+ ## Credits
161
+
162
+ - Built with [Playwright](https://playwright.dev) for reliable automation
163
+ - Optimized for [Bun](https://bun.sh) runtime performance
164
+ - Inspired by the need for simple, scriptable file downloads
165
+
166
+ ---
167
+
168
+ > **Repository**: https://github.com/neuxdotdev/sfiledl
169
+ > **Issues**: https://github.com/neuxdotdev/sfiledl/issues
170
+ > **npm**: https://www.npmjs.com/package/sfiledl
package/readme DELETED
@@ -1,3 +0,0 @@
1
- sfiledl
2
-
3
- Implement and automate downloading of any file from sfile.co with javascripts library, written entirely in typescripts