drivekit 1.0.1 → 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 +2 -10
package/dist/index.cjs
CHANGED
|
@@ -37,6 +37,8 @@ __export(index_exports, {
|
|
|
37
37
|
Downloader: () => Downloader,
|
|
38
38
|
DriveAuthError: () => DriveAuthError,
|
|
39
39
|
DriveAuthenticator: () => DriveAuthenticator,
|
|
40
|
+
DriveFileRef: () => DriveFileRef,
|
|
41
|
+
DriveFolderRef: () => DriveFolderRef,
|
|
40
42
|
DriveKit: () => DriveKit,
|
|
41
43
|
DriveKitError: () => DriveKitError,
|
|
42
44
|
DriveNotFoundError: () => DriveNotFoundError,
|
|
@@ -48,6 +50,7 @@ __export(index_exports, {
|
|
|
48
50
|
MIN_CHUNK_SIZE: () => MIN_CHUNK_SIZE,
|
|
49
51
|
MULTIPART_THRESHOLD: () => MULTIPART_THRESHOLD,
|
|
50
52
|
PathResolver: () => PathResolver,
|
|
53
|
+
PluginManager: () => PluginManager,
|
|
51
54
|
ResumableUploader: () => ResumableUploader,
|
|
52
55
|
SmartSyncEngine: () => SmartSyncEngine,
|
|
53
56
|
StorageCleaner: () => StorageCleaner,
|
|
@@ -58,10 +61,14 @@ __export(index_exports, {
|
|
|
58
61
|
formatDuration: () => formatDuration,
|
|
59
62
|
formatSpeed: () => formatSpeed,
|
|
60
63
|
getExtensionForMime: () => getExtensionForMime,
|
|
64
|
+
getFileIcon: () => getFileIcon,
|
|
61
65
|
isGoogleWorkspaceDoc: () => isGoogleWorkspaceDoc,
|
|
62
66
|
isRetryableError: () => isRetryableError,
|
|
63
67
|
loginWithBrowser: () => loginWithBrowser,
|
|
64
68
|
lookupMimeType: () => lookupMimeType,
|
|
69
|
+
renderFileRow: () => renderFileRow,
|
|
70
|
+
runInteractiveExplorer: () => runInteractiveExplorer,
|
|
71
|
+
terminalLink: () => terminalLink,
|
|
65
72
|
withRetry: () => withRetry
|
|
66
73
|
});
|
|
67
74
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -646,6 +653,9 @@ var ResumableUploader = class {
|
|
|
646
653
|
let chunkIndex = 0;
|
|
647
654
|
try {
|
|
648
655
|
while (bytesSent < totalBytes) {
|
|
656
|
+
if (options.signal?.aborted) {
|
|
657
|
+
throw new Error("Upload aborted by user signal");
|
|
658
|
+
}
|
|
649
659
|
chunkIndex++;
|
|
650
660
|
const currentChunkSize = Math.min(chunkSize, totalBytes - bytesSent);
|
|
651
661
|
const buffer = Buffer.alloc(currentChunkSize);
|
|
@@ -706,6 +716,9 @@ var ResumableUploader = class {
|
|
|
706
716
|
const totalChunks = Math.ceil(totalBytes / chunkSize) || 1;
|
|
707
717
|
let chunkIndex = 0;
|
|
708
718
|
while (bytesSent < totalBytes) {
|
|
719
|
+
if (options.signal?.aborted) {
|
|
720
|
+
throw new Error("Upload aborted by user signal");
|
|
721
|
+
}
|
|
709
722
|
chunkIndex++;
|
|
710
723
|
const currentChunkSize = Math.min(chunkSize, totalBytes - bytesSent);
|
|
711
724
|
const chunk = buffer.subarray(bytesSent, bytesSent + currentChunkSize);
|
|
@@ -1614,6 +1627,155 @@ ${authUrl}
|
|
|
1614
1627
|
});
|
|
1615
1628
|
}
|
|
1616
1629
|
|
|
1630
|
+
// src/core/resource-refs.ts
|
|
1631
|
+
var DriveFileRef = class {
|
|
1632
|
+
drive;
|
|
1633
|
+
pathOrId;
|
|
1634
|
+
constructor(drive2, pathOrId) {
|
|
1635
|
+
this.drive = drive2;
|
|
1636
|
+
this.pathOrId = pathOrId;
|
|
1637
|
+
}
|
|
1638
|
+
/** Gets file metadata */
|
|
1639
|
+
async get() {
|
|
1640
|
+
return await this.drive.getFile(this.pathOrId);
|
|
1641
|
+
}
|
|
1642
|
+
/** Checks if the file exists */
|
|
1643
|
+
async exists() {
|
|
1644
|
+
return await this.drive.exists(this.pathOrId);
|
|
1645
|
+
}
|
|
1646
|
+
/** Reads file as UTF-8 string */
|
|
1647
|
+
async getText() {
|
|
1648
|
+
return await this.drive.getText(this.pathOrId);
|
|
1649
|
+
}
|
|
1650
|
+
/** Reads and parses JSON file */
|
|
1651
|
+
async getJson() {
|
|
1652
|
+
return await this.drive.getJson(this.pathOrId);
|
|
1653
|
+
}
|
|
1654
|
+
/** Downloads the file to destination */
|
|
1655
|
+
async download(optionsOrDestination) {
|
|
1656
|
+
const opts = typeof optionsOrDestination === "string" ? { destination: optionsOrDestination } : optionsOrDestination;
|
|
1657
|
+
return await this.drive.download(this.pathOrId, opts);
|
|
1658
|
+
}
|
|
1659
|
+
/** Moves the file to a new folder path or ID */
|
|
1660
|
+
async moveTo(newParentPathOrId) {
|
|
1661
|
+
return await this.drive.move(this.pathOrId, newParentPathOrId);
|
|
1662
|
+
}
|
|
1663
|
+
/** Copies the file to a target directory */
|
|
1664
|
+
async copyTo(parentPathOrId, newName) {
|
|
1665
|
+
return await this.drive.copy(this.pathOrId, { parent: parentPathOrId, name: newName });
|
|
1666
|
+
}
|
|
1667
|
+
/** Renames the file */
|
|
1668
|
+
async rename(newName) {
|
|
1669
|
+
return await this.drive.rename(this.pathOrId, newName);
|
|
1670
|
+
}
|
|
1671
|
+
/** Deletes the file (or moves to trash if permanent is false) */
|
|
1672
|
+
async delete(permanent = false) {
|
|
1673
|
+
return await this.drive.delete(this.pathOrId, permanent);
|
|
1674
|
+
}
|
|
1675
|
+
/** Moves file to trash */
|
|
1676
|
+
async trash() {
|
|
1677
|
+
return await this.drive.trash(this.pathOrId);
|
|
1678
|
+
}
|
|
1679
|
+
/** Shares file */
|
|
1680
|
+
async share(options) {
|
|
1681
|
+
return await this.drive.share(this.pathOrId, options);
|
|
1682
|
+
}
|
|
1683
|
+
/** Makes file publicly accessible */
|
|
1684
|
+
async sharePublic(role = "reader") {
|
|
1685
|
+
return await this.drive.sharePublic(this.pathOrId, role);
|
|
1686
|
+
}
|
|
1687
|
+
/** Gets public/preview links */
|
|
1688
|
+
async getLink() {
|
|
1689
|
+
return await this.drive.getShareableLink(this.pathOrId);
|
|
1690
|
+
}
|
|
1691
|
+
};
|
|
1692
|
+
var DriveFolderRef = class {
|
|
1693
|
+
drive;
|
|
1694
|
+
pathOrId;
|
|
1695
|
+
constructor(drive2, pathOrId) {
|
|
1696
|
+
this.drive = drive2;
|
|
1697
|
+
this.pathOrId = pathOrId;
|
|
1698
|
+
}
|
|
1699
|
+
/** Lists contents of this folder */
|
|
1700
|
+
async ls() {
|
|
1701
|
+
return await this.drive.ls(this.pathOrId);
|
|
1702
|
+
}
|
|
1703
|
+
/** Ensures this folder and subpaths exist (mkdir -p) */
|
|
1704
|
+
async mkdirp(subPath) {
|
|
1705
|
+
const target = subPath ? this.pathOrId.endsWith("/") ? `${this.pathOrId}${subPath}` : `${this.pathOrId}/${subPath}` : this.pathOrId;
|
|
1706
|
+
return await this.drive.mkdirp(target);
|
|
1707
|
+
}
|
|
1708
|
+
/** Uploads a file directly into this folder */
|
|
1709
|
+
async upload(source, options = {}) {
|
|
1710
|
+
return await this.drive.upload({
|
|
1711
|
+
...options,
|
|
1712
|
+
source,
|
|
1713
|
+
parent: this.pathOrId
|
|
1714
|
+
});
|
|
1715
|
+
}
|
|
1716
|
+
/** Synchronizes a local directory into this remote folder */
|
|
1717
|
+
async syncFrom(localDir, options = {}) {
|
|
1718
|
+
return await this.drive.syncFolder(localDir, this.pathOrId, options);
|
|
1719
|
+
}
|
|
1720
|
+
/** Pulls this remote folder down to local directory */
|
|
1721
|
+
async pullTo(localDestinationDir, options = {}) {
|
|
1722
|
+
return await this.drive.pull(this.pathOrId, localDestinationDir, options);
|
|
1723
|
+
}
|
|
1724
|
+
/** Watches this folder for real-time changes */
|
|
1725
|
+
async watch(options = {}) {
|
|
1726
|
+
return await this.drive.watch(this.pathOrId, options);
|
|
1727
|
+
}
|
|
1728
|
+
};
|
|
1729
|
+
|
|
1730
|
+
// src/core/plugins.ts
|
|
1731
|
+
var PluginManager = class {
|
|
1732
|
+
plugins = [];
|
|
1733
|
+
use(plugin) {
|
|
1734
|
+
this.plugins.push(plugin);
|
|
1735
|
+
return this;
|
|
1736
|
+
}
|
|
1737
|
+
async runBeforeUpload(options) {
|
|
1738
|
+
let current = { ...options };
|
|
1739
|
+
for (const plugin of this.plugins) {
|
|
1740
|
+
if (plugin.beforeUpload) {
|
|
1741
|
+
const modified = await plugin.beforeUpload(current);
|
|
1742
|
+
if (modified) current = modified;
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
return current;
|
|
1746
|
+
}
|
|
1747
|
+
async runAfterUpload(file) {
|
|
1748
|
+
let current = file;
|
|
1749
|
+
for (const plugin of this.plugins) {
|
|
1750
|
+
if (plugin.afterUpload) {
|
|
1751
|
+
const modified = await plugin.afterUpload(current);
|
|
1752
|
+
if (modified) current = modified;
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
return current;
|
|
1756
|
+
}
|
|
1757
|
+
async runBeforeDownload(fileId, options) {
|
|
1758
|
+
let current = { ...options };
|
|
1759
|
+
for (const plugin of this.plugins) {
|
|
1760
|
+
if (plugin.beforeDownload) {
|
|
1761
|
+
const modified = await plugin.beforeDownload(fileId, current);
|
|
1762
|
+
if (modified) current = modified;
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
return current;
|
|
1766
|
+
}
|
|
1767
|
+
async runAfterDownload(result) {
|
|
1768
|
+
let current = result;
|
|
1769
|
+
for (const plugin of this.plugins) {
|
|
1770
|
+
if (plugin.afterDownload) {
|
|
1771
|
+
const modified = await plugin.afterDownload(current);
|
|
1772
|
+
if (modified) current = modified;
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
return current;
|
|
1776
|
+
}
|
|
1777
|
+
};
|
|
1778
|
+
|
|
1617
1779
|
// src/core/client.ts
|
|
1618
1780
|
var DriveKit = class {
|
|
1619
1781
|
options;
|
|
@@ -1623,11 +1785,31 @@ var DriveKit = class {
|
|
|
1623
1785
|
uploaderInstance = null;
|
|
1624
1786
|
downloaderInstance = null;
|
|
1625
1787
|
rootFolderId;
|
|
1788
|
+
pluginManager = new PluginManager();
|
|
1626
1789
|
constructor(options = {}) {
|
|
1627
1790
|
this.options = options;
|
|
1628
1791
|
this.rootFolderId = options.rootFolderId || "root";
|
|
1629
1792
|
this.authenticator = new DriveAuthenticator(options.auth);
|
|
1630
1793
|
}
|
|
1794
|
+
/**
|
|
1795
|
+
* Registers a middleware plugin into DriveKit lifecycle
|
|
1796
|
+
*/
|
|
1797
|
+
use(plugin) {
|
|
1798
|
+
this.pluginManager.use(plugin);
|
|
1799
|
+
return this;
|
|
1800
|
+
}
|
|
1801
|
+
/**
|
|
1802
|
+
* Returns a fluent, chained reference to a specific file
|
|
1803
|
+
*/
|
|
1804
|
+
file(pathOrId) {
|
|
1805
|
+
return new DriveFileRef(this, pathOrId);
|
|
1806
|
+
}
|
|
1807
|
+
/**
|
|
1808
|
+
* Returns a fluent, chained reference to a specific folder
|
|
1809
|
+
*/
|
|
1810
|
+
folder(pathOrId) {
|
|
1811
|
+
return new DriveFolderRef(this, pathOrId);
|
|
1812
|
+
}
|
|
1631
1813
|
/**
|
|
1632
1814
|
* Initializes the Google Drive API client (lazy-loaded if not called explicitly)
|
|
1633
1815
|
*/
|
|
@@ -1736,21 +1918,23 @@ var DriveKit = class {
|
|
|
1736
1918
|
* - Real-time progress callback: % complete, transfer speed (MB/s), ETA
|
|
1737
1919
|
*/
|
|
1738
1920
|
async upload(options) {
|
|
1921
|
+
const opts = await this.pluginManager.runBeforeUpload(options);
|
|
1739
1922
|
const uploader = await this.getUploader();
|
|
1740
|
-
let parentId =
|
|
1923
|
+
let parentId = opts.parent;
|
|
1741
1924
|
if (parentId && parentId.startsWith("/")) {
|
|
1742
1925
|
parentId = await this.mkdirp(parentId);
|
|
1743
1926
|
}
|
|
1744
|
-
if (
|
|
1745
|
-
const existing = await this.query().inFolder(parentId).nameEquals(
|
|
1927
|
+
if (opts.overwrite && opts.name && parentId) {
|
|
1928
|
+
const existing = await this.query().inFolder(parentId).nameEquals(opts.name).notTrashed().first();
|
|
1746
1929
|
if (existing?.id) {
|
|
1747
1930
|
await this.delete(existing.id, true);
|
|
1748
1931
|
}
|
|
1749
1932
|
}
|
|
1750
|
-
|
|
1751
|
-
...
|
|
1933
|
+
const uploaded = await uploader.upload({
|
|
1934
|
+
...opts,
|
|
1752
1935
|
parent: parentId
|
|
1753
1936
|
});
|
|
1937
|
+
return await this.pluginManager.runAfterUpload(uploaded);
|
|
1754
1938
|
}
|
|
1755
1939
|
/**
|
|
1756
1940
|
* Downloads a file from Google Drive:
|
|
@@ -1760,8 +1944,10 @@ var DriveKit = class {
|
|
|
1760
1944
|
*/
|
|
1761
1945
|
async download(fileIdOrPath, options = {}) {
|
|
1762
1946
|
const fileId = await this.resolveId(fileIdOrPath);
|
|
1947
|
+
const processedOpts = await this.pluginManager.runBeforeDownload(fileId, options);
|
|
1763
1948
|
const downloader = await this.getDownloader();
|
|
1764
|
-
|
|
1949
|
+
const result = await downloader.download(fileId, processedOpts);
|
|
1950
|
+
return await this.pluginManager.runAfterDownload(result);
|
|
1765
1951
|
}
|
|
1766
1952
|
/**
|
|
1767
1953
|
* Gets file metadata
|
|
@@ -2176,6 +2362,158 @@ var DriveKit = class {
|
|
|
2176
2362
|
}
|
|
2177
2363
|
};
|
|
2178
2364
|
|
|
2365
|
+
// src/cli/terminal-ui.ts
|
|
2366
|
+
var import_node_readline = __toESM(require("readline"), 1);
|
|
2367
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
2368
|
+
function terminalLink(text, url) {
|
|
2369
|
+
return `\x1B]8;;${url}\x07${text}\x1B]8;;\x07`;
|
|
2370
|
+
}
|
|
2371
|
+
function renderFileRow(item, index) {
|
|
2372
|
+
const isDir = item.mimeType === "application/vnd.google-apps.folder";
|
|
2373
|
+
const icon = isDir ? "\u{1F4C1}" : getFileIcon(item.mimeType || "");
|
|
2374
|
+
const prefix = index !== void 0 ? `${import_chalk.default.dim((index + 1).toString().padStart(2, " ") + ".")} ` : "";
|
|
2375
|
+
let nameFormatted = isDir ? import_chalk.default.bold.blue(item.name || "untitled") : import_chalk.default.white(item.name || "untitled");
|
|
2376
|
+
if (item.webViewLink) {
|
|
2377
|
+
nameFormatted = terminalLink(nameFormatted, item.webViewLink);
|
|
2378
|
+
}
|
|
2379
|
+
const sizeFormatted = item.size ? import_chalk.default.dim(`[${formatBytes(parseInt(item.size, 10)).padStart(9, " ")}]`) : import_chalk.default.dim(isDir ? "[ FOLDER ]" : "[ DOC ]");
|
|
2380
|
+
const idFormatted = import_chalk.default.dim(`ID: ${item.id}`);
|
|
2381
|
+
return `${prefix}${icon} ${nameFormatted.padEnd(45)} ${sizeFormatted} ${idFormatted}`;
|
|
2382
|
+
}
|
|
2383
|
+
function getFileIcon(mimeType) {
|
|
2384
|
+
if (mimeType.includes("pdf")) return "\u{1F4D5}";
|
|
2385
|
+
if (mimeType.includes("image")) return "\u{1F5BC}\uFE0F ";
|
|
2386
|
+
if (mimeType.includes("video")) return "\u{1F3AC}";
|
|
2387
|
+
if (mimeType.includes("audio")) return "\u{1F3B5}";
|
|
2388
|
+
if (mimeType.includes("zip") || mimeType.includes("compressed") || mimeType.includes("tar")) return "\u{1F4E6}";
|
|
2389
|
+
if (mimeType.includes("spreadsheet") || mimeType.includes("excel")) return "\u{1F4CA}";
|
|
2390
|
+
if (mimeType.includes("document") || mimeType.includes("word")) return "\u{1F4DD}";
|
|
2391
|
+
if (mimeType.includes("presentation")) return "\u{1F4FD}\uFE0F ";
|
|
2392
|
+
if (mimeType.includes("json") || mimeType.includes("javascript") || mimeType.includes("typescript")) return "\u2699\uFE0F ";
|
|
2393
|
+
return "\u{1F4C4}";
|
|
2394
|
+
}
|
|
2395
|
+
async function runInteractiveExplorer(client, initialFolder = "/") {
|
|
2396
|
+
let currentFolder = initialFolder;
|
|
2397
|
+
let items = [];
|
|
2398
|
+
let selectedIndex = 0;
|
|
2399
|
+
let history = [];
|
|
2400
|
+
const refreshItems = async () => {
|
|
2401
|
+
items = await client.ls(currentFolder);
|
|
2402
|
+
selectedIndex = Math.min(selectedIndex, Math.max(0, items.length - 1));
|
|
2403
|
+
};
|
|
2404
|
+
await refreshItems();
|
|
2405
|
+
if (!process.stdin.isTTY) {
|
|
2406
|
+
console.log(import_chalk.default.yellow("Interactive explorer requires a TTY terminal. Listing items instead:"));
|
|
2407
|
+
for (const item of items) {
|
|
2408
|
+
console.log(renderFileRow(item));
|
|
2409
|
+
}
|
|
2410
|
+
return;
|
|
2411
|
+
}
|
|
2412
|
+
import_node_readline.default.emitKeypressEvents(process.stdin);
|
|
2413
|
+
process.stdin.setRawMode(true);
|
|
2414
|
+
const renderScreen = () => {
|
|
2415
|
+
console.clear();
|
|
2416
|
+
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"));
|
|
2417
|
+
console.log(import_chalk.default.bold.cyan("\u2551") + import_chalk.default.bold.yellow(" \u26A1 DriveKit Interactive Terminal Explorer ") + import_chalk.default.bold.cyan("\u2551"));
|
|
2418
|
+
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"));
|
|
2419
|
+
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"));
|
|
2420
|
+
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"));
|
|
2421
|
+
console.log(import_chalk.default.dim(" [\u2191/\u2193] Navigate \u2022 [Enter] Open Folder \u2022 [B] Back \u2022 [S] Share \u2022 [Q] Exit\n"));
|
|
2422
|
+
if (items.length === 0) {
|
|
2423
|
+
console.log(import_chalk.default.dim(" (This folder is empty)\n"));
|
|
2424
|
+
return;
|
|
2425
|
+
}
|
|
2426
|
+
const pageSize = 12;
|
|
2427
|
+
const startIdx = Math.max(0, Math.min(selectedIndex - Math.floor(pageSize / 2), items.length - pageSize));
|
|
2428
|
+
const endIdx = Math.min(items.length, startIdx + pageSize);
|
|
2429
|
+
for (let i = startIdx; i < endIdx; i++) {
|
|
2430
|
+
const isSelected = i === selectedIndex;
|
|
2431
|
+
const cursor = isSelected ? import_chalk.default.bold.cyan(" \u25BA ") : " ";
|
|
2432
|
+
const row = renderFileRow(items[i]);
|
|
2433
|
+
if (isSelected) {
|
|
2434
|
+
console.log(import_chalk.default.bgHex("#1e293b")(cursor + row));
|
|
2435
|
+
} else {
|
|
2436
|
+
console.log(cursor + row);
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
console.log(import_chalk.default.dim(`
|
|
2440
|
+
Item ${selectedIndex + 1} of ${items.length}`));
|
|
2441
|
+
};
|
|
2442
|
+
renderScreen();
|
|
2443
|
+
return new Promise((resolve) => {
|
|
2444
|
+
const onKeypress = async (str, key) => {
|
|
2445
|
+
if (key.ctrl && key.name === "c") {
|
|
2446
|
+
cleanup();
|
|
2447
|
+
process.exit(0);
|
|
2448
|
+
}
|
|
2449
|
+
if (key.name === "q" || key.name === "escape" && history.length === 0) {
|
|
2450
|
+
cleanup();
|
|
2451
|
+
resolve();
|
|
2452
|
+
return;
|
|
2453
|
+
}
|
|
2454
|
+
if (key.name === "up") {
|
|
2455
|
+
selectedIndex = selectedIndex > 0 ? selectedIndex - 1 : items.length - 1;
|
|
2456
|
+
renderScreen();
|
|
2457
|
+
} else if (key.name === "down") {
|
|
2458
|
+
selectedIndex = selectedIndex < items.length - 1 ? selectedIndex + 1 : 0;
|
|
2459
|
+
renderScreen();
|
|
2460
|
+
} else if (key.name === "return") {
|
|
2461
|
+
const item = items[selectedIndex];
|
|
2462
|
+
if (item && item.mimeType === "application/vnd.google-apps.folder") {
|
|
2463
|
+
history.push(currentFolder);
|
|
2464
|
+
currentFolder = currentFolder === "/" ? `/${item.name}` : `${currentFolder}/${item.name}`;
|
|
2465
|
+
selectedIndex = 0;
|
|
2466
|
+
await refreshItems();
|
|
2467
|
+
renderScreen();
|
|
2468
|
+
} else if (item && item.webViewLink) {
|
|
2469
|
+
const { exec: exec2 } = await import("child_process");
|
|
2470
|
+
const openCmd = process.platform === "darwin" ? `open "${item.webViewLink}"` : `xdg-open "${item.webViewLink}"`;
|
|
2471
|
+
exec2(openCmd);
|
|
2472
|
+
renderScreen();
|
|
2473
|
+
}
|
|
2474
|
+
} else if (key.name === "b" || key.name === "backspace") {
|
|
2475
|
+
if (history.length > 0) {
|
|
2476
|
+
currentFolder = history.pop();
|
|
2477
|
+
selectedIndex = 0;
|
|
2478
|
+
await refreshItems();
|
|
2479
|
+
renderScreen();
|
|
2480
|
+
}
|
|
2481
|
+
} else if (str === "s" || str === "S") {
|
|
2482
|
+
const item = items[selectedIndex];
|
|
2483
|
+
if (item && item.id) {
|
|
2484
|
+
process.stdin.pause();
|
|
2485
|
+
console.log(`
|
|
2486
|
+
|
|
2487
|
+
${import_chalk.default.cyan("\u{1F517} Getting shareable link for:")} ${import_chalk.default.bold(item.name)}...`);
|
|
2488
|
+
try {
|
|
2489
|
+
const links = await client.sharePublic(item.id);
|
|
2490
|
+
console.log(`Preview URL: ${import_chalk.default.underline(links.previewLink)}`);
|
|
2491
|
+
console.log(`Direct Download URL: ${import_chalk.default.underline(links.directDownloadLink)}`);
|
|
2492
|
+
console.log(import_chalk.default.dim("\nPress any key to return to explorer..."));
|
|
2493
|
+
process.stdin.resume();
|
|
2494
|
+
process.stdin.once("data", () => {
|
|
2495
|
+
renderScreen();
|
|
2496
|
+
});
|
|
2497
|
+
} catch (err) {
|
|
2498
|
+
console.error(import_chalk.default.red(`Failed to share: ${err.message}`));
|
|
2499
|
+
setTimeout(renderScreen, 2e3);
|
|
2500
|
+
}
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
};
|
|
2504
|
+
const cleanup = () => {
|
|
2505
|
+
process.stdin.removeListener("keypress", onKeypress);
|
|
2506
|
+
if (process.stdin.setRawMode) {
|
|
2507
|
+
process.stdin.setRawMode(false);
|
|
2508
|
+
}
|
|
2509
|
+
process.stdin.pause();
|
|
2510
|
+
console.clear();
|
|
2511
|
+
console.log(import_chalk.default.green("\u{1F44B} Exited DriveKit explorer."));
|
|
2512
|
+
};
|
|
2513
|
+
process.stdin.on("keypress", onKeypress);
|
|
2514
|
+
});
|
|
2515
|
+
}
|
|
2516
|
+
|
|
2179
2517
|
// src/index.ts
|
|
2180
2518
|
async function createDrive(options) {
|
|
2181
2519
|
const instance = new DriveKit(options);
|
|
@@ -2192,6 +2530,8 @@ var index_default = DriveKit;
|
|
|
2192
2530
|
Downloader,
|
|
2193
2531
|
DriveAuthError,
|
|
2194
2532
|
DriveAuthenticator,
|
|
2533
|
+
DriveFileRef,
|
|
2534
|
+
DriveFolderRef,
|
|
2195
2535
|
DriveKit,
|
|
2196
2536
|
DriveKitError,
|
|
2197
2537
|
DriveNotFoundError,
|
|
@@ -2203,6 +2543,7 @@ var index_default = DriveKit;
|
|
|
2203
2543
|
MIN_CHUNK_SIZE,
|
|
2204
2544
|
MULTIPART_THRESHOLD,
|
|
2205
2545
|
PathResolver,
|
|
2546
|
+
PluginManager,
|
|
2206
2547
|
ResumableUploader,
|
|
2207
2548
|
SmartSyncEngine,
|
|
2208
2549
|
StorageCleaner,
|
|
@@ -2212,10 +2553,14 @@ var index_default = DriveKit;
|
|
|
2212
2553
|
formatDuration,
|
|
2213
2554
|
formatSpeed,
|
|
2214
2555
|
getExtensionForMime,
|
|
2556
|
+
getFileIcon,
|
|
2215
2557
|
isGoogleWorkspaceDoc,
|
|
2216
2558
|
isRetryableError,
|
|
2217
2559
|
loginWithBrowser,
|
|
2218
2560
|
lookupMimeType,
|
|
2561
|
+
renderFileRow,
|
|
2562
|
+
runInteractiveExplorer,
|
|
2563
|
+
terminalLink,
|
|
2219
2564
|
withRetry
|
|
2220
2565
|
});
|
|
2221
2566
|
//# sourceMappingURL=index.cjs.map
|