(
files: { path: string; newPath?: string }[],
branch: string,
hasSubfolders = true,
)
| 624 | } |
| 625 | |
| 626 | async getCommitItems( |
| 627 | files: { path: string; newPath?: string }[], |
| 628 | branch: string, |
| 629 | hasSubfolders = true, |
| 630 | ) { |
| 631 | const items: CommitItem[] = await Promise.all( |
| 632 | files.map(async file => { |
| 633 | const [base64Content, fileExists] = await Promise.all([ |
| 634 | result(file, 'toBase64', partial(this.toBase64, (file as DataFile).raw)), |
| 635 | this.isFileExists(file.path, branch), |
| 636 | ]); |
| 637 | |
| 638 | let action = CommitAction.CREATE; |
| 639 | let path = trimStart(file.path, '/'); |
| 640 | let oldPath = undefined; |
| 641 | if (fileExists) { |
| 642 | oldPath = file.newPath && path; |
| 643 | action = |
| 644 | file.newPath && file.newPath !== oldPath ? CommitAction.MOVE : CommitAction.UPDATE; |
| 645 | path = file.newPath ? trimStart(file.newPath, '/') : path; |
| 646 | } |
| 647 | |
| 648 | return { |
| 649 | action, |
| 650 | base64Content, |
| 651 | path, |
| 652 | oldPath, |
| 653 | }; |
| 654 | }), |
| 655 | ); |
| 656 | |
| 657 | // Move children if subfolders is true (legacy/default behavior) |
| 658 | if (hasSubfolders) { |
| 659 | for (const item of items.filter(i => i.oldPath && i.action === CommitAction.MOVE)) { |
| 660 | const sourceDir = dirname(item.oldPath as string); |
| 661 | const destDir = dirname(item.path); |
| 662 | const children = await this.listAllFiles(sourceDir, true, branch); |
| 663 | children |
| 664 | .filter(f => f.path !== item.oldPath) |
| 665 | .forEach(file => { |
| 666 | items.push({ |
| 667 | action: CommitAction.MOVE, |
| 668 | path: file.path.replace(sourceDir, destDir), |
| 669 | oldPath: file.path, |
| 670 | }); |
| 671 | }); |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | return items; |
| 676 | } |
| 677 | |
| 678 | async persistFiles(dataFiles: DataFile[], mediaFiles: AssetProxy[], options: PersistOptions) { |
| 679 | const files = [...dataFiles, ...mediaFiles]; |
no test coverage detected