Skip to content

Commit 6802a9b

Browse files
committed
feat(image-loader): allow setting FileTransfer options
closes #88
1 parent 9ca29d8 commit 6802a9b

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,19 @@ Example:
266266
this.imageLoaderConfig.enableFallbackAsPlaceholder(true);
267267
```
268268
---
269+
#### setFileTransferOptions(options: any)
270+
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.
271+
272+
Example:
273+
```ts
274+
this.imageLoaderConfig.setFileTransferOptions({
275+
trustAllHosts: true, // defaults to false
276+
headers: {
277+
Authorization: 'Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA=='
278+
}
279+
});
280+
```
281+
---
269282
270283
# Preloading images
271284
```typescript

src/providers/image-loader-config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export class ImageLoaderConfig {
3535

3636
spinnerColor: string;
3737

38+
fileTransferOptions: any = {
39+
trustAllHosts: false
40+
};
41+
3842
private _cacheDirectoryName: string = 'image-loader-cache';
3943

4044
set cacheDirectoryName(name: string) {
@@ -182,4 +186,12 @@ export class ImageLoaderConfig {
182186
this.spinnerColor = color;
183187
}
184188

189+
/**
190+
* Set options for the FileTransfer plugin
191+
* @param options
192+
*/
193+
setFileTransferOptions(options: { trustAllHosts: boolean; [key: string]: any; }): void {
194+
this.fileTransferOptions = options;
195+
}
196+
185197
}

src/providers/image-loader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export class ImageLoader {
241241

242242
// take the first item from queue
243243
const currentItem: QueueItem = this.queue.splice(0, 1)[0];
244-
244+
245245
// create FileTransferObject instance if needed
246246
// we would only reach here if current jobs < concurrency limit
247247
// so, there's no need to check anything other than the length of
@@ -266,7 +266,7 @@ export class ImageLoader {
266266

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

269-
transfer.download(currentItem.imageUrl, localPath)
269+
transfer.download(currentItem.imageUrl, localPath, Boolean(this.config.fileTransferOptions.trustAllHosts), this.config.fileTransferOptions)
270270
.then((file: FileEntry) => {
271271
if (this.shouldIndex) {
272272
this.addFileToIndex(file).then(this.maintainCacheSize.bind(this));

0 commit comments

Comments
 (0)