diff --git a/src/app/@dataflow/rclone/index.ts b/src/app/@dataflow/rclone/index.ts index 2747c88..b6e066e 100644 --- a/src/app/@dataflow/rclone/index.ts +++ b/src/app/@dataflow/rclone/index.ts @@ -9,3 +9,4 @@ export * from './list-group-flow'; export * from './operations-mkdir-flow'; export * from './async-post-flow'; export * from './operations-copyfile-flow'; +export * from './operations-movefile-flow'; diff --git a/src/app/@dataflow/rclone/operations-movefile-flow.ts b/src/app/@dataflow/rclone/operations-movefile-flow.ts new file mode 100644 index 0000000..ea9a8f1 --- /dev/null +++ b/src/app/@dataflow/rclone/operations-movefile-flow.ts @@ -0,0 +1,37 @@ +import { IRcloneServer } from '../extra'; +import { CombErr } from '../core'; +import { AsyncPostFlow, AsyncPostFlowParamsNode } from './async-post-flow'; + +export interface OperationsMovefileFlowParamsNode extends AsyncPostFlowParamsNode { + /** a remote name string eg “drive:” for the source */ + srcFs: string; + /** a path within that remote eg “file.txt” for the source */ + srcRemote: string; + /** a remote name string eg “drive2:” for the destination */ + dstFs: string; + /** a path within that remote eg “file2.txt” for the destination */ + dstRemote: string; +} +export interface OperationsMovefileFlowInNode + extends OperationsMovefileFlowParamsNode, + IRcloneServer {} + +export abstract class OperationsMovefileFlow extends AsyncPostFlow< + OperationsMovefileFlowInNode, + OperationsMovefileFlowParamsNode +> { + // public prerequest$: Observable>; + protected cmd: string = 'operations/movefile'; + protected params = ( + pre: CombErr + ): OperationsMovefileFlowParamsNode => { + if (pre[1].length !== 0) return {} as any; + return { + srcFs: pre[0].srcFs, + srcRemote: pre[0].srcRemote, + dstFs: pre[0].dstFs, + dstRemote: pre[0].dstRemote, + }; + }; + protected cacheSupport: boolean = false; +} diff --git a/src/app/pages/manager/tasks/task.service.ts b/src/app/pages/manager/tasks/task.service.ts index ee3d44a..2288536 100644 --- a/src/app/pages/manager/tasks/task.service.ts +++ b/src/app/pages/manager/tasks/task.service.ts @@ -1,5 +1,11 @@ import { Injectable } from '@angular/core'; -import { OperationsCopyfileFlow, OperationsCopyfileFlowInNode } from 'src/app/@dataflow/rclone'; +import { + OperationsCopyfileFlow, + OperationsCopyfileFlowInNode, + AsyncPostFlowOutNode, + OperationsMovefileFlow, + OperationsMovefileFlowInNode, +} from 'src/app/@dataflow/rclone'; import { ClipboardService, Clipboard, ClipboardItem } from '../clipboard/clipboard.service'; import { Subject, from, Observable } from 'rxjs'; import { @@ -94,12 +100,50 @@ export class TaskService { this.copyFile$ .getOutput() .pipe(zip(taskReal$)) - .subscribe(([x, y]) => { - this.tasksPool.pop(y.srcRemote, y.srcItem.Path); // TODO: replase as del rather pop, for perf - this.emptySlot++; - if (x[1].length !== 0) this.tasksFailure.add(y.oper, y.srcRemote, y.srcItem, y.dst); - this.detailTrigger.next(1); - this.postTrigger.next(1); + .subscribe((x) => { + this.postAfter(...x); + }); + } + + private postAfter(output: CombErr, task: ClipboardItem) { + this.tasksPool.pop(task.srcRemote, task.srcItem.Path); // TODO: replase as del rather pop, for perf + this.emptySlot++; + if (output[1].length !== 0) + this.tasksFailure.add(task.oper, task.srcRemote, task.srcItem, task.dst); + this.detailTrigger.next(1); + this.postTrigger.next(1); + } + + private moveFile$: OperationsMovefileFlow; + private deployMoveFile() { + const outer = this; + const taskReal$ = outer.post$.pipe(filter((x) => x.oper === 'move' && !x.srcItem.IsDir)); + this.moveFile$ = new (class extends OperationsMovefileFlow { + public prerequest$ = taskReal$.pipe( + withLatestFrom(outer.connectService.listCmd$.verify(this.cmd)), + map( + ([item, cmdNode]): CombErr => { + if (cmdNode[1].length !== 0) return [{}, cmdNode[1]] as any; + return [ + { + ...cmdNode[0], + srcFs: `${item.srcRemote}:`, + srcRemote: item.srcItem.Path, + dstFs: `${item.dst.remote}:`, + dstRemote: [item.dst.path, item.srcItem.Name].join('/'), // TODO: windows path delimiter '\' ? + }, + [], + ]; + } + ) + ); + })(); + this.moveFile$.deploy(); + this.moveFile$ + .getOutput() + .pipe(zip(taskReal$)) + .subscribe((x) => { + this.postAfter(...x); }); } @@ -139,6 +183,7 @@ export class TaskService { this.deployCreate(); this.deployPost(); this.deployCopyFile(); + this.deployMoveFile(); this.deployDetail(); } }