Skip to content

Commit

Permalink
feat(move-file-flow): enable move file now
Browse files Browse the repository at this point in the history
  • Loading branch information
ElonH committed Jun 1, 2020
1 parent bab48c7 commit 2b2a94d
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/app/@dataflow/rclone/index.ts
Expand Up @@ -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';
37 changes: 37 additions & 0 deletions 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<CombErr<OperationsMovefileFlowInNode>>;
protected cmd: string = 'operations/movefile';
protected params = (
pre: CombErr<OperationsMovefileFlowInNode>
): 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;
}
59 changes: 52 additions & 7 deletions 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 {
Expand Down Expand Up @@ -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<AsyncPostFlowOutNode>, 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<OperationsMovefileFlowInNode> => {
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);
});
}

Expand Down Expand Up @@ -139,6 +183,7 @@ export class TaskService {
this.deployCreate();
this.deployPost();
this.deployCopyFile();
this.deployMoveFile();
this.deployDetail();
}
}

0 comments on commit 2b2a94d

Please sign in to comment.