Skip to content

Commit

Permalink
feat(image-loader): allow setting FileTransfer options
Browse files Browse the repository at this point in the history
closes #88
  • Loading branch information
ihadeed committed Sep 2, 2017
1 parent 9ca29d8 commit 6802a9b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,19 @@ Example:
this.imageLoaderConfig.enableFallbackAsPlaceholder(true);
```
---
#### setFileTransferOptions(options: any)
Set options for FileTransfer plugin to use. If you would like to set a value for the `trustAllHosts` param, you can add it to the options object.
Example:
```ts
this.imageLoaderConfig.setFileTransferOptions({
trustAllHosts: true, // defaults to false
headers: {
Authorization: 'Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=='
}
});
```
---
# Preloading images
```typescript
Expand Down
12 changes: 12 additions & 0 deletions src/providers/image-loader-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export class ImageLoaderConfig {

spinnerColor: string;

fileTransferOptions: any = {
trustAllHosts: false
};

private _cacheDirectoryName: string = 'image-loader-cache';

set cacheDirectoryName(name: string) {
Expand Down Expand Up @@ -182,4 +186,12 @@ export class ImageLoaderConfig {
this.spinnerColor = color;
}

/**
* Set options for the FileTransfer plugin
* @param options
*/
setFileTransferOptions(options: { trustAllHosts: boolean; [key: string]: any; }): void {
this.fileTransferOptions = options;
}

}
4 changes: 2 additions & 2 deletions src/providers/image-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class ImageLoader {

// take the first item from queue
const currentItem: QueueItem = this.queue.splice(0, 1)[0];

// create FileTransferObject instance if needed
// we would only reach here if current jobs < concurrency limit
// so, there's no need to check anything other than the length of
Expand All @@ -266,7 +266,7 @@ export class ImageLoader {

const localPath = this.file.cacheDirectory + this.config.cacheDirectoryName + '/' + this.createFileName(currentItem.imageUrl);

transfer.download(currentItem.imageUrl, localPath)
transfer.download(currentItem.imageUrl, localPath, Boolean(this.config.fileTransferOptions.trustAllHosts), this.config.fileTransferOptions)
.then((file: FileEntry) => {
if (this.shouldIndex) {
this.addFileToIndex(file).then(this.maintainCacheSize.bind(this));
Expand Down

0 comments on commit 6802a9b

Please sign in to comment.