snics/ng2-avatar

protocol-agnostic approach breaks when using file: as protocol

Closed this issue · 3 comments

For example when using Cordova and/or Ionic the Gravatar URL of the request will look like file://www.gravatar.com/avatar/...?s=40&d=404.
There may should be a check if http is used at all.

this.gravatarUrl = `//www.gravatar.com/avatar/${hash}?s=${this.size}&d=404`;

snics commented

Thank you very much of course this is a useful idea but how can the location of the protocol be verified according to your opinion?

My first idea would be something like:

if (window.location.protocol.startsWith('http')) {
    this.gravatarUrl = `//www.gravatar.com/avatar/${hash}?s=${this.size}&d=404`;
} else {
    this.gravatarUrl = `https//www.gravatar.com/avatar/${hash}?s=${this.size}&d=404`;
}

But of cause, this is not very independent of the used platform running this component.
What about adding an optional property for this?
I will provide a MR in a second.

snics commented

@stetro Your changes are now published on NPM under version 2.1.1.