cliproxy-server-termux 1.0.0 → 1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cliproxy-server-termux",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "CLIProxyAPIPlus server for Termux - Multi-provider AI API proxy with OAuth support",
5
5
  "type": "module",
6
6
  "main": "bin/cliproxy.js",
@@ -1,17 +1,90 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { mkdir, copyFile, access, constants } from 'fs/promises';
4
- import { join } from 'path';
3
+ import { mkdir, copyFile, access, constants, chmod, readFile } from 'fs/promises';
4
+ import { join, dirname } from 'path';
5
5
  import { homedir } from 'os';
6
+ import { fileURLToPath } from 'url';
7
+ import https from 'https';
8
+ import { createWriteStream } from 'fs';
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = dirname(__filename);
6
12
 
7
13
  const CONFIG_DIR = join(homedir(), '.config', 'cliproxyapi');
8
14
  const CONFIG_FILE = join(CONFIG_DIR, 'config.yaml');
9
- const SOURCE_CONFIG = join(process.cwd(), 'config', 'config-termux.yaml');
15
+ const SOURCE_CONFIG = join(__dirname, '..', 'config', 'config-termux.yaml');
16
+ const BINARY_PATH = join(__dirname, '..', 'bin', 'cliproxyapi');
17
+
18
+ // GitHub release URL for ARM64 binary
19
+ const BINARY_URL = 'https://github.com/julianromli/CLIProxyAPIPlus-Easy-Installation/releases/latest/download/cliproxyapi-plus-arm64';
20
+
21
+ async function downloadBinary(url, dest) {
22
+ return new Promise((resolve, reject) => {
23
+ console.log('šŸ“„ Downloading ARM64 binary from GitHub releases...');
24
+ const file = createWriteStream(dest);
25
+
26
+ https.get(url, (response) => {
27
+ if (response.statusCode === 302 || response.statusCode === 301) {
28
+ // Follow redirect
29
+ https.get(response.headers.location, (res) => {
30
+ res.pipe(file);
31
+ file.on('finish', () => {
32
+ file.close();
33
+ resolve();
34
+ });
35
+ }).on('error', reject);
36
+ } else {
37
+ response.pipe(file);
38
+ file.on('finish', () => {
39
+ file.close();
40
+ resolve();
41
+ });
42
+ }
43
+ }).on('error', (err) => {
44
+ file.close();
45
+ reject(err);
46
+ });
47
+ });
48
+ }
49
+
50
+ async function isBinaryValid(path) {
51
+ try {
52
+ const content = await readFile(path);
53
+ // Check if file is real binary (should be large) or placeholder
54
+ return content.length > 1000; // Real binary is >40MB, placeholder is <100 bytes
55
+ } catch {
56
+ return false;
57
+ }
58
+ }
10
59
 
11
60
  async function postinstall() {
12
61
  try {
13
62
  console.log('šŸ“¦ Setting up CLIProxyAPIPlus...\n');
14
63
 
64
+ // Check if binary exists and is valid
65
+ const binaryExists = await isBinaryValid(BINARY_PATH);
66
+
67
+ if (!binaryExists) {
68
+ console.log('āš ļø Binary not bundled in package (or invalid), downloading from GitHub...');
69
+ try {
70
+ await downloadBinary(BINARY_URL, BINARY_PATH);
71
+ await chmod(BINARY_PATH, 0o755);
72
+ console.log('āœ… Binary downloaded and set executable');
73
+ } catch (error) {
74
+ console.error('āŒ Binary download failed:', error.message);
75
+ console.log('\nāš ļø Manual installation required:');
76
+ console.log(' 1. Install Go: pkg install golang');
77
+ console.log(' 2. Clone: git clone https://github.com/julianromli/CLIProxyAPIPlus-Easy-Installation.git');
78
+ console.log(' 3. Build: cd CLIProxyAPIPlus-Easy-Installation/CLIProxyAPIPlus-main && go build -o ~/bin/cliproxyapi-plus ./cmd/cliproxyapi-plus');
79
+ console.log(' 4. Run: ~/bin/cliproxyapi-plus oauth login');
80
+ // Don't exit - continue with config setup
81
+ }
82
+ } else {
83
+ console.log('āœ… Binary found in package');
84
+ // Ensure it's executable
85
+ await chmod(BINARY_PATH, 0o755);
86
+ }
87
+
15
88
  // Create config directory
16
89
  await mkdir(CONFIG_DIR, { recursive: true });
17
90
  console.log('āœ… Created config directory:', CONFIG_DIR);