| 510 | } |
| 511 | |
| 512 | async getCommitItems( |
| 513 | files: { path: string; newPath?: string }[], |
| 514 | branch: string, |
| 515 | subfolders = true, |
| 516 | ) { |
| 517 | const items = await Promise.all( |
| 518 | files.map(async file => { |
| 519 | const [base64Content, fileExists] = await Promise.all([ |
| 520 | result(file, 'toBase64', partial(this.toBase64, (file as DataFile).raw)), |
| 521 | this.isFileExists(file.path, branch), |
| 522 | ]); |
| 523 | |
| 524 | const path = file.newPath || file.path; |
| 525 | const oldPath = file.path; |
| 526 | const renameOrEdit = |
| 527 | path !== oldPath ? AzureCommitChangeType.RENAME : AzureCommitChangeType.EDIT; |
| 528 | |
| 529 | const action = fileExists ? renameOrEdit : AzureCommitChangeType.ADD; |
| 530 | return { |
| 531 | action, |
| 532 | base64Content, |
| 533 | path, |
| 534 | oldPath, |
| 535 | } as AzureCommitItem; |
| 536 | }), |
| 537 | ); |
| 538 | |
| 539 | // move children when subfolders is true (legacy/default behavior) |
| 540 | if (subfolders) { |
| 541 | for (const item of items.filter( |
| 542 | i => i.oldPath && i.action === AzureCommitChangeType.RENAME, |
| 543 | )) { |
| 544 | const sourceDir = dirname(item.oldPath as string); |
| 545 | const destDir = dirname(item.path); |
| 546 | const children = await this.listFiles(sourceDir, true, branch); |
| 547 | children |
| 548 | .filter(file => file.path !== item.oldPath) |
| 549 | .forEach(file => { |
| 550 | items.push({ |
| 551 | action: AzureCommitChangeType.RENAME, |
| 552 | path: file.path.replace(sourceDir, destDir), |
| 553 | oldPath: file.path, |
| 554 | }); |
| 555 | }); |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | return items; |
| 560 | } |
| 561 | |
| 562 | async persistFiles(dataFiles: DataFile[], mediaFiles: AssetProxy[], options: PersistOptions) { |
| 563 | const files = [...dataFiles, ...mediaFiles]; |