Skip to content

Commit

Permalink
feat(core): add progress
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Sep 26, 2023
1 parent cb8971d commit c79737d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 33 deletions.
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
"dependencies": {
"@breadc/color": "^0.9.6",
"@breadc/death": "^0.9.6",
"@breadfs/webdav": "^0.0.6",
"@breadfs/webdav": "^0.0.7",
"anitomy": "^0.0.27",
"breadfs": "^0.0.6",
"breadfs": "^0.0.7",
"consola": "^3.1.0",
"date-fns": "^2.30.0",
"debug": "^4.3.4",
Expand Down
28 changes: 17 additions & 11 deletions packages/core/src/anime/anime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export class Anime {
private async addVideo(
localSrc: string,
newVideo: LocalVideo,
{ copy = false }: { copy?: boolean } = {}
{ copy = false, onProgress }: { copy?: boolean } & AddVideoOptions = {}
): Promise<LocalVideoDelta | undefined> {
await this.library();

Expand All @@ -282,16 +282,16 @@ export class Anime {
// }

if (copy) {
await src.copyTo(dst, { overwrite: true });
// await fs.copy(src, dst, {
// overwrite: true,
// });
await src.copyTo(dst, {
overwrite: true,
fallback: { file: { write: { onProgress } } }
});
delta = { operation: 'copy', video: newVideo };
} else {
await src.moveTo(dst, { overwrite: true });
// await fs.move(src, dst, {
// overwrite: true,
// });
await src.moveTo(dst, {
overwrite: true,
fallback: { file: { write: { onProgress } } }
});
delta = { operation: 'move', video: newVideo };
}
this._delta.push(delta);
Expand All @@ -315,7 +315,8 @@ export class Anime {
*/
public async addVideoByCopy(
src: string,
video: LocalVideo
video: LocalVideo,
options: AddVideoOptions = {}
): Promise<LocalVideoDelta | undefined> {
return this.addVideo(src, video, { copy: true });
}
Expand All @@ -329,7 +330,8 @@ export class Anime {
*/
public async addVideoByMove(
src: string,
video: LocalVideo
video: LocalVideo,
options: AddVideoOptions = {}
): Promise<LocalVideoDelta | undefined> {
return this.addVideo(src, video, { copy: false });
}
Expand Down Expand Up @@ -442,3 +444,7 @@ interface LocalVideoDelta {

log?: string;
}

interface AddVideoOptions {
onProgress?: (payload: { current: number; total: number }) => void;
}
2 changes: 1 addition & 1 deletion packages/local/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@animespace/core": "workspace:*",
"@breadc/color": "^0.9.6",
"anitomy": "^0.0.27",
"breadfs": "^0.0.6",
"breadfs": "^0.0.7",
"memofunc": "^0.0.6"
},
"engines": {
Expand Down
38 changes: 19 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c79737d

Please sign in to comment.