-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(file.detail): enable download file
- Loading branch information
Showing
14 changed files
with
224 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { AjaxRequest, AjaxResponse } from 'rxjs/ajax'; | ||
import { AjaxFlowInteralNode, CombErr } from '../core'; | ||
import { IRcloneServer } from '../extra'; | ||
import { GetFlow } from './get-flow'; | ||
|
||
export interface DownloadFileFlowParamsNode { | ||
remote: string; | ||
Path: string; | ||
Name: string; | ||
} | ||
export interface DownloadFileFlowInNode extends IRcloneServer, DownloadFileFlowParamsNode {} | ||
export abstract class DownloadFileFlow extends GetFlow< | ||
DownloadFileFlowInNode, | ||
{ ajaxRsp: AjaxResponse } | ||
> { | ||
// public prerequest$: Observable<CombErr<DownloadFileFlowInNode>>; | ||
protected requestAjax(x: CombErr<DownloadFileFlowInNode>): AjaxRequest { | ||
const req = super.requestAjax(x); | ||
req.url = `${x[0].url}/[${x[0].remote}:]/${x[0].Path}`; | ||
req.responseType = 'blob'; | ||
return req; | ||
} | ||
protected reconstructAjaxResult(x: AjaxFlowInteralNode): AjaxFlowInteralNode { | ||
return x; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { AjaxRequest } from 'rxjs/ajax'; | ||
import { AjaxFlow, CombErr, FlowOutNode, FlowSupNode } from '../core'; | ||
import { IRcloneServer } from '../extra'; | ||
|
||
export abstract class GetFlow< | ||
Tin extends IRcloneServer, | ||
Tout extends FlowOutNode, | ||
Tsup extends FlowSupNode = Tin & Tout | ||
> extends AjaxFlow<Tin, Tout, Tsup> { | ||
// public prerequest$: Observable<CombErr<Tin>>; | ||
protected cacheSupport = false; | ||
protected cachePath = ''; | ||
protected requestAjax(x: CombErr<Tin>): AjaxRequest { | ||
const headers = {}; | ||
if (x[0]['user'] && x[0]['user'] !== '' && x[0]['password'] && x[0]['password'] !== '') | ||
headers['Authorization'] = 'Basic ' + btoa(`${x[0]['user']}:${x[0]['password']}`); | ||
return { | ||
method: 'GET', | ||
headers, | ||
}; | ||
} | ||
// protected reconstructAjaxResult(x: AjaxFlowInteralNode): CombErr<Tout> { | ||
// throw new Error('Method not implemented.'); | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/app/pages/manager/fileMode/download-file.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* tslint:disable:no-unused-variable */ | ||
|
||
import { async, inject, TestBed } from '@angular/core/testing'; | ||
import { DownloadFileService } from './download-file.service'; | ||
|
||
describe('Service: DownloadFile', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [DownloadFileService], | ||
}); | ||
}); | ||
|
||
it('should ...', inject([DownloadFileService], (service: DownloadFileService) => { | ||
expect(service).toBeTruthy(); | ||
})); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { NbToastrService } from '@nebular/theme'; | ||
import { FileSaverService } from 'ngx-filesaver'; | ||
import { Observable, Subject } from 'rxjs'; | ||
import { map, withLatestFrom } from 'rxjs/operators'; | ||
import { CombErr } from '../../..//@dataflow/core'; | ||
import { | ||
DownloadFileFlow, | ||
DownloadFileFlowInNode, | ||
DownloadFileFlowParamsNode, | ||
} from '../../../@dataflow/rclone'; | ||
import { ConnectionService } from '../../connection.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class DownloadFileService { | ||
private trigger = new Subject<DownloadFileFlowParamsNode>(); | ||
download$: DownloadFileFlow; | ||
|
||
post(task: DownloadFileFlowParamsNode) { | ||
this.trigger.next(task); | ||
this.toastr.default(task.Name, 'Downloading ...'); | ||
} | ||
|
||
constructor( | ||
private cmdService: ConnectionService, | ||
private toastr: NbToastrService, | ||
private fileSaverService: FileSaverService | ||
) { | ||
const outer = this; | ||
this.download$ = new (class extends DownloadFileFlow { | ||
public prerequest$: Observable<CombErr<DownloadFileFlowInNode>> = outer.trigger.pipe( | ||
withLatestFrom(outer.cmdService.connection$.getOutput()), | ||
map( | ||
([item, connectNode]): CombErr<DownloadFileFlowInNode> => [ | ||
{ ...connectNode[0], ...item }, | ||
connectNode[1], | ||
] | ||
) | ||
); | ||
})(); | ||
this.download$.deploy(); | ||
this.download$.getSupersetOutput().subscribe(x => { | ||
if (x[1].length !== 0) { | ||
this.toastr.danger(`${x[0].remote}:${x[0].Path}`, 'File download failure.'); | ||
return; | ||
} | ||
this.fileSaverService.save(x[0].ajaxRsp.response, x[0].Name); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { OperationsListExtendsFlowOutItemNode } from '../../../@dataflow/extra'; | ||
import { DownloadFileService } from './download-file.service'; | ||
|
||
@Component({ | ||
selector: 'app-file-file-detail', | ||
template: ` | ||
<div *ngIf="!currentDirDetail"> | ||
<img [src]="'assets/icons/' + typeIcon" /> | ||
<h5>{{ name }}</h5> | ||
<button nbButton (click)="download()" *ngIf="!isDir">download</button> | ||
</div> | ||
`, | ||
styles: [ | ||
` | ||
div { | ||
padding: 0 1.25rem; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
img { | ||
width: 8rem; | ||
margin: 0 auto; | ||
} | ||
h5 { | ||
overflow-wrap: break-word; | ||
} | ||
`, | ||
], | ||
}) | ||
export class FileDetailComponent implements OnInit { | ||
constructor(private downloadService: DownloadFileService) {} | ||
|
||
/** if user wasn't select any item, right sidebar can show current directory detail. */ | ||
currentDirDetail = true; | ||
|
||
remote = ''; | ||
path = ''; | ||
name = ''; | ||
isDir = true; | ||
typeIcon = ''; | ||
|
||
itemNode(x: OperationsListExtendsFlowOutItemNode) { | ||
this.remote = x.remote || ''; | ||
this.path = x.Path || ''; | ||
this.name = x.Name || ''; | ||
this.isDir = x.IsDir; | ||
this.typeIcon = x.TypeIcon; | ||
if (this.remote !== '' && this.path !== '' && this.name !== '') this.currentDirDetail = false; | ||
} | ||
|
||
download() { | ||
this.downloadService.post({ remote: this.remote, Path: this.path, Name: this.name }); | ||
} | ||
|
||
ngOnInit() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters