Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security fix #100

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@angular-material-extensions/link-preview",
"description": "Angular open source UI library to preview web links",
"version": "1.1.1",
"version": "1.1.3",
"homepage": "https://github.com/angular-material-extensions/link-preview",
"author": {
"name": "Anthony Nahas",
Expand Down
36 changes: 12 additions & 24 deletions src/module/directives/mat-link-preview.directive.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
import {Directive, OnInit} from '@angular/core';
import {fromEvent} from 'rxjs';
import {debounceTime, distinctUntilChanged, map} from 'rxjs/operators';
import {Directive, ElementRef, Input, OnInit} from '@angular/core';
import {Link, NgxLinkifyjsService} from 'ngx-linkifyjs';
import {MatLinkPreviewService} from '../../module/service/mat-link-preview.service';

@Directive({
selector: '[matLinkPreview]',
exportAs: '[matLinkPreview]',
})
export class MatLinkPreviewDirective implements OnInit {
export class MatLinkPreviewDirective implements OnInit {

constructor(public linkifyService: NgxLinkifyjsService,
public linkPreviewService: MatLinkPreviewService) {
public linkPreviewService: MatLinkPreviewService,
private _elemRef: ElementRef) {
}

ngOnInit(): void {
this._init();
}

private _init() {
fromEvent(document, 'input')
.pipe(
debounceTime(2000),
distinctUntilChanged(),
map(event => {
const data = event.target['value'];
const links: Link[] = this.linkifyService.find(data);
console.log('data: ', data);
console.log('links: ', links);
// event.target['value'] = this.linkifyService.linkify(data);
return links;
})).subscribe((links) => {
this.linkPreviewService.onLinkFound.emit(links);
});
ngOnInit() {
this._elemRef.nativeElement.oninput = (inputEvent: any) => {
setTimeout( () => {
const data = inputEvent.target.value;
const links: Link[] = this.linkifyService.find(data);
this.linkPreviewService.onLinkFound.emit(links);
}, 2000)
};
}

}
2 changes: 1 addition & 1 deletion src/module/service/link-preview.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('MatLinkPreviewService', () => {

return req.url === 'https://api.linkpreview.net/'
&& req.method === 'GET'
&& params.get('key') === '5b54e80a65c77848ceaa4630331e8384950e09d392365'
&& params.get('key') === ''
&& params.get('q') === 'github.com';
}, `Get link info from api`);
})));
Expand Down
13 changes: 7 additions & 6 deletions src/module/service/mat-link-preview.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {LinkPreview} from '../..';
@Injectable()
export class MatLinkPreviewService {

private _accessKey = '5b54e80a65c77848ceaa4630331e8384950e09d392365';
private _accessKey = '';
private _apiURL = 'https://api.linkpreview.net/';

onLinkFound: EventEmitter<Array<Link>> = new EventEmitter<Array<Link>>();
Expand All @@ -19,12 +19,13 @@ export class MatLinkPreviewService {
this.onLinkFound.subscribe((links: Array<Link>) => this.links = links);
}

setAccessKey(accessKey: string) {
this._accessKey = accessKey;
}

fetchLink(url: string): Observable<LinkPreview> {
console.log('fetching the following link: ', url);
const params = new HttpParams()
.append('key', this._accessKey)
.append('q', url);
const body = { key: this._accessKey, q: url };

return this.http.get(this._apiURL, {params: params}).pipe(map(value => value as LinkPreview));
return this.http.post(this._apiURL, body).pipe(map(value => value as LinkPreview));
}
}