@hasna/files 0.2.17 → 0.2.19
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/dist/cli/index.js +262 -35
- package/dist/index.js +253 -26
- package/dist/mcp/index.js +266 -39
- package/dist/server/index.js +255 -28
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -131979,7 +131979,7 @@ var init_sync = __esm(() => {
|
|
|
131979
131979
|
|
|
131980
131980
|
// node_modules/readdirp/esm/index.js
|
|
131981
131981
|
import { stat, lstat, readdir, realpath } from "fs/promises";
|
|
131982
|
-
import { Readable as
|
|
131982
|
+
import { Readable as Readable5 } from "stream";
|
|
131983
131983
|
import { resolve as presolve, relative as prelative, join as pjoin, sep as psep } from "path";
|
|
131984
131984
|
function readdirp(root2, options = {}) {
|
|
131985
131985
|
let type = options.entryType || options.type;
|
|
@@ -132048,7 +132048,7 @@ var init_esm2 = __esm(() => {
|
|
|
132048
132048
|
EntryTypes.FILE_TYPE
|
|
132049
132049
|
]);
|
|
132050
132050
|
wantBigintFsStats = process.platform === "win32";
|
|
132051
|
-
ReaddirpStream = class ReaddirpStream extends
|
|
132051
|
+
ReaddirpStream = class ReaddirpStream extends Readable5 {
|
|
132052
132052
|
constructor(options = {}) {
|
|
132053
132053
|
super({
|
|
132054
132054
|
objectMode: true,
|
|
@@ -134007,8 +134007,9 @@ async function walkDir(rootPath, dirPath, source, machine_id, seenPaths, stats,
|
|
|
134007
134007
|
init_mime_types();
|
|
134008
134008
|
init_machines();
|
|
134009
134009
|
init_files();
|
|
134010
|
-
import { mkdirSync as
|
|
134011
|
-
import { basename as basename5, dirname as dirname5, extname as extname5, join as
|
|
134010
|
+
import { createWriteStream as createWriteStream2, mkdirSync as mkdirSync10, writeFileSync as writeFileSync9 } from "fs";
|
|
134011
|
+
import { basename as basename5, dirname as dirname5, extname as extname5, join as join11, posix } from "path";
|
|
134012
|
+
import { pipeline as pipeline2 } from "stream/promises";
|
|
134012
134013
|
|
|
134013
134014
|
// src/db/google-drive.ts
|
|
134014
134015
|
init_database();
|
|
@@ -143584,6 +143585,12 @@ async function uploadBufferToS3(source, body, s3Key, contentType = "application/
|
|
|
143584
143585
|
return s3Key;
|
|
143585
143586
|
}
|
|
143586
143587
|
|
|
143588
|
+
// src/lib/google-drive-client.ts
|
|
143589
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync8, readFileSync as readFileSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
143590
|
+
import { homedir as homedir7 } from "os";
|
|
143591
|
+
import { join as join8 } from "path";
|
|
143592
|
+
import { Readable as Readable4 } from "stream";
|
|
143593
|
+
|
|
143587
143594
|
// node_modules/@hasna/connectors/dist/index.js
|
|
143588
143595
|
import { Buffer as Buffer22 } from "buffer";
|
|
143589
143596
|
import { existsSync as existsSync5 } from "fs";
|
|
@@ -167379,6 +167386,10 @@ function runLegacyConnectorCommand(name, args, timeoutMs = 30000) {
|
|
|
167379
167386
|
|
|
167380
167387
|
// src/lib/google-drive-client.ts
|
|
167381
167388
|
var GOOGLE_FOLDER_MIME = "application/vnd.google-apps.folder";
|
|
167389
|
+
var DRIVE_API_BASE2 = "https://www.googleapis.com/drive/v3";
|
|
167390
|
+
var TOKEN_URL3 = "https://oauth2.googleapis.com/token";
|
|
167391
|
+
var REFRESH_BUFFER_MS3 = 5 * 60 * 1000;
|
|
167392
|
+
var RANGE_DOWNLOAD_CHUNK_BYTES = 64 * 1024 * 1024;
|
|
167382
167393
|
var DEFAULT_EXPORT_FORMATS2 = {
|
|
167383
167394
|
document: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
167384
167395
|
spreadsheet: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
@@ -167450,6 +167461,38 @@ class ConnectorSdkGoogleDriveClient {
|
|
|
167450
167461
|
mimeType: response.mimeType ?? file.mimeType ?? "application/octet-stream"
|
|
167451
167462
|
};
|
|
167452
167463
|
}
|
|
167464
|
+
async downloadFileStream(file, exportFormats = {}) {
|
|
167465
|
+
if (file.mimeType.startsWith("application/vnd.google-apps.")) {
|
|
167466
|
+
const downloaded = await this.downloadFile(file, exportFormats);
|
|
167467
|
+
return {
|
|
167468
|
+
body: Readable4.from(Buffer.from(downloaded.data)),
|
|
167469
|
+
filename: downloaded.filename,
|
|
167470
|
+
mimeType: downloaded.mimeType,
|
|
167471
|
+
size: downloaded.data.byteLength
|
|
167472
|
+
};
|
|
167473
|
+
}
|
|
167474
|
+
const size = file.size ? Number(file.size) : undefined;
|
|
167475
|
+
if (size && size > RANGE_DOWNLOAD_CHUNK_BYTES) {
|
|
167476
|
+
return {
|
|
167477
|
+
body: Readable4.from(downloadGoogleDriveRangeChunks(this.profile, file.id, size)),
|
|
167478
|
+
filename: file.name,
|
|
167479
|
+
mimeType: file.mimeType || "application/octet-stream",
|
|
167480
|
+
size
|
|
167481
|
+
};
|
|
167482
|
+
}
|
|
167483
|
+
const response = await requestGoogleDrive(this.profile, `/files/${encodeURIComponent(file.id)}`, {
|
|
167484
|
+
alt: "media",
|
|
167485
|
+
supportsAllDrives: true
|
|
167486
|
+
});
|
|
167487
|
+
if (!response.body)
|
|
167488
|
+
throw new Error(`Google Drive download for "${file.name}" returned no stream`);
|
|
167489
|
+
return {
|
|
167490
|
+
body: Readable4.fromWeb(response.body),
|
|
167491
|
+
filename: file.name,
|
|
167492
|
+
mimeType: response.headers.get("content-type")?.split(";")[0] || file.mimeType || "application/octet-stream",
|
|
167493
|
+
size: size ?? (Number(response.headers.get("content-length") ?? 0) || undefined)
|
|
167494
|
+
};
|
|
167495
|
+
}
|
|
167453
167496
|
}
|
|
167454
167497
|
async function runGoogleDriveOperation(operation, profile, input) {
|
|
167455
167498
|
const result = await runConnectorOperation({
|
|
@@ -167477,9 +167520,145 @@ function getExportMimeType(googleMimeType, exportFormats) {
|
|
|
167477
167520
|
return exportFormats.drawing ?? DEFAULT_EXPORT_FORMATS2.drawing;
|
|
167478
167521
|
throw new Error(`Cannot export Google Workspace file type: ${googleMimeType}`);
|
|
167479
167522
|
}
|
|
167523
|
+
async function requestGoogleDrive(profile, path, params, headers = {}) {
|
|
167524
|
+
const token = await getValidAccessToken3(profile);
|
|
167525
|
+
const url = new URL(`${DRIVE_API_BASE2}${path}`);
|
|
167526
|
+
for (const [key, value] of Object.entries(params)) {
|
|
167527
|
+
if (value !== undefined && value !== null && value !== "")
|
|
167528
|
+
url.searchParams.set(key, String(value));
|
|
167529
|
+
}
|
|
167530
|
+
const response = await fetch(url, {
|
|
167531
|
+
headers: {
|
|
167532
|
+
Authorization: `Bearer ${token}`,
|
|
167533
|
+
Accept: "application/octet-stream",
|
|
167534
|
+
...headers
|
|
167535
|
+
}
|
|
167536
|
+
});
|
|
167537
|
+
if (!response.ok) {
|
|
167538
|
+
const body = await response.text().catch(() => "");
|
|
167539
|
+
throw new Error(`Google Drive request failed (${response.status}): ${extractGoogleError2(body) || response.statusText}`);
|
|
167540
|
+
}
|
|
167541
|
+
return response;
|
|
167542
|
+
}
|
|
167543
|
+
async function* downloadGoogleDriveRangeChunks(profile, fileId, size) {
|
|
167544
|
+
for (let start = 0;start < size; start += RANGE_DOWNLOAD_CHUNK_BYTES) {
|
|
167545
|
+
const end = Math.min(start + RANGE_DOWNLOAD_CHUNK_BYTES - 1, size - 1);
|
|
167546
|
+
const response = await requestGoogleDrive(profile, `/files/${encodeURIComponent(fileId)}`, { alt: "media", supportsAllDrives: true }, { Range: `bytes=${start}-${end}` });
|
|
167547
|
+
const data = Buffer.from(await response.arrayBuffer());
|
|
167548
|
+
yield data;
|
|
167549
|
+
}
|
|
167550
|
+
}
|
|
167551
|
+
async function getValidAccessToken3(profile) {
|
|
167552
|
+
if (process.env.GOOGLE_ACCESS_TOKEN)
|
|
167553
|
+
return process.env.GOOGLE_ACCESS_TOKEN;
|
|
167554
|
+
const loaded = loadTokens4(profile);
|
|
167555
|
+
const tokens = loaded?.tokens;
|
|
167556
|
+
if (!tokens?.accessToken && !tokens?.refreshToken) {
|
|
167557
|
+
throw new Error(`Google Drive profile "${profile}" is not authenticated. Run: connectors auth googledrive`);
|
|
167558
|
+
}
|
|
167559
|
+
if (tokens.accessToken && (!tokens.expiresAt || Date.now() < tokens.expiresAt - REFRESH_BUFFER_MS3))
|
|
167560
|
+
return tokens.accessToken;
|
|
167561
|
+
if (!tokens.refreshToken)
|
|
167562
|
+
return tokens.accessToken ?? "";
|
|
167563
|
+
return (await refreshAccessToken3(profile, tokens, loaded?.baseDir)).accessToken ?? "";
|
|
167564
|
+
}
|
|
167565
|
+
async function refreshAccessToken3(profile, currentTokens, preferredBaseDir) {
|
|
167566
|
+
const credentials = loadCredentials3(profile);
|
|
167567
|
+
if (!credentials.clientId || !credentials.clientSecret)
|
|
167568
|
+
throw new Error("Google Drive OAuth credentials are not configured. Run: connectors auth googledrive");
|
|
167569
|
+
if (!currentTokens.refreshToken)
|
|
167570
|
+
throw new Error(`Google Drive profile "${profile}" has no refresh token. Run: connectors auth googledrive`);
|
|
167571
|
+
const response = await fetch(TOKEN_URL3, {
|
|
167572
|
+
method: "POST",
|
|
167573
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
167574
|
+
body: new URLSearchParams({
|
|
167575
|
+
client_id: credentials.clientId,
|
|
167576
|
+
client_secret: credentials.clientSecret,
|
|
167577
|
+
refresh_token: currentTokens.refreshToken,
|
|
167578
|
+
grant_type: "refresh_token"
|
|
167579
|
+
})
|
|
167580
|
+
});
|
|
167581
|
+
const data = await response.json().catch(() => ({}));
|
|
167582
|
+
if (!response.ok || !data.access_token)
|
|
167583
|
+
throw new Error(`Google Drive token refresh failed: ${data.error_description || data.error || response.statusText}`);
|
|
167584
|
+
const tokens = {
|
|
167585
|
+
accessToken: data.access_token,
|
|
167586
|
+
refreshToken: currentTokens.refreshToken,
|
|
167587
|
+
expiresAt: Date.now() + (data.expires_in ?? 3600) * 1000,
|
|
167588
|
+
tokenType: data.token_type ?? currentTokens.tokenType,
|
|
167589
|
+
scope: data.scope ?? currentTokens.scope
|
|
167590
|
+
};
|
|
167591
|
+
saveTokens3(profile, tokens, preferredBaseDir);
|
|
167592
|
+
return tokens;
|
|
167593
|
+
}
|
|
167594
|
+
function loadCredentials3(profile) {
|
|
167595
|
+
const envClientId = process.env.GOOGLE_CLIENT_ID;
|
|
167596
|
+
const envClientSecret = process.env.GOOGLE_CLIENT_SECRET;
|
|
167597
|
+
if (envClientId && envClientSecret)
|
|
167598
|
+
return { clientId: envClientId, clientSecret: envClientSecret };
|
|
167599
|
+
for (const baseDir of configDirs3()) {
|
|
167600
|
+
const credentials = {
|
|
167601
|
+
...readJson3(join8(baseDir, "credentials.json")),
|
|
167602
|
+
...readJson3(join8(baseDir, "profiles", profile, "config.json"))
|
|
167603
|
+
};
|
|
167604
|
+
if (credentials.clientId || credentials.clientSecret)
|
|
167605
|
+
return credentials;
|
|
167606
|
+
}
|
|
167607
|
+
return {};
|
|
167608
|
+
}
|
|
167609
|
+
function loadTokens4(profile) {
|
|
167610
|
+
for (const baseDir of configDirs3()) {
|
|
167611
|
+
const fromProfile = readJson3(join8(baseDir, "profiles", profile, "tokens.json"));
|
|
167612
|
+
if (fromProfile)
|
|
167613
|
+
return { tokens: fromProfile, baseDir };
|
|
167614
|
+
const flat = readJson3(join8(baseDir, "profiles", `${profile}.json`));
|
|
167615
|
+
const tokens = flat?.tokens ?? (flat?.accessToken || flat?.refreshToken ? flat : null);
|
|
167616
|
+
if (tokens)
|
|
167617
|
+
return { tokens, baseDir };
|
|
167618
|
+
}
|
|
167619
|
+
return null;
|
|
167620
|
+
}
|
|
167621
|
+
function saveTokens3(profile, tokens, preferredBaseDir) {
|
|
167622
|
+
const dirs = configDirs3();
|
|
167623
|
+
const baseDir = preferredBaseDir ?? dirs.find((dir) => existsSync9(dir)) ?? dirs[0];
|
|
167624
|
+
if (!baseDir)
|
|
167625
|
+
throw new Error("Google Drive connector configuration directory is unavailable");
|
|
167626
|
+
const profileDir = join8(baseDir, "profiles", profile);
|
|
167627
|
+
mkdirSync8(profileDir, { recursive: true });
|
|
167628
|
+
writeFileSync7(join8(profileDir, "tokens.json"), JSON.stringify(tokens, null, 2), { mode: 384 });
|
|
167629
|
+
}
|
|
167630
|
+
function configDirs3() {
|
|
167631
|
+
const explicit = process.env.HASNA_GOOGLE_DRIVE_CONNECTOR_DIR ?? process.env.GOOGLE_DRIVE_CONNECTOR_DIR;
|
|
167632
|
+
if (explicit)
|
|
167633
|
+
return [explicit];
|
|
167634
|
+
const baseDir = process.env.HASNA_CONNECTORS_DIR ?? join8(homedir7(), ".hasna", "connectors");
|
|
167635
|
+
return [join8(baseDir, "googledrive"), join8(baseDir, "connect-googledrive")];
|
|
167636
|
+
}
|
|
167637
|
+
function readJson3(path) {
|
|
167638
|
+
if (!existsSync9(path))
|
|
167639
|
+
return null;
|
|
167640
|
+
try {
|
|
167641
|
+
return JSON.parse(readFileSync8(path, "utf8"));
|
|
167642
|
+
} catch {
|
|
167643
|
+
return null;
|
|
167644
|
+
}
|
|
167645
|
+
}
|
|
167646
|
+
function extractGoogleError2(body) {
|
|
167647
|
+
if (!body)
|
|
167648
|
+
return "";
|
|
167649
|
+
try {
|
|
167650
|
+
const parsed = JSON.parse(body);
|
|
167651
|
+
if (typeof parsed.error === "object" && parsed.error?.message)
|
|
167652
|
+
return parsed.error.message;
|
|
167653
|
+
if (typeof parsed.error === "string")
|
|
167654
|
+
return parsed.error_description || parsed.error;
|
|
167655
|
+
} catch {}
|
|
167656
|
+
return body.slice(0, 500);
|
|
167657
|
+
}
|
|
167480
167658
|
|
|
167481
167659
|
// src/lib/google-drive.ts
|
|
167482
167660
|
var DRIVE_FIELDS = "nextPageToken,files(id,name,mimeType,size,modifiedTime,parents,version,md5Checksum)";
|
|
167661
|
+
var STREAM_TO_S3_THRESHOLD_BYTES = 64 * 1024 * 1024;
|
|
167483
167662
|
var clientFactory = createConnectorProfileGoogleDriveClient;
|
|
167484
167663
|
var profileStatusProvider = listGoogleDriveProfileStatusesFromConnectorConfig;
|
|
167485
167664
|
var storageAdapter = {
|
|
@@ -167487,9 +167666,17 @@ var storageAdapter = {
|
|
|
167487
167666
|
writeLocal: async (source, relativePath, data) => {
|
|
167488
167667
|
if (!source.path)
|
|
167489
167668
|
throw new Error("Local destination source missing path");
|
|
167490
|
-
const localPath =
|
|
167491
|
-
|
|
167492
|
-
|
|
167669
|
+
const localPath = join11(source.path, relativePath);
|
|
167670
|
+
mkdirSync10(dirname5(localPath), { recursive: true });
|
|
167671
|
+
writeFileSync9(localPath, data);
|
|
167672
|
+
return relativePath;
|
|
167673
|
+
},
|
|
167674
|
+
writeLocalStream: async (source, relativePath, body) => {
|
|
167675
|
+
if (!source.path)
|
|
167676
|
+
throw new Error("Local destination source missing path");
|
|
167677
|
+
const localPath = join11(source.path, relativePath);
|
|
167678
|
+
mkdirSync10(dirname5(localPath), { recursive: true });
|
|
167679
|
+
await pipeline2(body, createWriteStream2(localPath));
|
|
167493
167680
|
return relativePath;
|
|
167494
167681
|
}
|
|
167495
167682
|
};
|
|
@@ -167615,22 +167802,17 @@ async function syncGoogleDriveSource(source) {
|
|
|
167615
167802
|
const existing = getGoogleDriveImportedObject(source.id, item.drive_id, item.id);
|
|
167616
167803
|
if (existing && !shouldImport(config9, item, existing, destination.source.id, destination.storage_type))
|
|
167617
167804
|
continue;
|
|
167618
|
-
const
|
|
167619
|
-
const importedName = basename5(downloaded.filename);
|
|
167620
|
-
const importedPath = buildImportedPath(config9, item, importedName);
|
|
167621
|
-
const contentType = downloaded.mimeType || ($lookup(downloaded.filename) || item.mime || "application/octet-stream");
|
|
167622
|
-
const data = Buffer.from(downloaded.data);
|
|
167623
|
-
const storageKey = await writeToDestination(destination.source, destination.storage_type, importedPath, data, contentType);
|
|
167805
|
+
const importResult = await importGoogleDriveItem(client2, item, config9, destination.source, destination.storage_type);
|
|
167624
167806
|
const fileRecord = upsertFile({
|
|
167625
167807
|
id: existing?.file_record_id,
|
|
167626
167808
|
source_id: destination.source.id,
|
|
167627
167809
|
machine_id: machine.id,
|
|
167628
|
-
path: storageKey,
|
|
167629
|
-
name: importedName,
|
|
167630
|
-
ext: extname5(importedName).toLowerCase(),
|
|
167631
|
-
size:
|
|
167632
|
-
mime: contentType,
|
|
167633
|
-
hash:
|
|
167810
|
+
path: importResult.storageKey,
|
|
167811
|
+
name: importResult.importedName,
|
|
167812
|
+
ext: extname5(importResult.importedName).toLowerCase(),
|
|
167813
|
+
size: importResult.size,
|
|
167814
|
+
mime: importResult.contentType,
|
|
167815
|
+
hash: importResult.hash,
|
|
167634
167816
|
status: "active",
|
|
167635
167817
|
modified_at: item.modified_at
|
|
167636
167818
|
});
|
|
@@ -167640,17 +167822,17 @@ async function syncGoogleDriveSource(source) {
|
|
|
167640
167822
|
file_id: item.id,
|
|
167641
167823
|
profile: config9.profile,
|
|
167642
167824
|
parent_id: item.parent_id,
|
|
167643
|
-
path: importedPath,
|
|
167644
|
-
name: importedName,
|
|
167645
|
-
mime: contentType,
|
|
167646
|
-
size:
|
|
167825
|
+
path: importResult.importedPath,
|
|
167826
|
+
name: importResult.importedName,
|
|
167827
|
+
mime: importResult.contentType,
|
|
167828
|
+
size: importResult.size,
|
|
167647
167829
|
modified_at: item.modified_at,
|
|
167648
167830
|
version: item.version,
|
|
167649
|
-
hash:
|
|
167831
|
+
hash: importResult.hash,
|
|
167650
167832
|
storage_type: destination.storage_type,
|
|
167651
|
-
storage_key: storageKey,
|
|
167833
|
+
storage_key: importResult.storageKey,
|
|
167652
167834
|
destination_source_id: destination.source.id,
|
|
167653
|
-
s3_key: destination.storage_type === "s3" ? storageKey : "",
|
|
167835
|
+
s3_key: destination.storage_type === "s3" ? importResult.storageKey : "",
|
|
167654
167836
|
file_record_id: fileRecord.id,
|
|
167655
167837
|
deleted: false,
|
|
167656
167838
|
last_imported_at: new Date().toISOString()
|
|
@@ -167715,6 +167897,51 @@ async function writeToDestination(source, storageType, importedPath, data, conte
|
|
|
167715
167897
|
}
|
|
167716
167898
|
return storageAdapter.writeLocal(source, importedPath, data);
|
|
167717
167899
|
}
|
|
167900
|
+
async function importGoogleDriveItem(client2, item, config9, destinationSource, storageType) {
|
|
167901
|
+
if (shouldStreamGoogleDriveItem(client2, item, storageType)) {
|
|
167902
|
+
const downloaded2 = await client2.downloadFileStream(toApiFile(item), config9.export_formats);
|
|
167903
|
+
return importGoogleDriveStream(destinationSource, storageType, item, config9, downloaded2);
|
|
167904
|
+
}
|
|
167905
|
+
const downloaded = await downloadOrArchiveGoogleDriveItem(client2, item, config9);
|
|
167906
|
+
const importedName = basename5(downloaded.filename);
|
|
167907
|
+
const importedPath = buildImportedPath(config9, item, importedName);
|
|
167908
|
+
const contentType = downloaded.mimeType || ($lookup(downloaded.filename) || item.mime || "application/octet-stream");
|
|
167909
|
+
const data = Buffer.from(downloaded.data);
|
|
167910
|
+
const storageKey = await writeToDestination(destinationSource, storageType, importedPath, data, contentType);
|
|
167911
|
+
return {
|
|
167912
|
+
importedName,
|
|
167913
|
+
importedPath,
|
|
167914
|
+
contentType,
|
|
167915
|
+
size: data.byteLength,
|
|
167916
|
+
hash: item.hash ?? hashBuffer(data),
|
|
167917
|
+
storageKey
|
|
167918
|
+
};
|
|
167919
|
+
}
|
|
167920
|
+
function shouldStreamGoogleDriveItem(client2, item, storageType) {
|
|
167921
|
+
return storageType === "s3" && typeof client2.downloadFileStream === "function" && !item.mime.startsWith("application/vnd.google-apps.") && item.size >= STREAM_TO_S3_THRESHOLD_BYTES;
|
|
167922
|
+
}
|
|
167923
|
+
async function importGoogleDriveStream(source, storageType, item, config9, downloaded) {
|
|
167924
|
+
const importedName = basename5(downloaded.filename);
|
|
167925
|
+
const importedPath = buildImportedPath(config9, item, importedName);
|
|
167926
|
+
const contentType = downloaded.mimeType || ($lookup(downloaded.filename) || item.mime || "application/octet-stream");
|
|
167927
|
+
const size = downloaded.size ?? item.size;
|
|
167928
|
+
const storageKey = await writeStreamToDestination(source, storageType, importedPath, downloaded.body, contentType, size);
|
|
167929
|
+
return {
|
|
167930
|
+
importedName,
|
|
167931
|
+
importedPath,
|
|
167932
|
+
contentType,
|
|
167933
|
+
size,
|
|
167934
|
+
hash: item.hash,
|
|
167935
|
+
storageKey
|
|
167936
|
+
};
|
|
167937
|
+
}
|
|
167938
|
+
async function writeStreamToDestination(source, storageType, importedPath, body, contentType, contentLength) {
|
|
167939
|
+
if (storageType === "s3") {
|
|
167940
|
+
const key = buildStorageKey(source, importedPath);
|
|
167941
|
+
return storageAdapter.uploadS3(source, body, key, contentType, contentLength);
|
|
167942
|
+
}
|
|
167943
|
+
return storageAdapter.writeLocalStream(source, importedPath, body);
|
|
167944
|
+
}
|
|
167718
167945
|
async function getIncludedSharedDrives(source, client2) {
|
|
167719
167946
|
const config9 = getGoogleDriveConfig(source);
|
|
167720
167947
|
if (!config9.include_all_shared_drives && (!config9.shared_drive_ids || config9.shared_drive_ids.length === 0)) {
|
|
@@ -167979,8 +168206,8 @@ function requireId(partial, table) {
|
|
|
167979
168206
|
}
|
|
167980
168207
|
|
|
167981
168208
|
// src/cli/index.tsx
|
|
167982
|
-
import { resolve as resolve3, join as
|
|
167983
|
-
import { existsSync as
|
|
168209
|
+
import { resolve as resolve3, join as join18 } from "path";
|
|
168210
|
+
import { existsSync as existsSync13, readFileSync as readFileSync10 } from "fs";
|
|
167984
168211
|
import { createRequire as createRequire2 } from "module";
|
|
167985
168212
|
var _require = createRequire2(import.meta.url);
|
|
167986
168213
|
var _pkg = _require("../../package.json");
|
|
@@ -168037,7 +168264,7 @@ sources.command("add <path-or-s3>").description("Add a local folder or S3 bucket
|
|
|
168037
168264
|
console.log(chalk.green(`\u2713 S3 source added: ${source.id} \u2192 s3://${bucket}${prefix ? `/${prefix}` : ""}`));
|
|
168038
168265
|
} else {
|
|
168039
168266
|
const absPath = resolve3(pathOrS3);
|
|
168040
|
-
if (!
|
|
168267
|
+
if (!existsSync13(absPath)) {
|
|
168041
168268
|
console.error(chalk.red(`Path does not exist: ${absPath}`));
|
|
168042
168269
|
process.exit(1);
|
|
168043
168270
|
}
|
|
@@ -168478,7 +168705,7 @@ program2.command("download <file-id> [dest]").description("Download a file to lo
|
|
|
168478
168705
|
process.exit(1);
|
|
168479
168706
|
}
|
|
168480
168707
|
if (source.type === "local") {
|
|
168481
|
-
const fullPath =
|
|
168708
|
+
const fullPath = join18(source.path, file.path);
|
|
168482
168709
|
console.log(chalk.dim(`Local file at: ${fullPath}`));
|
|
168483
168710
|
return;
|
|
168484
168711
|
}
|
|
@@ -168499,7 +168726,7 @@ program2.command("upload <local-path> <source-id> [s3-key]").description("Upload
|
|
|
168499
168726
|
console.error(chalk.red("upload only works with S3 sources"));
|
|
168500
168727
|
process.exit(1);
|
|
168501
168728
|
}
|
|
168502
|
-
if (!
|
|
168729
|
+
if (!existsSync13(localPath)) {
|
|
168503
168730
|
console.error(chalk.red(`File not found: ${localPath}`));
|
|
168504
168731
|
process.exit(1);
|
|
168505
168732
|
}
|
|
@@ -168772,7 +168999,7 @@ program2.command("open <file-id>").description("Open a file in the default appli
|
|
|
168772
168999
|
console.error(chalk.red("open only works with local sources"));
|
|
168773
169000
|
process.exit(1);
|
|
168774
169001
|
}
|
|
168775
|
-
const fullPath =
|
|
169002
|
+
const fullPath = join18(source.path, file.path);
|
|
168776
169003
|
Bun.spawn(getOpenCommand(fullPath), { stdout: "inherit", stderr: "inherit" });
|
|
168777
169004
|
} catch (e3) {
|
|
168778
169005
|
console.error(chalk.red(e3.message));
|
|
@@ -168787,7 +169014,7 @@ program2.command("where <file-id>").description("Print the full absolute path of
|
|
|
168787
169014
|
console.error(chalk.red("where only works with local sources"));
|
|
168788
169015
|
process.exit(1);
|
|
168789
169016
|
}
|
|
168790
|
-
process.stdout.write(
|
|
169017
|
+
process.stdout.write(join18(source.path, file.path) + `
|
|
168791
169018
|
`);
|
|
168792
169019
|
} catch (e3) {
|
|
168793
169020
|
console.error(chalk.red(e3.message));
|
|
@@ -168802,9 +169029,9 @@ program2.command("cat <file-id>").description("Print file content to stdout").op
|
|
|
168802
169029
|
console.error(chalk.red("cat only works with local sources"));
|
|
168803
169030
|
process.exit(1);
|
|
168804
169031
|
}
|
|
168805
|
-
const fullPath =
|
|
169032
|
+
const fullPath = join18(source.path, file.path);
|
|
168806
169033
|
const maxBytes = parseIntFlag(opts.maxBytes, "max-bytes", { min: 0 });
|
|
168807
|
-
const buf =
|
|
169034
|
+
const buf = readFileSync10(fullPath);
|
|
168808
169035
|
const slice = maxBytes > 0 ? buf.slice(0, maxBytes) : buf;
|
|
168809
169036
|
process.stdout.write(slice);
|
|
168810
169037
|
} catch (e3) {
|