drivekit 1.0.0 → 1.0.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.
- package/README.ar.md +18 -2
- package/README.md +17 -5
- package/dist/cli.cjs +436 -81
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +436 -81
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +351 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +111 -8
- package/dist/index.d.ts +111 -8
- package/dist/index.js +344 -6
- package/dist/index.js.map +1 -1
- package/package.json +4 -12
package/dist/cli.cjs
CHANGED
|
@@ -652,6 +652,9 @@ var init_resumable_uploader = __esm({
|
|
|
652
652
|
let chunkIndex = 0;
|
|
653
653
|
try {
|
|
654
654
|
while (bytesSent < totalBytes) {
|
|
655
|
+
if (options.signal?.aborted) {
|
|
656
|
+
throw new Error("Upload aborted by user signal");
|
|
657
|
+
}
|
|
655
658
|
chunkIndex++;
|
|
656
659
|
const currentChunkSize = Math.min(chunkSize, totalBytes - bytesSent);
|
|
657
660
|
const buffer = Buffer.alloc(currentChunkSize);
|
|
@@ -712,6 +715,9 @@ var init_resumable_uploader = __esm({
|
|
|
712
715
|
const totalChunks = Math.ceil(totalBytes / chunkSize) || 1;
|
|
713
716
|
let chunkIndex = 0;
|
|
714
717
|
while (bytesSent < totalBytes) {
|
|
718
|
+
if (options.signal?.aborted) {
|
|
719
|
+
throw new Error("Upload aborted by user signal");
|
|
720
|
+
}
|
|
715
721
|
chunkIndex++;
|
|
716
722
|
const currentChunkSize = Math.min(chunkSize, totalBytes - bytesSent);
|
|
717
723
|
const chunk = buffer.subarray(bytesSent, bytesSent + currentChunkSize);
|
|
@@ -1683,6 +1689,169 @@ var init_browser_login = __esm({
|
|
|
1683
1689
|
}
|
|
1684
1690
|
});
|
|
1685
1691
|
|
|
1692
|
+
// src/core/resource-refs.ts
|
|
1693
|
+
var DriveFileRef, DriveFolderRef;
|
|
1694
|
+
var init_resource_refs = __esm({
|
|
1695
|
+
"src/core/resource-refs.ts"() {
|
|
1696
|
+
"use strict";
|
|
1697
|
+
init_cjs_shims();
|
|
1698
|
+
DriveFileRef = class {
|
|
1699
|
+
drive;
|
|
1700
|
+
pathOrId;
|
|
1701
|
+
constructor(drive2, pathOrId) {
|
|
1702
|
+
this.drive = drive2;
|
|
1703
|
+
this.pathOrId = pathOrId;
|
|
1704
|
+
}
|
|
1705
|
+
/** Gets file metadata */
|
|
1706
|
+
async get() {
|
|
1707
|
+
return await this.drive.getFile(this.pathOrId);
|
|
1708
|
+
}
|
|
1709
|
+
/** Checks if the file exists */
|
|
1710
|
+
async exists() {
|
|
1711
|
+
return await this.drive.exists(this.pathOrId);
|
|
1712
|
+
}
|
|
1713
|
+
/** Reads file as UTF-8 string */
|
|
1714
|
+
async getText() {
|
|
1715
|
+
return await this.drive.getText(this.pathOrId);
|
|
1716
|
+
}
|
|
1717
|
+
/** Reads and parses JSON file */
|
|
1718
|
+
async getJson() {
|
|
1719
|
+
return await this.drive.getJson(this.pathOrId);
|
|
1720
|
+
}
|
|
1721
|
+
/** Downloads the file to destination */
|
|
1722
|
+
async download(optionsOrDestination) {
|
|
1723
|
+
const opts = typeof optionsOrDestination === "string" ? { destination: optionsOrDestination } : optionsOrDestination;
|
|
1724
|
+
return await this.drive.download(this.pathOrId, opts);
|
|
1725
|
+
}
|
|
1726
|
+
/** Moves the file to a new folder path or ID */
|
|
1727
|
+
async moveTo(newParentPathOrId) {
|
|
1728
|
+
return await this.drive.move(this.pathOrId, newParentPathOrId);
|
|
1729
|
+
}
|
|
1730
|
+
/** Copies the file to a target directory */
|
|
1731
|
+
async copyTo(parentPathOrId, newName) {
|
|
1732
|
+
return await this.drive.copy(this.pathOrId, { parent: parentPathOrId, name: newName });
|
|
1733
|
+
}
|
|
1734
|
+
/** Renames the file */
|
|
1735
|
+
async rename(newName) {
|
|
1736
|
+
return await this.drive.rename(this.pathOrId, newName);
|
|
1737
|
+
}
|
|
1738
|
+
/** Deletes the file (or moves to trash if permanent is false) */
|
|
1739
|
+
async delete(permanent = false) {
|
|
1740
|
+
return await this.drive.delete(this.pathOrId, permanent);
|
|
1741
|
+
}
|
|
1742
|
+
/** Moves file to trash */
|
|
1743
|
+
async trash() {
|
|
1744
|
+
return await this.drive.trash(this.pathOrId);
|
|
1745
|
+
}
|
|
1746
|
+
/** Shares file */
|
|
1747
|
+
async share(options) {
|
|
1748
|
+
return await this.drive.share(this.pathOrId, options);
|
|
1749
|
+
}
|
|
1750
|
+
/** Makes file publicly accessible */
|
|
1751
|
+
async sharePublic(role = "reader") {
|
|
1752
|
+
return await this.drive.sharePublic(this.pathOrId, role);
|
|
1753
|
+
}
|
|
1754
|
+
/** Gets public/preview links */
|
|
1755
|
+
async getLink() {
|
|
1756
|
+
return await this.drive.getShareableLink(this.pathOrId);
|
|
1757
|
+
}
|
|
1758
|
+
};
|
|
1759
|
+
DriveFolderRef = class {
|
|
1760
|
+
drive;
|
|
1761
|
+
pathOrId;
|
|
1762
|
+
constructor(drive2, pathOrId) {
|
|
1763
|
+
this.drive = drive2;
|
|
1764
|
+
this.pathOrId = pathOrId;
|
|
1765
|
+
}
|
|
1766
|
+
/** Lists contents of this folder */
|
|
1767
|
+
async ls() {
|
|
1768
|
+
return await this.drive.ls(this.pathOrId);
|
|
1769
|
+
}
|
|
1770
|
+
/** Ensures this folder and subpaths exist (mkdir -p) */
|
|
1771
|
+
async mkdirp(subPath) {
|
|
1772
|
+
const target = subPath ? this.pathOrId.endsWith("/") ? `${this.pathOrId}${subPath}` : `${this.pathOrId}/${subPath}` : this.pathOrId;
|
|
1773
|
+
return await this.drive.mkdirp(target);
|
|
1774
|
+
}
|
|
1775
|
+
/** Uploads a file directly into this folder */
|
|
1776
|
+
async upload(source, options = {}) {
|
|
1777
|
+
return await this.drive.upload({
|
|
1778
|
+
...options,
|
|
1779
|
+
source,
|
|
1780
|
+
parent: this.pathOrId
|
|
1781
|
+
});
|
|
1782
|
+
}
|
|
1783
|
+
/** Synchronizes a local directory into this remote folder */
|
|
1784
|
+
async syncFrom(localDir, options = {}) {
|
|
1785
|
+
return await this.drive.syncFolder(localDir, this.pathOrId, options);
|
|
1786
|
+
}
|
|
1787
|
+
/** Pulls this remote folder down to local directory */
|
|
1788
|
+
async pullTo(localDestinationDir, options = {}) {
|
|
1789
|
+
return await this.drive.pull(this.pathOrId, localDestinationDir, options);
|
|
1790
|
+
}
|
|
1791
|
+
/** Watches this folder for real-time changes */
|
|
1792
|
+
async watch(options = {}) {
|
|
1793
|
+
return await this.drive.watch(this.pathOrId, options);
|
|
1794
|
+
}
|
|
1795
|
+
};
|
|
1796
|
+
}
|
|
1797
|
+
});
|
|
1798
|
+
|
|
1799
|
+
// src/core/plugins.ts
|
|
1800
|
+
var PluginManager;
|
|
1801
|
+
var init_plugins = __esm({
|
|
1802
|
+
"src/core/plugins.ts"() {
|
|
1803
|
+
"use strict";
|
|
1804
|
+
init_cjs_shims();
|
|
1805
|
+
PluginManager = class {
|
|
1806
|
+
plugins = [];
|
|
1807
|
+
use(plugin) {
|
|
1808
|
+
this.plugins.push(plugin);
|
|
1809
|
+
return this;
|
|
1810
|
+
}
|
|
1811
|
+
async runBeforeUpload(options) {
|
|
1812
|
+
let current = { ...options };
|
|
1813
|
+
for (const plugin of this.plugins) {
|
|
1814
|
+
if (plugin.beforeUpload) {
|
|
1815
|
+
const modified = await plugin.beforeUpload(current);
|
|
1816
|
+
if (modified) current = modified;
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
return current;
|
|
1820
|
+
}
|
|
1821
|
+
async runAfterUpload(file) {
|
|
1822
|
+
let current = file;
|
|
1823
|
+
for (const plugin of this.plugins) {
|
|
1824
|
+
if (plugin.afterUpload) {
|
|
1825
|
+
const modified = await plugin.afterUpload(current);
|
|
1826
|
+
if (modified) current = modified;
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
return current;
|
|
1830
|
+
}
|
|
1831
|
+
async runBeforeDownload(fileId, options) {
|
|
1832
|
+
let current = { ...options };
|
|
1833
|
+
for (const plugin of this.plugins) {
|
|
1834
|
+
if (plugin.beforeDownload) {
|
|
1835
|
+
const modified = await plugin.beforeDownload(fileId, current);
|
|
1836
|
+
if (modified) current = modified;
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
return current;
|
|
1840
|
+
}
|
|
1841
|
+
async runAfterDownload(result) {
|
|
1842
|
+
let current = result;
|
|
1843
|
+
for (const plugin of this.plugins) {
|
|
1844
|
+
if (plugin.afterDownload) {
|
|
1845
|
+
const modified = await plugin.afterDownload(current);
|
|
1846
|
+
if (modified) current = modified;
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
return current;
|
|
1850
|
+
}
|
|
1851
|
+
};
|
|
1852
|
+
}
|
|
1853
|
+
});
|
|
1854
|
+
|
|
1686
1855
|
// src/core/client.ts
|
|
1687
1856
|
var client_exports = {};
|
|
1688
1857
|
__export(client_exports, {
|
|
@@ -1706,6 +1875,8 @@ var init_client = __esm({
|
|
|
1706
1875
|
init_storage_cleaner();
|
|
1707
1876
|
init_smart_sync();
|
|
1708
1877
|
init_browser_login();
|
|
1878
|
+
init_resource_refs();
|
|
1879
|
+
init_plugins();
|
|
1709
1880
|
init_retry();
|
|
1710
1881
|
init_format();
|
|
1711
1882
|
init_mime();
|
|
@@ -1717,11 +1888,31 @@ var init_client = __esm({
|
|
|
1717
1888
|
uploaderInstance = null;
|
|
1718
1889
|
downloaderInstance = null;
|
|
1719
1890
|
rootFolderId;
|
|
1891
|
+
pluginManager = new PluginManager();
|
|
1720
1892
|
constructor(options = {}) {
|
|
1721
1893
|
this.options = options;
|
|
1722
1894
|
this.rootFolderId = options.rootFolderId || "root";
|
|
1723
1895
|
this.authenticator = new DriveAuthenticator(options.auth);
|
|
1724
1896
|
}
|
|
1897
|
+
/**
|
|
1898
|
+
* Registers a middleware plugin into DriveKit lifecycle
|
|
1899
|
+
*/
|
|
1900
|
+
use(plugin) {
|
|
1901
|
+
this.pluginManager.use(plugin);
|
|
1902
|
+
return this;
|
|
1903
|
+
}
|
|
1904
|
+
/**
|
|
1905
|
+
* Returns a fluent, chained reference to a specific file
|
|
1906
|
+
*/
|
|
1907
|
+
file(pathOrId) {
|
|
1908
|
+
return new DriveFileRef(this, pathOrId);
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* Returns a fluent, chained reference to a specific folder
|
|
1912
|
+
*/
|
|
1913
|
+
folder(pathOrId) {
|
|
1914
|
+
return new DriveFolderRef(this, pathOrId);
|
|
1915
|
+
}
|
|
1725
1916
|
/**
|
|
1726
1917
|
* Initializes the Google Drive API client (lazy-loaded if not called explicitly)
|
|
1727
1918
|
*/
|
|
@@ -1830,21 +2021,23 @@ var init_client = __esm({
|
|
|
1830
2021
|
* - Real-time progress callback: % complete, transfer speed (MB/s), ETA
|
|
1831
2022
|
*/
|
|
1832
2023
|
async upload(options) {
|
|
2024
|
+
const opts = await this.pluginManager.runBeforeUpload(options);
|
|
1833
2025
|
const uploader = await this.getUploader();
|
|
1834
|
-
let parentId =
|
|
2026
|
+
let parentId = opts.parent;
|
|
1835
2027
|
if (parentId && parentId.startsWith("/")) {
|
|
1836
2028
|
parentId = await this.mkdirp(parentId);
|
|
1837
2029
|
}
|
|
1838
|
-
if (
|
|
1839
|
-
const existing = await this.query().inFolder(parentId).nameEquals(
|
|
2030
|
+
if (opts.overwrite && opts.name && parentId) {
|
|
2031
|
+
const existing = await this.query().inFolder(parentId).nameEquals(opts.name).notTrashed().first();
|
|
1840
2032
|
if (existing?.id) {
|
|
1841
2033
|
await this.delete(existing.id, true);
|
|
1842
2034
|
}
|
|
1843
2035
|
}
|
|
1844
|
-
|
|
1845
|
-
...
|
|
2036
|
+
const uploaded = await uploader.upload({
|
|
2037
|
+
...opts,
|
|
1846
2038
|
parent: parentId
|
|
1847
2039
|
});
|
|
2040
|
+
return await this.pluginManager.runAfterUpload(uploaded);
|
|
1848
2041
|
}
|
|
1849
2042
|
/**
|
|
1850
2043
|
* Downloads a file from Google Drive:
|
|
@@ -1854,8 +2047,10 @@ var init_client = __esm({
|
|
|
1854
2047
|
*/
|
|
1855
2048
|
async download(fileIdOrPath, options = {}) {
|
|
1856
2049
|
const fileId = await this.resolveId(fileIdOrPath);
|
|
2050
|
+
const processedOpts = await this.pluginManager.runBeforeDownload(fileId, options);
|
|
1857
2051
|
const downloader = await this.getDownloader();
|
|
1858
|
-
|
|
2052
|
+
const result = await downloader.download(fileId, processedOpts);
|
|
2053
|
+
return await this.pluginManager.runAfterDownload(result);
|
|
1859
2054
|
}
|
|
1860
2055
|
/**
|
|
1861
2056
|
* Gets file metadata
|
|
@@ -2282,12 +2477,168 @@ init_cjs_shims();
|
|
|
2282
2477
|
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
2283
2478
|
var import_node_path5 = __toESM(require("path"), 1);
|
|
2284
2479
|
var import_commander = require("commander");
|
|
2285
|
-
var
|
|
2480
|
+
var import_chalk2 = __toESM(require("chalk"), 1);
|
|
2286
2481
|
var import_ora = __toESM(require("ora"), 1);
|
|
2287
2482
|
init_client();
|
|
2288
2483
|
init_format();
|
|
2484
|
+
|
|
2485
|
+
// src/cli/terminal-ui.ts
|
|
2486
|
+
init_cjs_shims();
|
|
2487
|
+
var import_node_readline = __toESM(require("readline"), 1);
|
|
2488
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
2489
|
+
init_format();
|
|
2490
|
+
function terminalLink(text, url) {
|
|
2491
|
+
return `\x1B]8;;${url}\x07${text}\x1B]8;;\x07`;
|
|
2492
|
+
}
|
|
2493
|
+
function renderFileRow(item, index) {
|
|
2494
|
+
const isDir = item.mimeType === "application/vnd.google-apps.folder";
|
|
2495
|
+
const icon = isDir ? "\u{1F4C1}" : getFileIcon(item.mimeType || "");
|
|
2496
|
+
const prefix = index !== void 0 ? `${import_chalk.default.dim((index + 1).toString().padStart(2, " ") + ".")} ` : "";
|
|
2497
|
+
let nameFormatted = isDir ? import_chalk.default.bold.blue(item.name || "untitled") : import_chalk.default.white(item.name || "untitled");
|
|
2498
|
+
if (item.webViewLink) {
|
|
2499
|
+
nameFormatted = terminalLink(nameFormatted, item.webViewLink);
|
|
2500
|
+
}
|
|
2501
|
+
const sizeFormatted = item.size ? import_chalk.default.dim(`[${formatBytes(parseInt(item.size, 10)).padStart(9, " ")}]`) : import_chalk.default.dim(isDir ? "[ FOLDER ]" : "[ DOC ]");
|
|
2502
|
+
const idFormatted = import_chalk.default.dim(`ID: ${item.id}`);
|
|
2503
|
+
return `${prefix}${icon} ${nameFormatted.padEnd(45)} ${sizeFormatted} ${idFormatted}`;
|
|
2504
|
+
}
|
|
2505
|
+
function getFileIcon(mimeType) {
|
|
2506
|
+
if (mimeType.includes("pdf")) return "\u{1F4D5}";
|
|
2507
|
+
if (mimeType.includes("image")) return "\u{1F5BC}\uFE0F ";
|
|
2508
|
+
if (mimeType.includes("video")) return "\u{1F3AC}";
|
|
2509
|
+
if (mimeType.includes("audio")) return "\u{1F3B5}";
|
|
2510
|
+
if (mimeType.includes("zip") || mimeType.includes("compressed") || mimeType.includes("tar")) return "\u{1F4E6}";
|
|
2511
|
+
if (mimeType.includes("spreadsheet") || mimeType.includes("excel")) return "\u{1F4CA}";
|
|
2512
|
+
if (mimeType.includes("document") || mimeType.includes("word")) return "\u{1F4DD}";
|
|
2513
|
+
if (mimeType.includes("presentation")) return "\u{1F4FD}\uFE0F ";
|
|
2514
|
+
if (mimeType.includes("json") || mimeType.includes("javascript") || mimeType.includes("typescript")) return "\u2699\uFE0F ";
|
|
2515
|
+
return "\u{1F4C4}";
|
|
2516
|
+
}
|
|
2517
|
+
async function runInteractiveExplorer(client, initialFolder = "/") {
|
|
2518
|
+
let currentFolder = initialFolder;
|
|
2519
|
+
let items = [];
|
|
2520
|
+
let selectedIndex = 0;
|
|
2521
|
+
let history = [];
|
|
2522
|
+
const refreshItems = async () => {
|
|
2523
|
+
items = await client.ls(currentFolder);
|
|
2524
|
+
selectedIndex = Math.min(selectedIndex, Math.max(0, items.length - 1));
|
|
2525
|
+
};
|
|
2526
|
+
await refreshItems();
|
|
2527
|
+
if (!process.stdin.isTTY) {
|
|
2528
|
+
console.log(import_chalk.default.yellow("Interactive explorer requires a TTY terminal. Listing items instead:"));
|
|
2529
|
+
for (const item of items) {
|
|
2530
|
+
console.log(renderFileRow(item));
|
|
2531
|
+
}
|
|
2532
|
+
return;
|
|
2533
|
+
}
|
|
2534
|
+
import_node_readline.default.emitKeypressEvents(process.stdin);
|
|
2535
|
+
process.stdin.setRawMode(true);
|
|
2536
|
+
const renderScreen = () => {
|
|
2537
|
+
console.clear();
|
|
2538
|
+
console.log(import_chalk.default.bold.cyan("\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557"));
|
|
2539
|
+
console.log(import_chalk.default.bold.cyan("\u2551") + import_chalk.default.bold.yellow(" \u26A1 DriveKit Interactive Terminal Explorer ") + import_chalk.default.bold.cyan("\u2551"));
|
|
2540
|
+
console.log(import_chalk.default.bold.cyan("\u2560\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2563"));
|
|
2541
|
+
console.log(import_chalk.default.bold.cyan("\u2551") + ` \u{1F4C2} Path: ${import_chalk.default.bold.green(currentFolder.padEnd(72))} ` + import_chalk.default.bold.cyan("\u2551"));
|
|
2542
|
+
console.log(import_chalk.default.bold.cyan("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"));
|
|
2543
|
+
console.log(import_chalk.default.dim(" [\u2191/\u2193] Navigate \u2022 [Enter] Open Folder \u2022 [B] Back \u2022 [S] Share \u2022 [Q] Exit\n"));
|
|
2544
|
+
if (items.length === 0) {
|
|
2545
|
+
console.log(import_chalk.default.dim(" (This folder is empty)\n"));
|
|
2546
|
+
return;
|
|
2547
|
+
}
|
|
2548
|
+
const pageSize = 12;
|
|
2549
|
+
const startIdx = Math.max(0, Math.min(selectedIndex - Math.floor(pageSize / 2), items.length - pageSize));
|
|
2550
|
+
const endIdx = Math.min(items.length, startIdx + pageSize);
|
|
2551
|
+
for (let i = startIdx; i < endIdx; i++) {
|
|
2552
|
+
const isSelected = i === selectedIndex;
|
|
2553
|
+
const cursor = isSelected ? import_chalk.default.bold.cyan(" \u25BA ") : " ";
|
|
2554
|
+
const row = renderFileRow(items[i]);
|
|
2555
|
+
if (isSelected) {
|
|
2556
|
+
console.log(import_chalk.default.bgHex("#1e293b")(cursor + row));
|
|
2557
|
+
} else {
|
|
2558
|
+
console.log(cursor + row);
|
|
2559
|
+
}
|
|
2560
|
+
}
|
|
2561
|
+
console.log(import_chalk.default.dim(`
|
|
2562
|
+
Item ${selectedIndex + 1} of ${items.length}`));
|
|
2563
|
+
};
|
|
2564
|
+
renderScreen();
|
|
2565
|
+
return new Promise((resolve) => {
|
|
2566
|
+
const onKeypress = async (str, key) => {
|
|
2567
|
+
if (key.ctrl && key.name === "c") {
|
|
2568
|
+
cleanup();
|
|
2569
|
+
process.exit(0);
|
|
2570
|
+
}
|
|
2571
|
+
if (key.name === "q" || key.name === "escape" && history.length === 0) {
|
|
2572
|
+
cleanup();
|
|
2573
|
+
resolve();
|
|
2574
|
+
return;
|
|
2575
|
+
}
|
|
2576
|
+
if (key.name === "up") {
|
|
2577
|
+
selectedIndex = selectedIndex > 0 ? selectedIndex - 1 : items.length - 1;
|
|
2578
|
+
renderScreen();
|
|
2579
|
+
} else if (key.name === "down") {
|
|
2580
|
+
selectedIndex = selectedIndex < items.length - 1 ? selectedIndex + 1 : 0;
|
|
2581
|
+
renderScreen();
|
|
2582
|
+
} else if (key.name === "return") {
|
|
2583
|
+
const item = items[selectedIndex];
|
|
2584
|
+
if (item && item.mimeType === "application/vnd.google-apps.folder") {
|
|
2585
|
+
history.push(currentFolder);
|
|
2586
|
+
currentFolder = currentFolder === "/" ? `/${item.name}` : `${currentFolder}/${item.name}`;
|
|
2587
|
+
selectedIndex = 0;
|
|
2588
|
+
await refreshItems();
|
|
2589
|
+
renderScreen();
|
|
2590
|
+
} else if (item && item.webViewLink) {
|
|
2591
|
+
const { exec: exec2 } = await import("child_process");
|
|
2592
|
+
const openCmd = process.platform === "darwin" ? `open "${item.webViewLink}"` : `xdg-open "${item.webViewLink}"`;
|
|
2593
|
+
exec2(openCmd);
|
|
2594
|
+
renderScreen();
|
|
2595
|
+
}
|
|
2596
|
+
} else if (key.name === "b" || key.name === "backspace") {
|
|
2597
|
+
if (history.length > 0) {
|
|
2598
|
+
currentFolder = history.pop();
|
|
2599
|
+
selectedIndex = 0;
|
|
2600
|
+
await refreshItems();
|
|
2601
|
+
renderScreen();
|
|
2602
|
+
}
|
|
2603
|
+
} else if (str === "s" || str === "S") {
|
|
2604
|
+
const item = items[selectedIndex];
|
|
2605
|
+
if (item && item.id) {
|
|
2606
|
+
process.stdin.pause();
|
|
2607
|
+
console.log(`
|
|
2608
|
+
|
|
2609
|
+
${import_chalk.default.cyan("\u{1F517} Getting shareable link for:")} ${import_chalk.default.bold(item.name)}...`);
|
|
2610
|
+
try {
|
|
2611
|
+
const links = await client.sharePublic(item.id);
|
|
2612
|
+
console.log(`Preview URL: ${import_chalk.default.underline(links.previewLink)}`);
|
|
2613
|
+
console.log(`Direct Download URL: ${import_chalk.default.underline(links.directDownloadLink)}`);
|
|
2614
|
+
console.log(import_chalk.default.dim("\nPress any key to return to explorer..."));
|
|
2615
|
+
process.stdin.resume();
|
|
2616
|
+
process.stdin.once("data", () => {
|
|
2617
|
+
renderScreen();
|
|
2618
|
+
});
|
|
2619
|
+
} catch (err) {
|
|
2620
|
+
console.error(import_chalk.default.red(`Failed to share: ${err.message}`));
|
|
2621
|
+
setTimeout(renderScreen, 2e3);
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
};
|
|
2626
|
+
const cleanup = () => {
|
|
2627
|
+
process.stdin.removeListener("keypress", onKeypress);
|
|
2628
|
+
if (process.stdin.setRawMode) {
|
|
2629
|
+
process.stdin.setRawMode(false);
|
|
2630
|
+
}
|
|
2631
|
+
process.stdin.pause();
|
|
2632
|
+
console.clear();
|
|
2633
|
+
console.log(import_chalk.default.green("\u{1F44B} Exited DriveKit explorer."));
|
|
2634
|
+
};
|
|
2635
|
+
process.stdin.on("keypress", onKeypress);
|
|
2636
|
+
});
|
|
2637
|
+
}
|
|
2638
|
+
|
|
2639
|
+
// src/cli.ts
|
|
2289
2640
|
var program = new import_commander.Command();
|
|
2290
|
-
program.name("drivekit").description(
|
|
2641
|
+
program.name("drivekit").description(import_chalk2.default.bold.cyan("\u26A1 DriveKit CLI: High-speed, flexible Google Drive tool for developers")).version("1.0.0").option("-k, --key <path>", "Path to service account JSON key file").option("-t, --token <token>", "Google OAuth2 Bearer access token");
|
|
2291
2642
|
function getAuthConfig(cmdOptions) {
|
|
2292
2643
|
const keyFilePath = cmdOptions.key || process.env.GOOGLE_APPLICATION_CREDENTIALS || process.env.GDRIVE_SERVICE_ACCOUNT_PATH;
|
|
2293
2644
|
const accessToken = cmdOptions.token || process.env.GDRIVE_ACCESS_TOKEN;
|
|
@@ -2310,19 +2661,19 @@ program.command("quota").description("Show Google Drive storage usage & quota").
|
|
|
2310
2661
|
const client = await getClient(options);
|
|
2311
2662
|
const quota = await client.getStorageQuota();
|
|
2312
2663
|
spinner.stop();
|
|
2313
|
-
console.log(
|
|
2664
|
+
console.log(import_chalk2.default.bold.cyan("\n\u{1F4CA} Google Drive Storage Quota:"));
|
|
2314
2665
|
if (quota.user?.displayName) {
|
|
2315
|
-
console.log(`\u{1F464} User: ${
|
|
2666
|
+
console.log(`\u{1F464} User: ${import_chalk2.default.yellow(quota.user.displayName)} (${quota.user.emailAddress})`);
|
|
2316
2667
|
}
|
|
2317
|
-
console.log(`\u{1F4BE} Total Usage: ${
|
|
2668
|
+
console.log(`\u{1F4BE} Total Usage: ${import_chalk2.default.green(quota.formattedUsage)} / ${import_chalk2.default.blue(quota.formattedLimit)}`);
|
|
2318
2669
|
if (quota.percentUsed !== null) {
|
|
2319
|
-
console.log(`\u{1F4C8} Usage %: ${
|
|
2670
|
+
console.log(`\u{1F4C8} Usage %: ${import_chalk2.default.bold(quota.percentUsed + "%")}`);
|
|
2320
2671
|
}
|
|
2321
2672
|
console.log(`\u{1F4C1} In Drive: ${formatBytes(quota.usageInDrive)}`);
|
|
2322
2673
|
console.log(`\u{1F5D1}\uFE0F In Trash: ${formatBytes(quota.usageInDriveTrash)}
|
|
2323
2674
|
`);
|
|
2324
2675
|
} catch (err) {
|
|
2325
|
-
spinner.fail(
|
|
2676
|
+
spinner.fail(import_chalk2.default.red(`Failed to fetch quota: ${err.message}`));
|
|
2326
2677
|
process.exit(1);
|
|
2327
2678
|
}
|
|
2328
2679
|
});
|
|
@@ -2333,31 +2684,35 @@ program.command("ls [folder]").description("List files and folders (by virtual p
|
|
|
2333
2684
|
const items = await client.ls(folder);
|
|
2334
2685
|
spinner.stop();
|
|
2335
2686
|
if (items.length === 0) {
|
|
2336
|
-
console.log(
|
|
2687
|
+
console.log(import_chalk2.default.dim(`(Folder ${folder} is empty)`));
|
|
2337
2688
|
return;
|
|
2338
2689
|
}
|
|
2339
|
-
console.log(
|
|
2690
|
+
console.log(import_chalk2.default.bold.cyan(`
|
|
2340
2691
|
\u{1F4C1} Contents of "${folder}":
|
|
2341
2692
|
`));
|
|
2342
|
-
for (
|
|
2343
|
-
|
|
2344
|
-
const icon = isDir ? "\u{1F4C1}" : "\u{1F4C4}";
|
|
2345
|
-
const nameFormatted = isDir ? import_chalk.default.bold.blue(item.name) : import_chalk.default.white(item.name);
|
|
2346
|
-
const sizeFormatted = item.size ? import_chalk.default.dim(`[${formatBytes(parseInt(item.size, 10))}]`) : import_chalk.default.dim(isDir ? "[DIR]" : "[Google Doc]");
|
|
2347
|
-
const idFormatted = import_chalk.default.dim(`(ID: ${item.id})`);
|
|
2348
|
-
console.log(` ${icon} ${nameFormatted.padEnd(40)} ${sizeFormatted.padEnd(16)} ${idFormatted}`);
|
|
2693
|
+
for (let i = 0; i < items.length; i++) {
|
|
2694
|
+
console.log(renderFileRow(items[i], i));
|
|
2349
2695
|
}
|
|
2350
2696
|
console.log(`
|
|
2351
|
-
Total items: ${
|
|
2697
|
+
Total items: ${import_chalk2.default.green(items.length)}
|
|
2352
2698
|
`);
|
|
2353
2699
|
} catch (err) {
|
|
2354
|
-
spinner.fail(
|
|
2700
|
+
spinner.fail(import_chalk2.default.red(`Failed to list items: ${err.message}`));
|
|
2701
|
+
process.exit(1);
|
|
2702
|
+
}
|
|
2703
|
+
});
|
|
2704
|
+
program.command("explore [folder]").description("Interactive terminal keyboard file explorer (TUI) for Google Drive").action(async (folder = "/", options) => {
|
|
2705
|
+
try {
|
|
2706
|
+
const client = await getClient(options);
|
|
2707
|
+
await runInteractiveExplorer(client, folder);
|
|
2708
|
+
} catch (err) {
|
|
2709
|
+
console.error(import_chalk2.default.red(`Explorer failed: ${err.message}`));
|
|
2355
2710
|
process.exit(1);
|
|
2356
2711
|
}
|
|
2357
2712
|
});
|
|
2358
2713
|
program.command("upload <localFile> [remotePath]").description("Upload a file with high speed and live progress tracking").option("-o, --overwrite", "Overwrite remote file if it exists").action(async (localFile, remotePath = "/", options) => {
|
|
2359
2714
|
if (!import_node_fs6.default.existsSync(localFile)) {
|
|
2360
|
-
console.error(
|
|
2715
|
+
console.error(import_chalk2.default.red(`\u274C Local file not found: ${localFile}`));
|
|
2361
2716
|
process.exit(1);
|
|
2362
2717
|
}
|
|
2363
2718
|
const fileName = import_node_path5.default.basename(localFile);
|
|
@@ -2373,22 +2728,22 @@ program.command("upload <localFile> [remotePath]").description("Upload a file wi
|
|
|
2373
2728
|
overwrite: options.overwrite,
|
|
2374
2729
|
onProgress: (p) => {
|
|
2375
2730
|
process.stdout.write(
|
|
2376
|
-
`\r\u{1F680} Uploading: ${
|
|
2731
|
+
`\r\u{1F680} Uploading: ${import_chalk2.default.cyan(p.percentage + "%")} | Speed: ${import_chalk2.default.green(p.speedFormatted)} | ETA: ${import_chalk2.default.yellow(p.estimatedTimeRemainingSeconds + "s")} [${formatBytes(p.bytesSent)} / ${formatBytes(p.totalBytes)}]`
|
|
2377
2732
|
);
|
|
2378
2733
|
}
|
|
2379
2734
|
});
|
|
2380
2735
|
process.stdout.write("\n");
|
|
2381
2736
|
const durationSecs = ((Date.now() - startTime) / 1e3).toFixed(1);
|
|
2382
|
-
console.log(
|
|
2737
|
+
console.log(import_chalk2.default.green(`
|
|
2383
2738
|
\u2705 Upload completed successfully in ${durationSecs}s!`));
|
|
2384
|
-
console.log(`\u{1F4C4} Name: ${
|
|
2385
|
-
console.log(`\u{1F194} ID: ${
|
|
2739
|
+
console.log(`\u{1F4C4} Name: ${import_chalk2.default.bold(res.name)}`);
|
|
2740
|
+
console.log(`\u{1F194} ID: ${import_chalk2.default.cyan(res.id)}`);
|
|
2386
2741
|
if (res.webViewLink) {
|
|
2387
|
-
console.log(`\u{1F517} Link: ${
|
|
2742
|
+
console.log(`\u{1F517} Link: ${import_chalk2.default.underline(res.webViewLink)}`);
|
|
2388
2743
|
}
|
|
2389
2744
|
console.log("");
|
|
2390
2745
|
} catch (err) {
|
|
2391
|
-
spinner.fail(
|
|
2746
|
+
spinner.fail(import_chalk2.default.red(`Upload failed: ${err.message}`));
|
|
2392
2747
|
process.exit(1);
|
|
2393
2748
|
}
|
|
2394
2749
|
});
|
|
@@ -2402,20 +2757,20 @@ program.command("download <fileIdOrPath> [destination]").description("Download a
|
|
|
2402
2757
|
onProgress: (p) => {
|
|
2403
2758
|
const pct = p.percentage !== void 0 ? `${p.percentage}%` : `${formatBytes(p.bytesRead)}`;
|
|
2404
2759
|
process.stdout.write(
|
|
2405
|
-
`\r\u2B07\uFE0F Downloading: ${
|
|
2760
|
+
`\r\u2B07\uFE0F Downloading: ${import_chalk2.default.cyan(pct)} | Speed: ${import_chalk2.default.green(p.speedFormatted)}`
|
|
2406
2761
|
);
|
|
2407
2762
|
}
|
|
2408
2763
|
});
|
|
2409
2764
|
process.stdout.write("\n");
|
|
2410
|
-
console.log(
|
|
2765
|
+
console.log(import_chalk2.default.green(`
|
|
2411
2766
|
\u2705 Download completed!`));
|
|
2412
|
-
console.log(`\u{1F4C2} Saved to: ${
|
|
2767
|
+
console.log(`\u{1F4C2} Saved to: ${import_chalk2.default.bold(res.filePath)}`);
|
|
2413
2768
|
if (res.size) {
|
|
2414
2769
|
console.log(`\u{1F4E6} Size: ${formatBytes(res.size)}`);
|
|
2415
2770
|
}
|
|
2416
2771
|
console.log("");
|
|
2417
2772
|
} catch (err) {
|
|
2418
|
-
spinner.fail(
|
|
2773
|
+
spinner.fail(import_chalk2.default.red(`Download failed: ${err.message}`));
|
|
2419
2774
|
process.exit(1);
|
|
2420
2775
|
}
|
|
2421
2776
|
});
|
|
@@ -2429,16 +2784,16 @@ program.command("share <fileIdOrPath> [email]").description("Share file publicly
|
|
|
2429
2784
|
type: "user",
|
|
2430
2785
|
emailAddress: email
|
|
2431
2786
|
});
|
|
2432
|
-
spinner.succeed(
|
|
2787
|
+
spinner.succeed(import_chalk2.default.green(`File shared with ${email} as reader!`));
|
|
2433
2788
|
} else {
|
|
2434
2789
|
const links = await client.sharePublic(fileIdOrPath);
|
|
2435
|
-
spinner.succeed(
|
|
2436
|
-
console.log(`\u{1F517} Preview Link: ${
|
|
2437
|
-
console.log(`\u{1F4E5} Direct Download Link: ${
|
|
2790
|
+
spinner.succeed(import_chalk2.default.green(`File is now publicly accessible to anyone with the link!`));
|
|
2791
|
+
console.log(`\u{1F517} Preview Link: ${import_chalk2.default.underline(links.previewLink)}`);
|
|
2792
|
+
console.log(`\u{1F4E5} Direct Download Link: ${import_chalk2.default.underline(links.directDownloadLink)}
|
|
2438
2793
|
`);
|
|
2439
2794
|
}
|
|
2440
2795
|
} catch (err) {
|
|
2441
|
-
spinner.fail(
|
|
2796
|
+
spinner.fail(import_chalk2.default.red(`Sharing failed: ${err.message}`));
|
|
2442
2797
|
process.exit(1);
|
|
2443
2798
|
}
|
|
2444
2799
|
});
|
|
@@ -2448,19 +2803,19 @@ program.command("delete <fileIdOrPath>").description("Move a file/folder to tras
|
|
|
2448
2803
|
try {
|
|
2449
2804
|
const client = await getClient(options);
|
|
2450
2805
|
await client.delete(fileIdOrPath, options.permanent);
|
|
2451
|
-
spinner.succeed(
|
|
2806
|
+
spinner.succeed(import_chalk2.default.green(`Success! ${fileIdOrPath} has been ${options.permanent ? "permanently deleted" : "moved to trash"}.`));
|
|
2452
2807
|
} catch (err) {
|
|
2453
|
-
spinner.fail(
|
|
2808
|
+
spinner.fail(import_chalk2.default.red(`Failed: ${err.message}`));
|
|
2454
2809
|
process.exit(1);
|
|
2455
2810
|
}
|
|
2456
2811
|
});
|
|
2457
2812
|
program.command("sync <localDir> <remoteFolder>").description("Sync a local directory to Google Drive recursively with high concurrency").option("-c, --concurrency <number>", "Number of parallel uploads", "4").option("-o, --overwrite", "Overwrite files if they already exist").action(async (localDir, remoteFolder, options) => {
|
|
2458
2813
|
if (!import_node_fs6.default.existsSync(localDir)) {
|
|
2459
|
-
console.error(
|
|
2814
|
+
console.error(import_chalk2.default.red(`\u274C Local directory not found: ${localDir}`));
|
|
2460
2815
|
process.exit(1);
|
|
2461
2816
|
}
|
|
2462
2817
|
const concurrency = parseInt(options.concurrency, 10) || 4;
|
|
2463
|
-
console.log(
|
|
2818
|
+
console.log(import_chalk2.default.bold.cyan(`
|
|
2464
2819
|
\u26A1 Starting recursive sync:`));
|
|
2465
2820
|
console.log(`\u{1F4C2} Local: ${localDir}`);
|
|
2466
2821
|
console.log(`\u2601\uFE0F Remote: ${remoteFolder}`);
|
|
@@ -2474,30 +2829,30 @@ program.command("sync <localDir> <remoteFolder>").description("Sync a local dire
|
|
|
2474
2829
|
concurrency,
|
|
2475
2830
|
overwrite: options.overwrite,
|
|
2476
2831
|
onFileStart: (_, rel) => {
|
|
2477
|
-
console.log(` \u2B06\uFE0F Uploading: ${
|
|
2832
|
+
console.log(` \u2B06\uFE0F Uploading: ${import_chalk2.default.dim(rel)}`);
|
|
2478
2833
|
},
|
|
2479
2834
|
onFileComplete: (_, fileId) => {
|
|
2480
|
-
console.log(` ${
|
|
2835
|
+
console.log(` ${import_chalk2.default.green("\u2713 Completed")} ${import_chalk2.default.dim(`(ID: ${fileId})`)}`);
|
|
2481
2836
|
}
|
|
2482
2837
|
});
|
|
2483
|
-
console.log(
|
|
2838
|
+
console.log(import_chalk2.default.bold.green(`
|
|
2484
2839
|
\u{1F389} Sync Finished in ${(result.durationMs / 1e3).toFixed(1)}s!`));
|
|
2485
|
-
console.log(`\u2705 Uploaded: ${
|
|
2840
|
+
console.log(`\u2705 Uploaded: ${import_chalk2.default.green(result.uploaded.length)} files (${formatBytes(result.totalBytes)})`);
|
|
2486
2841
|
if (result.failed.length > 0) {
|
|
2487
|
-
console.log(`\u274C Failed: ${
|
|
2842
|
+
console.log(`\u274C Failed: ${import_chalk2.default.red(result.failed.length)} files`);
|
|
2488
2843
|
for (const f of result.failed) {
|
|
2489
|
-
console.log(` - ${f.localPath}: ${
|
|
2844
|
+
console.log(` - ${f.localPath}: ${import_chalk2.default.red(f.error.message)}`);
|
|
2490
2845
|
}
|
|
2491
2846
|
}
|
|
2492
2847
|
console.log("");
|
|
2493
2848
|
} catch (err) {
|
|
2494
|
-
spinner.fail(
|
|
2849
|
+
spinner.fail(import_chalk2.default.red(`Sync failed: ${err.message}`));
|
|
2495
2850
|
process.exit(1);
|
|
2496
2851
|
}
|
|
2497
2852
|
});
|
|
2498
2853
|
program.command("pull <remoteFolder> <localDir>").description("Download an entire remote Google Drive folder down to local directory with MD5 deduplication").option("-c, --concurrency <number>", "Parallel downloads", "4").option("-o, --overwrite", "Overwrite local files even if identical").action(async (remoteFolder, localDir, options) => {
|
|
2499
2854
|
const concurrency = parseInt(options.concurrency, 10) || 4;
|
|
2500
|
-
console.log(
|
|
2855
|
+
console.log(import_chalk2.default.bold.cyan(`
|
|
2501
2856
|
\u2B07\uFE0F Starting smart pull:`));
|
|
2502
2857
|
console.log(`\u2601\uFE0F Remote: ${remoteFolder}`);
|
|
2503
2858
|
console.log(`\u{1F4C2} Local: ${localDir}`);
|
|
@@ -2511,24 +2866,24 @@ program.command("pull <remoteFolder> <localDir>").description("Download an entir
|
|
|
2511
2866
|
concurrency,
|
|
2512
2867
|
overwrite: options.overwrite,
|
|
2513
2868
|
onFileStart: (name, rel) => {
|
|
2514
|
-
console.log(` \u2B07\uFE0F Downloading: ${
|
|
2869
|
+
console.log(` \u2B07\uFE0F Downloading: ${import_chalk2.default.dim(rel)}`);
|
|
2515
2870
|
},
|
|
2516
2871
|
onFileComplete: (name) => {
|
|
2517
|
-
console.log(` ${
|
|
2872
|
+
console.log(` ${import_chalk2.default.green("\u2713 Saved")} ${name}`);
|
|
2518
2873
|
}
|
|
2519
2874
|
});
|
|
2520
|
-
console.log(
|
|
2875
|
+
console.log(import_chalk2.default.bold.green(`
|
|
2521
2876
|
\u{1F389} Pull Finished in ${(result.durationMs / 1e3).toFixed(1)}s!`));
|
|
2522
|
-
console.log(`\u2705 Downloaded: ${
|
|
2877
|
+
console.log(`\u2705 Downloaded: ${import_chalk2.default.green(result.downloaded.length)} files (${formatBytes(result.totalBytes)})`);
|
|
2523
2878
|
if (result.skipped.length > 0) {
|
|
2524
|
-
console.log(`\u23ED\uFE0F Skipped: ${
|
|
2879
|
+
console.log(`\u23ED\uFE0F Skipped: ${import_chalk2.default.yellow(result.skipped.length)} identical files`);
|
|
2525
2880
|
}
|
|
2526
2881
|
if (result.failed.length > 0) {
|
|
2527
|
-
console.log(`\u274C Failed: ${
|
|
2882
|
+
console.log(`\u274C Failed: ${import_chalk2.default.red(result.failed.length)} files`);
|
|
2528
2883
|
}
|
|
2529
2884
|
console.log("");
|
|
2530
2885
|
} catch (err) {
|
|
2531
|
-
spinner.fail(
|
|
2886
|
+
spinner.fail(import_chalk2.default.red(`Pull failed: ${err.message}`));
|
|
2532
2887
|
process.exit(1);
|
|
2533
2888
|
}
|
|
2534
2889
|
});
|
|
@@ -2538,7 +2893,7 @@ program.command("clean").description("Storage management: find largest files, de
|
|
|
2538
2893
|
if (options.emptyTrash) {
|
|
2539
2894
|
const spinner2 = (0, import_ora.default)("Emptying trash bin...").start();
|
|
2540
2895
|
await client.emptyTrash();
|
|
2541
|
-
spinner2.succeed(
|
|
2896
|
+
spinner2.succeed(import_chalk2.default.green("Trash bin emptied successfully!"));
|
|
2542
2897
|
return;
|
|
2543
2898
|
}
|
|
2544
2899
|
if (options.duplicates) {
|
|
@@ -2546,16 +2901,16 @@ program.command("clean").description("Storage management: find largest files, de
|
|
|
2546
2901
|
const duplicates = await client.findDuplicates({ by: "name" });
|
|
2547
2902
|
spinner2.stop();
|
|
2548
2903
|
if (duplicates.length === 0) {
|
|
2549
|
-
console.log(
|
|
2904
|
+
console.log(import_chalk2.default.green("\n\u2728 No duplicate files found!"));
|
|
2550
2905
|
return;
|
|
2551
2906
|
}
|
|
2552
|
-
console.log(
|
|
2907
|
+
console.log(import_chalk2.default.bold.yellow(`
|
|
2553
2908
|
\u26A0\uFE0F Found ${duplicates.length} duplicate groups:
|
|
2554
2909
|
`));
|
|
2555
2910
|
for (const g of duplicates) {
|
|
2556
|
-
console.log(`\u{1F4C4} "${
|
|
2911
|
+
console.log(`\u{1F4C4} "${import_chalk2.default.bold(g.name)}" (${import_chalk2.default.cyan(g.count + " copies")} - total: ${import_chalk2.default.magenta(g.formattedTotalSize)})`);
|
|
2557
2912
|
for (const f of g.files) {
|
|
2558
|
-
console.log(` - ID: ${
|
|
2913
|
+
console.log(` - ID: ${import_chalk2.default.dim(f.id)} [${formatBytes(f.size)}] modified: ${import_chalk2.default.dim(f.modifiedTime || "unknown")}`);
|
|
2559
2914
|
}
|
|
2560
2915
|
}
|
|
2561
2916
|
console.log("");
|
|
@@ -2565,51 +2920,51 @@ program.command("clean").description("Storage management: find largest files, de
|
|
|
2565
2920
|
const spinner = (0, import_ora.default)(`Finding top ${limit} largest files...`).start();
|
|
2566
2921
|
const largest = await client.findLargestFiles(limit);
|
|
2567
2922
|
spinner.stop();
|
|
2568
|
-
console.log(
|
|
2923
|
+
console.log(import_chalk2.default.bold.cyan(`
|
|
2569
2924
|
\u{1F4CA} Top ${largest.length} Largest Files in Drive:
|
|
2570
2925
|
`));
|
|
2571
2926
|
for (let i = 0; i < largest.length; i++) {
|
|
2572
2927
|
const f = largest[i];
|
|
2573
|
-
console.log(` ${
|
|
2928
|
+
console.log(` ${import_chalk2.default.bold(i + 1 + ".")} ${import_chalk2.default.white(f.name.padEnd(35))} ${import_chalk2.default.green(f.formattedSize.padEnd(12))} ID: ${import_chalk2.default.dim(f.id)}`);
|
|
2574
2929
|
}
|
|
2575
2930
|
console.log("");
|
|
2576
2931
|
} catch (err) {
|
|
2577
|
-
console.error(
|
|
2932
|
+
console.error(import_chalk2.default.red(`Clean operation failed: ${err.message}`));
|
|
2578
2933
|
process.exit(1);
|
|
2579
2934
|
}
|
|
2580
2935
|
});
|
|
2581
2936
|
program.command("watch [folder]").description("Watch Google Drive or a specific folder for real-time changes").option("-i, --interval <ms>", "Polling interval in milliseconds", "5000").action(async (folder = "/", options) => {
|
|
2582
2937
|
const intervalMs = parseInt(options.interval, 10) || 5e3;
|
|
2583
|
-
console.log(
|
|
2938
|
+
console.log(import_chalk2.default.bold.cyan(`
|
|
2584
2939
|
\u{1F440} Watching for changes in "${folder}" (polling every ${intervalMs / 1e3}s)...`));
|
|
2585
|
-
console.log(
|
|
2940
|
+
console.log(import_chalk2.default.dim("Press Ctrl+C to stop watching.\n"));
|
|
2586
2941
|
try {
|
|
2587
2942
|
const client = await getClient(options);
|
|
2588
2943
|
const watcher = await client.watch(folder === "/" ? void 0 : folder, { intervalMs });
|
|
2589
2944
|
watcher.on("create", (e) => {
|
|
2590
|
-
console.log(`${
|
|
2945
|
+
console.log(`${import_chalk2.default.green("[CREATED]")} ${import_chalk2.default.bold(e.file?.name || e.fileId)} ${import_chalk2.default.dim(`(ID: ${e.fileId})`)}`);
|
|
2591
2946
|
});
|
|
2592
2947
|
watcher.on("modify", (e) => {
|
|
2593
|
-
console.log(`${
|
|
2948
|
+
console.log(`${import_chalk2.default.yellow("[MODIFIED]")} ${import_chalk2.default.bold(e.file?.name || e.fileId)} ${import_chalk2.default.dim(`(ID: ${e.fileId})`)}`);
|
|
2594
2949
|
});
|
|
2595
2950
|
watcher.on("delete", (e) => {
|
|
2596
|
-
console.log(`${
|
|
2951
|
+
console.log(`${import_chalk2.default.red("[DELETED]")} ${import_chalk2.default.bold(e.file?.name || e.fileId)} ${import_chalk2.default.dim(`(ID: ${e.fileId})`)}`);
|
|
2597
2952
|
});
|
|
2598
2953
|
watcher.on("error", (err) => {
|
|
2599
|
-
console.error(
|
|
2954
|
+
console.error(import_chalk2.default.red(`[WATCHER ERROR] ${err.message}`));
|
|
2600
2955
|
});
|
|
2601
2956
|
process.on("SIGINT", () => {
|
|
2602
2957
|
watcher.stop();
|
|
2603
|
-
console.log(
|
|
2958
|
+
console.log(import_chalk2.default.yellow("\nWatcher stopped. Goodbye!"));
|
|
2604
2959
|
process.exit(0);
|
|
2605
2960
|
});
|
|
2606
2961
|
} catch (err) {
|
|
2607
|
-
console.error(
|
|
2962
|
+
console.error(import_chalk2.default.red(`Failed to start watcher: ${err.message}`));
|
|
2608
2963
|
process.exit(1);
|
|
2609
2964
|
}
|
|
2610
2965
|
});
|
|
2611
2966
|
program.command("login").description("Interactive 1-click browser OAuth2 sign-in").requiredOption("--client-id <id>", "Google OAuth2 Client ID").requiredOption("--client-secret <secret>", "Google OAuth2 Client Secret").option("-p, --port <port>", "Local callback port", "3000").action(async (options) => {
|
|
2612
|
-
console.log(
|
|
2967
|
+
console.log(import_chalk2.default.bold.cyan("\n\u26A1 DriveKit Interactive Login"));
|
|
2613
2968
|
console.log("Opening your browser for one-click Google OAuth sign-in...\n");
|
|
2614
2969
|
try {
|
|
2615
2970
|
const { DriveKit: DriveKit2 } = await Promise.resolve().then(() => (init_client(), client_exports));
|
|
@@ -2618,17 +2973,17 @@ program.command("login").description("Interactive 1-click browser OAuth2 sign-in
|
|
|
2618
2973
|
clientSecret: options.clientSecret,
|
|
2619
2974
|
port: parseInt(options.port, 10) || 3e3
|
|
2620
2975
|
});
|
|
2621
|
-
console.log(
|
|
2622
|
-
console.log(`Access Token: ${
|
|
2976
|
+
console.log(import_chalk2.default.bold.green("\n\u{1F389} Login successful!"));
|
|
2977
|
+
console.log(`Access Token: ${import_chalk2.default.cyan(result.tokens.access_token?.slice(0, 25) + "...")}`);
|
|
2623
2978
|
if (result.tokens.refresh_token) {
|
|
2624
|
-
console.log(`Refresh Token: ${
|
|
2979
|
+
console.log(`Refresh Token: ${import_chalk2.default.green(result.tokens.refresh_token?.slice(0, 25) + "...")}`);
|
|
2625
2980
|
}
|
|
2626
2981
|
const outPath = import_node_path5.default.resolve("./gdrive-tokens.json");
|
|
2627
2982
|
import_node_fs6.default.writeFileSync(outPath, JSON.stringify(result.tokens, null, 2), "utf8");
|
|
2628
|
-
console.log(`\u{1F4BE} Saved tokens to: ${
|
|
2983
|
+
console.log(`\u{1F4BE} Saved tokens to: ${import_chalk2.default.bold(outPath)}
|
|
2629
2984
|
`);
|
|
2630
2985
|
} catch (err) {
|
|
2631
|
-
console.error(
|
|
2986
|
+
console.error(import_chalk2.default.red(`Login failed: ${err.message}`));
|
|
2632
2987
|
process.exit(1);
|
|
2633
2988
|
}
|
|
2634
2989
|
});
|