upfilesh 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Perry Raskin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # upfile-cli
2
+
3
+ Upload any file from your terminal. Get a permanent URL instantly.
4
+
5
+ → [upfile.sh](https://upfile.sh)
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ yarn global add upfile-cli
11
+ ```
12
+
13
+ ## Setup
14
+
15
+ ```bash
16
+ upfile config set api-key YOUR_API_KEY
17
+ ```
18
+
19
+ Get your API key at [upfile.sh](https://upfile.sh).
20
+
21
+ ## Usage
22
+
23
+ ```bash
24
+ # Public — permanent URL, anyone can access
25
+ upfile screenshot.png
26
+ # https://cdn.upfile.sh/xK9mZ.png
27
+
28
+ # Expiring — self-destructs after TTL (seconds)
29
+ upfile report.pdf --expiry 3600
30
+
31
+ # Private — auth-gated, only you can access
32
+ upfile secret.pdf --private
33
+
34
+ # JSON output — for AI agents and scripts
35
+ upfile screenshot.png --json
36
+
37
+ # Pipe from stdin — capture and upload in one line
38
+ screencapture -x - | upfile
39
+ cat file.txt | upfile --json
40
+ ```
41
+
42
+ ## Options
43
+
44
+ | Flag | Description |
45
+ |------|-------------|
46
+ | `--private` | Private file, requires auth to access |
47
+ | `--expiry <sec>` | Expiring URL with TTL in seconds |
48
+ | `--json` | Full JSON response (url, id, visibility, expires_at) |
49
+
50
+ ## JSON response
51
+
52
+ ```json
53
+ {
54
+ "id": "xK9mZaBcDe",
55
+ "url": "https://cdn.upfile.sh/xK9mZaBcDe.png",
56
+ "visibility": "public",
57
+ "size": 84231,
58
+ "type": "image/png",
59
+ "expires_at": null,
60
+ "created_at": "2026-03-02T03:00:00.000Z"
61
+ }
62
+ ```
63
+
64
+ ## Config
65
+
66
+ ```bash
67
+ upfile config set api-key <key> # save API key
68
+ upfile config set endpoint <url> # self-hosted endpoint
69
+ upfile config get # view current config
70
+ ```
71
+
72
+ Config stored at `~/.upfile/config.json`.
73
+
74
+ ## Environment variables
75
+
76
+ | Var | Description |
77
+ |-----|-------------|
78
+ | `UPFILE_API_KEY` | API key (overrides config file) |
package/bin/upfile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("../dist/index.js");
package/dist/config.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DEFAULT_ENDPOINT = void 0;
7
+ exports.loadConfig = loadConfig;
8
+ exports.saveConfig = saveConfig;
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const os_1 = __importDefault(require("os"));
12
+ const CONFIG_DIR = path_1.default.join(os_1.default.homedir(), ".upfile");
13
+ const CONFIG_FILE = path_1.default.join(CONFIG_DIR, "config.json");
14
+ function loadConfig() {
15
+ if (!fs_1.default.existsSync(CONFIG_FILE))
16
+ return {};
17
+ return JSON.parse(fs_1.default.readFileSync(CONFIG_FILE, "utf-8"));
18
+ }
19
+ function saveConfig(patch) {
20
+ fs_1.default.mkdirSync(CONFIG_DIR, { recursive: true });
21
+ const existing = loadConfig();
22
+ fs_1.default.writeFileSync(CONFIG_FILE, JSON.stringify({ ...existing, ...patch }, null, 2));
23
+ }
24
+ exports.DEFAULT_ENDPOINT = "https://api.upfile.sh";
package/dist/index.js ADDED
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const upload_js_1 = require("./upload.js");
8
+ const config_js_1 = require("./config.js");
9
+ const args = process.argv.slice(2);
10
+ function flag(name) {
11
+ const i = args.findIndex(a => a === `--${name}`);
12
+ if (i === -1)
13
+ return undefined;
14
+ return args[i + 1];
15
+ }
16
+ function hasFlag(name) {
17
+ return args.includes(`--${name}`);
18
+ }
19
+ function formatSize(bytes) {
20
+ if (bytes < 1024)
21
+ return `${bytes}B`;
22
+ if (bytes < 1024 * 1024)
23
+ return `${(bytes / 1024).toFixed(1)}KB`;
24
+ return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
25
+ }
26
+ async function main() {
27
+ const cmd = args[0];
28
+ // upfile signup --email me@example.com [--owner-email owner@example.com]
29
+ if (cmd === "signup") {
30
+ const email = flag("email");
31
+ const ownerEmail = flag("owner-email");
32
+ if (!email) {
33
+ console.error("Usage: upfile signup --email your@email.com [--owner-email owner@company.com]");
34
+ process.exit(1);
35
+ }
36
+ const result = await (0, upload_js_1.signup)(email, ownerEmail);
37
+ console.log("✓ Account created");
38
+ console.log(`API key: ${result.api_key}`);
39
+ console.log(`Tier: ${result.tier} (${result.storage_limit_gb}GB)`);
40
+ (0, config_js_1.saveConfig)({ apiKey: result.api_key });
41
+ console.log("\nKey saved. You're ready to upload.");
42
+ return;
43
+ }
44
+ // upfile status
45
+ if (cmd === "status") {
46
+ const status = await (0, upload_js_1.getStatus)();
47
+ console.log(`Tier: ${status.tier}`);
48
+ console.log(`Storage: ${status.storage_used_gb}GB / ${status.storage_limit_gb}GB`);
49
+ return;
50
+ }
51
+ // upfile upgrade
52
+ if (cmd === "upgrade") {
53
+ const result = await (0, upload_js_1.getUpgradeUrl)();
54
+ if (result.checkout_url) {
55
+ console.log(`Upgrade link: ${result.checkout_url}`);
56
+ console.log(`Sent to: ${result.message}`);
57
+ }
58
+ else {
59
+ console.log("Manual upgrade:");
60
+ console.log(result.message);
61
+ console.log(`Price: ${result.price}`);
62
+ }
63
+ return;
64
+ }
65
+ // upfile config set/get
66
+ if (cmd === "config") {
67
+ if (args[1] === "set") {
68
+ const [, , , key, value] = args;
69
+ if (!key || !value) {
70
+ console.error("Usage: upfile config set <key> <value>");
71
+ process.exit(1);
72
+ }
73
+ if (key === "api-key")
74
+ (0, config_js_1.saveConfig)({ apiKey: value });
75
+ else if (key === "endpoint")
76
+ (0, config_js_1.saveConfig)({ endpoint: value });
77
+ else {
78
+ console.error(`Unknown config key: ${key}`);
79
+ process.exit(1);
80
+ }
81
+ console.log(`✓ ${key} saved`);
82
+ }
83
+ else {
84
+ console.log(JSON.stringify((0, config_js_1.loadConfig)(), null, 2));
85
+ }
86
+ return;
87
+ }
88
+ // upfile ls [--limit N]
89
+ if (cmd === "ls" || cmd === "list") {
90
+ const limit = parseInt(flag("limit") || "20");
91
+ const isJson = hasFlag("json");
92
+ const files = await (0, upload_js_1.listFiles)(limit);
93
+ if (isJson) {
94
+ console.log(JSON.stringify(files, null, 2));
95
+ return;
96
+ }
97
+ if (files.length === 0) {
98
+ console.log("No files yet.");
99
+ return;
100
+ }
101
+ for (const f of files) {
102
+ const expires = f.expires_at ? ` (expires ${new Date(f.expires_at).toLocaleDateString()})` : "";
103
+ console.log(`${f.id} ${formatSize(f.size).padEnd(8)} [${f.visibility}]${expires}`);
104
+ console.log(` ${f.url}`);
105
+ }
106
+ return;
107
+ }
108
+ // upfile rm <id>
109
+ if (cmd === "rm" || cmd === "delete") {
110
+ const id = args[1];
111
+ if (!id) {
112
+ console.error("Usage: upfile rm <id>");
113
+ process.exit(1);
114
+ }
115
+ await (0, upload_js_1.deleteFile)(id);
116
+ console.log(`✓ deleted ${id}`);
117
+ return;
118
+ }
119
+ // upfile <file> [flags] OR stdin pipe
120
+ const isJson = hasFlag("json");
121
+ const isPrivate = hasFlag("private");
122
+ const ttl = flag("expiry") ? parseInt(flag("expiry")) : undefined;
123
+ const visibility = isPrivate ? "private" : ttl ? "expiring" : "public";
124
+ const opts = { visibility, ttl, json: isJson };
125
+ let result;
126
+ if (!process.stdin.isTTY && !cmd) {
127
+ result = await (0, upload_js_1.uploadStdin)(opts);
128
+ }
129
+ else {
130
+ const filePath = args.find(a => !a.startsWith("--"));
131
+ if (!filePath) {
132
+ console.error([
133
+ "Usage:",
134
+ " upfile signup --email <email> [--owner-email <email>] create account",
135
+ " upfile status check storage",
136
+ " upfile upgrade get upgrade link",
137
+ " upfile <file> upload file (public)",
138
+ " upfile <file> --private private file",
139
+ " upfile <file> --expiry <seconds> expiring URL",
140
+ " upfile <file> --json JSON output",
141
+ " cat file | upfile pipe from stdin",
142
+ " upfile ls [--limit N] [--json] list your files",
143
+ " upfile rm <id> delete a file",
144
+ " upfile config set api-key <key>",
145
+ " upfile config set endpoint <url>",
146
+ ].join("\n"));
147
+ process.exit(1);
148
+ }
149
+ result = await (0, upload_js_1.uploadFile)(path_1.default.resolve(filePath), opts);
150
+ }
151
+ if (isJson)
152
+ console.log(JSON.stringify(result, null, 2));
153
+ else
154
+ console.log(result.url);
155
+ }
156
+ main().catch(e => { console.error(e.message); process.exit(1); });
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/upload.js ADDED
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.signup = signup;
7
+ exports.getStatus = getStatus;
8
+ exports.getUpgradeUrl = getUpgradeUrl;
9
+ exports.uploadFile = uploadFile;
10
+ exports.uploadStdin = uploadStdin;
11
+ exports.listFiles = listFiles;
12
+ exports.deleteFile = deleteFile;
13
+ const fs_1 = __importDefault(require("fs"));
14
+ const path_1 = __importDefault(require("path"));
15
+ const form_data_1 = __importDefault(require("form-data"));
16
+ const node_fetch_1 = __importDefault(require("node-fetch"));
17
+ const config_js_1 = require("./config.js");
18
+ function getAuth() {
19
+ const config = (0, config_js_1.loadConfig)();
20
+ const apiKey = config.apiKey || process.env.UPFILE_API_KEY;
21
+ const endpoint = config.endpoint || config_js_1.DEFAULT_ENDPOINT;
22
+ if (!apiKey)
23
+ throw new Error("No API key. Run: upfile signup --email your@email.com");
24
+ return { apiKey, endpoint };
25
+ }
26
+ async function signup(email, ownerEmail) {
27
+ const { endpoint } = getAuth();
28
+ const res = await (0, node_fetch_1.default)(`${endpoint}/signup`, {
29
+ method: "POST",
30
+ headers: { "Content-Type": "application/json" },
31
+ body: JSON.stringify({ email, owner_email: ownerEmail }),
32
+ });
33
+ if (!res.ok)
34
+ throw new Error(`Signup failed (${res.status}): ${await res.text()}`);
35
+ return res.json();
36
+ }
37
+ async function getStatus() {
38
+ const { apiKey, endpoint } = getAuth();
39
+ const res = await (0, node_fetch_1.default)(`${endpoint}/status`, {
40
+ headers: { Authorization: `Bearer ${apiKey}` },
41
+ });
42
+ if (!res.ok)
43
+ throw new Error(`Status check failed (${res.status}): ${await res.text()}`);
44
+ const data = await res.json();
45
+ return data;
46
+ }
47
+ async function getUpgradeUrl() {
48
+ const { apiKey, endpoint } = getAuth();
49
+ const res = await (0, node_fetch_1.default)(`${endpoint}/upgrade`, {
50
+ headers: { Authorization: `Bearer ${apiKey}` },
51
+ });
52
+ if (!res.ok)
53
+ throw new Error(`Upgrade check failed (${res.status}): ${await res.text()}`);
54
+ return res.json();
55
+ }
56
+ async function uploadFile(filePath, opts) {
57
+ const { apiKey, endpoint } = getAuth();
58
+ const form = new form_data_1.default();
59
+ form.append("file", fs_1.default.createReadStream(filePath), path_1.default.basename(filePath));
60
+ form.append("visibility", opts.visibility);
61
+ if (opts.ttl)
62
+ form.append("ttl", String(opts.ttl));
63
+ const res = await (0, node_fetch_1.default)(`${endpoint}/upload`, {
64
+ method: "POST",
65
+ headers: { Authorization: `Bearer ${apiKey}`, ...form.getHeaders() },
66
+ body: form,
67
+ });
68
+ if (!res.ok) {
69
+ const err = await res.json().catch(async () => ({ error: await res.text() }));
70
+ const errorObj = err;
71
+ if (errorObj.error?.includes("Storage limit")) {
72
+ throw new Error(`Storage limit reached (${errorObj.storage_used_gb}GB / ${errorObj.limit_gb}GB). ${errorObj.message}`);
73
+ }
74
+ throw new Error(`Upload failed (${res.status}): ${errorObj.error || await res.text()}`);
75
+ }
76
+ return res.json();
77
+ }
78
+ async function uploadStdin(opts) {
79
+ const { apiKey, endpoint } = getAuth();
80
+ const chunks = [];
81
+ for await (const chunk of process.stdin)
82
+ chunks.push(chunk);
83
+ const buffer = Buffer.concat(chunks);
84
+ const form = new form_data_1.default();
85
+ form.append("file", buffer, { filename: "upload.bin", contentType: "application/octet-stream" });
86
+ form.append("visibility", opts.visibility);
87
+ if (opts.ttl)
88
+ form.append("ttl", String(opts.ttl));
89
+ const res = await (0, node_fetch_1.default)(`${endpoint}/upload`, {
90
+ method: "POST",
91
+ headers: { Authorization: `Bearer ${apiKey}`, ...form.getHeaders() },
92
+ body: form,
93
+ });
94
+ if (!res.ok)
95
+ throw new Error(`Upload failed (${res.status}): ${await res.text()}`);
96
+ return res.json();
97
+ }
98
+ async function listFiles(limit = 20) {
99
+ const { apiKey, endpoint } = getAuth();
100
+ const res = await (0, node_fetch_1.default)(`${endpoint}/files?limit=${limit}`, {
101
+ headers: { Authorization: `Bearer ${apiKey}` },
102
+ });
103
+ if (!res.ok)
104
+ throw new Error(`List failed (${res.status}): ${await res.text()}`);
105
+ const data = await res.json();
106
+ return data.files;
107
+ }
108
+ async function deleteFile(id) {
109
+ const { apiKey, endpoint } = getAuth();
110
+ const res = await (0, node_fetch_1.default)(`${endpoint}/f/${id}`, {
111
+ method: "DELETE",
112
+ headers: { Authorization: `Bearer ${apiKey}` },
113
+ });
114
+ if (!res.ok)
115
+ throw new Error(`Delete failed (${res.status}): ${await res.text()}`);
116
+ }
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "upfilesh",
3
+ "version": "0.1.0",
4
+ "description": "Instant file uploads from the command line — upfile.sh",
5
+ "bin": {
6
+ "upfile": "./bin/upfile"
7
+ },
8
+ "main": "dist/index.js",
9
+ "files": [
10
+ "bin/",
11
+ "dist/",
12
+ "README.md"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "dev": "ts-node src/index.ts",
17
+ "prepublishOnly": "yarn build"
18
+ },
19
+ "keywords": [
20
+ "upload",
21
+ "file-sharing",
22
+ "cli",
23
+ "cdn",
24
+ "ai-agents",
25
+ "terminal",
26
+ "command-line"
27
+ ],
28
+ "author": "Perry Raskin <perry@upfile.sh>",
29
+ "license": "MIT",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/upfilesh/cli.git"
33
+ },
34
+ "bugs": {
35
+ "url": "https://github.com/upfilesh/cli/issues"
36
+ },
37
+ "homepage": "https://upfile.sh",
38
+ "engines": {
39
+ "node": ">=18"
40
+ },
41
+ "dependencies": {
42
+ "form-data": "^4.0.0",
43
+ "node-fetch": "^3.3.0"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^20.0.0",
47
+ "typescript": "^5.4.0",
48
+ "ts-node": "^10.9.0"
49
+ }
50
+ }