Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cloud-archive",
"version": "1.1.1",
"version": "1.1.2",
"description": "A CLI tool",
"main": "dist/index.js",
"bin": {
Expand Down
8 changes: 2 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,8 @@ program
try {
const gcpClient = new GcpClient(bucket);
const syncClient = new SyncClient(path, destinationPath, gcpClient);
await syncClient.sync((p) => {
console.log(
`Uploaded ${p.fileCount} of ${p.totalFiles}. Size: ${displayFileSize(
p.sizeUploaded
)}/${displayFileSize(p.totalSize)}`
);
await syncClient.sync((message) => {
console.log(message);
});
} catch (error) {
console.error("Failed to sync the folder:", error);
Expand Down
27 changes: 8 additions & 19 deletions src/lib/sync-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ import * as fs from "fs";
import * as path from "path";
import { displayFileSize } from "./display-file-size";

export interface SyncProgress {
fileCount: number;
totalFiles: number;
sizeUploaded: number;
totalSize: number;
}

export interface SyncResult {
uploadedFiles: string[];
totalFilesUploaded: number;
Expand Down Expand Up @@ -85,9 +78,9 @@ export class SyncClient {
}

async sync(
onProgress: (progress: SyncProgress) => void
onProgress: (message: string) => void
): Promise<SyncResult> {
console.log("Getting the list of files...");
onProgress("Getting the list of files...");
const files = await this.listFiles();
const filesToUpload = await this.getFilesToUpload(files);
const totalFiles = filesToUpload.length;
Expand All @@ -100,28 +93,24 @@ export class SyncClient {
for (const [, , size] of filesToUpload) {
totalSize += size;
}
console.log(
onProgress(
`Will upload ${filesToUpload.length} files, total size ${displayFileSize(
totalSize
)}`
);
console.log("Starting upload");
// Upload files one by one
for (const [absolutePath, destinationPath, size] of filesToUpload) {
try {
onProgress(`Uploading ${destinationPath}, size ${displayFileSize(size)}`);
await this.gcpClient.uploadFile(absolutePath, destinationPath);
sizeUploaded += size;
fileCount++;
uploadedFiles.push(destinationPath);

onProgress({
fileCount,
totalFiles,
sizeUploaded,
totalSize,
});
onProgress(`Uploaded ${fileCount} of ${totalFiles}. Size: ${displayFileSize(
sizeUploaded
)}/${displayFileSize(totalSize)}`);
} catch (error) {
console.error(`Failed to upload ${destinationPath}:`, error);
onProgress(`Failed to upload ${destinationPath}: ${error}`);
// Continue with next file even if one fails
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = "v1.1.1";
export const version = "v1.1.2";