syncast-cli 0.1.2 → 0.1.3
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.js +27 -0
- package/dist/index.js +27 -0
- package/dist/ws-server.d.ts +5 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -625,6 +625,9 @@ class SyncServer {
|
|
|
625
625
|
case "write_config":
|
|
626
626
|
await this.handleWriteConfig(message.path, message.assetId, message.folderId, message.originalFilename, message.md5);
|
|
627
627
|
break;
|
|
628
|
+
case "create_folder":
|
|
629
|
+
await this.handleCreateFolder(message.path, message.folderId);
|
|
630
|
+
break;
|
|
628
631
|
case "cancel_transfer":
|
|
629
632
|
await this.handleCancelTransfer(message.requestId);
|
|
630
633
|
break;
|
|
@@ -770,6 +773,30 @@ class SyncServer {
|
|
|
770
773
|
this.send(createErrorMessage(ErrorCodes.PERMISSION_DENIED, `Failed to write config: ${error}`));
|
|
771
774
|
}
|
|
772
775
|
}
|
|
776
|
+
async handleCreateFolder(relativePath, folderId) {
|
|
777
|
+
if (!this.syncFolder || !this.fileWatcher) return void this.send(createErrorMessage(ErrorCodes.FOLDER_NOT_FOUND, "No folder selected"));
|
|
778
|
+
const fs = await import("node:fs/promises");
|
|
779
|
+
const nodePath = await import("node:path");
|
|
780
|
+
const absolutePath = nodePath.join(this.syncFolder, relativePath);
|
|
781
|
+
try {
|
|
782
|
+
this.fileWatcher.markProcessing(relativePath);
|
|
783
|
+
await fs.mkdir(absolutePath, {
|
|
784
|
+
recursive: true
|
|
785
|
+
});
|
|
786
|
+
console.log(`[SyncServer] Folder created: ${relativePath}`);
|
|
787
|
+
await this.fileWatcher.writeConfig(relativePath, void 0, folderId);
|
|
788
|
+
this.fileWatcher.unmarkProcessing(relativePath);
|
|
789
|
+
this.send({
|
|
790
|
+
type: "config_written",
|
|
791
|
+
path: relativePath,
|
|
792
|
+
folderId
|
|
793
|
+
});
|
|
794
|
+
} catch (error) {
|
|
795
|
+
this.fileWatcher.unmarkProcessing(relativePath);
|
|
796
|
+
console.error(`[SyncServer] Failed to create folder: ${relativePath}`, error);
|
|
797
|
+
this.send(createErrorMessage(ErrorCodes.PERMISSION_DENIED, `Failed to create folder: ${error}`));
|
|
798
|
+
}
|
|
799
|
+
}
|
|
773
800
|
async handleCancelTransfer(requestId) {
|
|
774
801
|
if (!this.fileTransfer) return;
|
|
775
802
|
await this.fileTransfer.cancelTransfer(requestId);
|
package/dist/index.js
CHANGED
|
@@ -625,6 +625,9 @@ class SyncServer {
|
|
|
625
625
|
case "write_config":
|
|
626
626
|
await this.handleWriteConfig(message.path, message.assetId, message.folderId, message.originalFilename, message.md5);
|
|
627
627
|
break;
|
|
628
|
+
case "create_folder":
|
|
629
|
+
await this.handleCreateFolder(message.path, message.folderId);
|
|
630
|
+
break;
|
|
628
631
|
case "cancel_transfer":
|
|
629
632
|
await this.handleCancelTransfer(message.requestId);
|
|
630
633
|
break;
|
|
@@ -770,6 +773,30 @@ class SyncServer {
|
|
|
770
773
|
this.send(createErrorMessage(ErrorCodes.PERMISSION_DENIED, `Failed to write config: ${error}`));
|
|
771
774
|
}
|
|
772
775
|
}
|
|
776
|
+
async handleCreateFolder(relativePath, folderId) {
|
|
777
|
+
if (!this.syncFolder || !this.fileWatcher) return void this.send(createErrorMessage(ErrorCodes.FOLDER_NOT_FOUND, "No folder selected"));
|
|
778
|
+
const fs = await import("node:fs/promises");
|
|
779
|
+
const nodePath = await import("node:path");
|
|
780
|
+
const absolutePath = nodePath.join(this.syncFolder, relativePath);
|
|
781
|
+
try {
|
|
782
|
+
this.fileWatcher.markProcessing(relativePath);
|
|
783
|
+
await fs.mkdir(absolutePath, {
|
|
784
|
+
recursive: true
|
|
785
|
+
});
|
|
786
|
+
console.log(`[SyncServer] Folder created: ${relativePath}`);
|
|
787
|
+
await this.fileWatcher.writeConfig(relativePath, void 0, folderId);
|
|
788
|
+
this.fileWatcher.unmarkProcessing(relativePath);
|
|
789
|
+
this.send({
|
|
790
|
+
type: "config_written",
|
|
791
|
+
path: relativePath,
|
|
792
|
+
folderId
|
|
793
|
+
});
|
|
794
|
+
} catch (error) {
|
|
795
|
+
this.fileWatcher.unmarkProcessing(relativePath);
|
|
796
|
+
console.error(`[SyncServer] Failed to create folder: ${relativePath}`, error);
|
|
797
|
+
this.send(createErrorMessage(ErrorCodes.PERMISSION_DENIED, `Failed to create folder: ${error}`));
|
|
798
|
+
}
|
|
799
|
+
}
|
|
773
800
|
async handleCancelTransfer(requestId) {
|
|
774
801
|
if (!this.fileTransfer) return;
|
|
775
802
|
await this.fileTransfer.cancelTransfer(requestId);
|
package/dist/ws-server.d.ts
CHANGED