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 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);
@@ -79,6 +79,11 @@ export declare class SyncServer {
79
79
  * 写入 config.json
80
80
  */
81
81
  private handleWriteConfig;
82
+ /**
83
+ * 创建文件夹并写入 config
84
+ * 用于前端 -> CLI 的文件夹同步
85
+ */
86
+ private handleCreateFolder;
82
87
  /**
83
88
  * 取消传输
84
89
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "syncast-cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Syncast CLI tool",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",