diff --git a/Client/src/app/components/image/image.component.html b/Client/src/app/components/image/image.component.html index 3a68a05..7c9a253 100644 --- a/Client/src/app/components/image/image.component.html +++ b/Client/src/app/components/image/image.component.html @@ -1,13 +1,13 @@
- - +
- +
\ No newline at end of file diff --git a/Client/src/app/components/image/image.component.ts b/Client/src/app/components/image/image.component.ts index 17c74e6..f3b009e 100644 --- a/Client/src/app/components/image/image.component.ts +++ b/Client/src/app/components/image/image.component.ts @@ -13,9 +13,11 @@ import { Router, ActivatedRouteSnapshot, ActivatedRoute } from '@angular/router' export class ImageComponent implements OnInit { public imageUrl: string; + public shareName: string constructor(private dialog: MatDialog, @Inject(DOCUMENT) private document, private route: ActivatedRoute) { this.imageUrl = this.route.snapshot.data.imageUrl; + this.shareName = this.route.snapshot.data.shareName; } ngOnInit() { @@ -27,18 +29,10 @@ export class ImageComponent implements OnInit { } public share() { - let port = this.document.location.port ? ":"+this.document.location.port : ""; - let baseUrl = this.document.location.protocol +'//'+ this.document.location.hostname + port let opts = new MatDialogConfig; opts.data = { prefix: 'o', - otherData: { - imageUrl: baseUrl + '/static/media/images/covid_fb_share.jpg', - imageWidth: 750, - imageHeight: 404, - title: 'Coronavirus Anxiety?', - description: 'The cure for coronavirus anxiety' - } + otherName: this.shareName }; let dialog = this.dialog.open(SharePopupComponent, opts); } diff --git a/Client/src/app/components/popups/share-popup/share-popup.component.ts b/Client/src/app/components/popups/share-popup/share-popup.component.ts index fb02941..6b99c77 100644 --- a/Client/src/app/components/popups/share-popup/share-popup.component.ts +++ b/Client/src/app/components/popups/share-popup/share-popup.component.ts @@ -31,10 +31,7 @@ export class SharePopupComponent implements OnInit { let port = this.document.location.port ? ":"+this.document.location.port : ""; this.shareUrl = this.document.location.protocol +'//'+ this.document.location.hostname + port + this.shareBaseUrl + data.prefix + this.id; if (this.data.prefix === 'o') { - const str = JSON.stringify(this.data.otherData); - const encoded = encodeURIComponent(str); - const shareData = encoded; - this.shareUrl = this.document.location.protocol + '//' + this.document.location.hostname + port + this.shareBaseUrl + data.prefix + shareData; + this.shareUrl = this.document.location.protocol + '//' + this.document.location.hostname + port + this.shareBaseUrl + data.prefix + data.otherName; } this.facebookIframeUrl = this.urlPartA + this.shareUrl + this.urlPartB; this.twitterUrl = this.twitterPartA + data.title + " - " + data.description + "&url=" + this.shareUrl; diff --git a/Client/src/assets/share/covid/covid_header.jpg b/Client/src/assets/share/covid/covid_header.jpg new file mode 100644 index 0000000..ca742f9 Binary files /dev/null and b/Client/src/assets/share/covid/covid_header.jpg differ diff --git a/Client/src/assets/share/covid/meta.json b/Client/src/assets/share/covid/meta.json new file mode 100644 index 0000000..3669836 --- /dev/null +++ b/Client/src/assets/share/covid/meta.json @@ -0,0 +1,8 @@ +{ + "title": "Coronavirus Anxiety?", + "description": "The cure for coronavirus anxiety", + "imageUrl": "/covid_header.jpg", + "imageWidth": 750, + "imageHeight": 404, + "url": "/covid" +} \ No newline at end of file diff --git a/Client/src/assets/share/covid2/covid_header_2.jpg b/Client/src/assets/share/covid2/covid_header_2.jpg new file mode 100644 index 0000000..11a2c94 Binary files /dev/null and b/Client/src/assets/share/covid2/covid_header_2.jpg differ diff --git a/Client/src/assets/share/covid2/meta.json b/Client/src/assets/share/covid2/meta.json new file mode 100644 index 0000000..e69de29 diff --git a/Server/src/routes/api/share.js b/Server/src/routes/api/share.js index 1c36914..b747f31 100644 --- a/Server/src/routes/api/share.js +++ b/Server/src/routes/api/share.js @@ -33,13 +33,13 @@ router.get("/:shareCode",function(req,res){ }); function getOther(req, res, param) { - const jsonPath = req.protocol + '://' + req.hostname + shareFolder + param + '.json'; + const jsonPath = req.protocol + '://' + req.hostname + shareFolder + param + '/meta.json'; http.get(jsonPath, resp => { - processOtherJson(req, res, JSON.parse(resp)); + processOtherJson(req, res, JSON.parse(resp), jsonPath); }); } -function processOtherJson(req, res, json) { +function processOtherJson(req, res, json, basePath) { var userAgent = req.headers['user-agent']; var userAgentOverride = req.headers['user-agent-override']; var referrer = req.headers['referer'] || ""; @@ -48,10 +48,11 @@ function processOtherJson(req, res, json) { userAgent === 'Facebot' || userAgent.startsWith('Twitterbot') || referrer.startsWith('http://opengraphcheck.com')) { + const imageUrl = basePath + json.imageUrl; getOtherMeta(req, res, json.title, json.description, json.imageUrl, json.imageWidth, json.imageHeight); } else { - var url = json.url || (req.protocol + "://" + req.hostname + req.originalUrl); - res.redirect(url); + const redirect = req.protocol + '://' + req.hostname + json.url; + res.redirect(redirect); } }