teledrive 1.2.0 → 1.2.2

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.
Files changed (2) hide show
  1. package/bin/teledrive.js +30 -11
  2. package/package.json +1 -1
package/bin/teledrive.js CHANGED
@@ -12,7 +12,8 @@ const https = require('node:https');
12
12
  const os = require('node:os');
13
13
  const path = require('node:path');
14
14
 
15
- const VERSION = '1.2.0';
15
+ const VERSION = '1.2.1';
16
+ const BINARY_VERSION = '1.2.0';
16
17
 
17
18
  // Map process.platform to TeleDrive release platform name
18
19
  const PLATFORM_MAP = {
@@ -48,7 +49,7 @@ function findLocalBinary() {
48
49
  }
49
50
 
50
51
  // 2. Local cache directory
51
- const cached = path.join(getCacheDir(), `teledrive-v${VERSION}${process.platform === 'win32' ? '.exe' : ''}`);
52
+ const cached = path.join(getCacheDir(), `teledrive-v${BINARY_VERSION}${process.platform === 'win32' ? '.exe' : ''}`);
52
53
  if (fs.existsSync(cached)) {
53
54
  return cached;
54
55
  }
@@ -99,6 +100,27 @@ function downloadUrl(url, destPath) {
99
100
  });
100
101
  }
101
102
 
103
+ function extractArchive(archivePath, destDir, platform) {
104
+ if (platform === 'windows') {
105
+ // 1. Try Windows tar (tar -xf handles .zip on Windows 10/11)
106
+ const tarResult = spawnSync('tar', ['-xf', archivePath, '-C', destDir], { stdio: 'inherit' });
107
+ if (tarResult.status === 0) return;
108
+
109
+ // 2. Fallback to PowerShell Expand-Archive (built into all modern Windows systems)
110
+ const psCmd = `Expand-Archive -LiteralPath '${archivePath}' -DestinationPath '${destDir}' -Force`;
111
+ const psResult = spawnSync('powershell.exe', ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', psCmd], { stdio: 'inherit' });
112
+ if (psResult.status === 0) return;
113
+
114
+ throw new Error(`Failed to extract Windows archive via tar or PowerShell.`);
115
+ }
116
+
117
+ // Linux and macOS: tar -xzf
118
+ const extractResult = spawnSync('tar', ['-xzf', archivePath, '-C', destDir], { stdio: 'inherit' });
119
+ if (extractResult.status !== 0) {
120
+ throw new Error(`tar extraction failed with exit code ${extractResult.status}`);
121
+ }
122
+ }
123
+
102
124
  async function ensureBinary() {
103
125
  const existing = findLocalBinary();
104
126
  if (existing) return existing;
@@ -113,21 +135,18 @@ async function ensureBinary() {
113
135
  const cacheDir = getCacheDir();
114
136
  fs.mkdirSync(cacheDir, { recursive: true });
115
137
 
116
- const binTarget = path.join(cacheDir, `teledrive-v${VERSION}${process.platform === 'win32' ? '.exe' : ''}`);
117
- const archiveName = `teledrive-v${VERSION}-${platform}-${arch}.tar.gz`;
138
+ const binTarget = path.join(cacheDir, `teledrive-v${BINARY_VERSION}${process.platform === 'win32' ? '.exe' : ''}`);
139
+ const ext = (platform === 'windows') ? '.zip' : '.tar.gz';
140
+ const archiveName = `teledrive-v${BINARY_VERSION}-${platform}-${arch}${ext}`;
118
141
  const downloadArchive = path.join(cacheDir, archiveName);
119
- const releaseUrl = `https://github.com/herliansyah/teledrive/releases/download/v${VERSION}/${archiveName}`;
142
+ const releaseUrl = `https://github.com/herliansyah/teledrive/releases/download/v${BINARY_VERSION}/${archiveName}`;
120
143
 
121
- console.log(`[teledrive] Binary not found locally. Downloading TeleDrive v${VERSION} for ${platform}/${arch}...`);
144
+ console.log(`[teledrive] Binary not found locally. Downloading TeleDrive v${BINARY_VERSION} for ${platform}/${arch}...`);
122
145
 
123
146
  try {
124
147
  await downloadUrl(releaseUrl, downloadArchive);
125
148
 
126
- // Extract using system tar
127
- const extractResult = spawnSync('tar', ['-xzf', downloadArchive, '-C', cacheDir], { stdio: 'inherit' });
128
- if (extractResult.status !== 0) {
129
- throw new Error(`tar extraction failed with exit code ${extractResult.status}`);
130
- }
149
+ extractArchive(downloadArchive, cacheDir, platform);
131
150
 
132
151
  // Clean up archive
133
152
  try { fs.unlinkSync(downloadArchive); } catch (_) {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teledrive",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "High-Capacity Cloud Storage Powered by Telegram MTProto Infrastructure",
5
5
  "main": "bin/teledrive.js",
6
6
  "bin": {