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

List trigger #52

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
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
142 changes: 95 additions & 47 deletions package-lock.json

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

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"dependencies": {
"@sendgrid/mail": "^7.0.0",
"@slack/webhook": "^5.0.3",
"@types/mkdirp": "^1.0.1",
"@types/node": "^14.0.27",
"@types/sharp": "^0.25.1",
"@types/tmp": "^0.2.0",
"algoliasearch": "^4.3.0",
"axios": "^0.19.2",
Expand All @@ -29,7 +32,8 @@
"javascript-stringify": "^2.0.1",
"mkdirp": "^1.0.4",
"moment": "^2.25.2",
"sharp": "^0.25.2",
"pure-uuid": "^1.6.1",
"sharp": "^0.25.4",
"tmp": "^0.2.1"
},
"devDependencies": {
Expand Down
74 changes: 74 additions & 0 deletions src/api/merklisteMetaPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';

export const merklisteMetaPage = functions.https.onRequest(async (req, res) => {
const path = req.path.split('/');
const merklisteId = path[2];
const documentRef = admin.firestore().doc('Merkliste_PUBLIC/' + merklisteId);
const merklistePub = await documentRef
.get()
.then((snapshot: any) => {
return snapshot.data();
})
.catch((err: any) => {
console.log('Error getting documents', err);
});
const bucket = admin.storage().bucket();
const imagePath = `Merklisten/${merklisteId}/preview.jpg`;
const url =
(await 'https://firebasestorage.googleapis.com/v0/b/') +
bucket.name +
'/o/' +
encodeURIComponent(imagePath) +
'?alt=media';
res.status(200).send(buildHtmlWithMerkliste(merklistePub, url, merklisteId));
});

function buildHtmlWithMerkliste(merklistePub: any, imageUrl: string, merklisteId: string) {
const url = functions.config().app.url;
let html;
if (merklistePub && merklistePub.isActive === true) {
html = `
<!DOCTYPE html><head>
<title>lokalkauf | ${merklistePub.name} </title>
<meta name="description" content="${merklistePub.description}"/>
<meta property="twitter:title" content="lokalkauf | ${merklistePub.name}"/>
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:description" content="${merklistePub.description}"/>
<meta name="twitter:image" content="${imageUrl}"/>
<meta name="twitter:site" content="@loaklkauf"/>
<meta name="twitter:creator" content="@lokalkauf"/>
<meta property="og:title" content="lokalkauf | ${merklistePub.name}"/>
<meta property="og:image" itemprop="image" content="${imageUrl}"/>
<meta property="og:type" content="web app"/>
<meta property="og:description" content="${merklistePub.description}"/>
<link rel="icon" href="https://www.lokalkauf.org/assets/lokalkauf-logo.svg"/>
</head><body>
<script>window.location.replace("${url}/bookmarks-public-redirect/${merklisteId}");</script>
</body></html>
`}
else {
html = `
<!DOCTYPE html><head>
<title>lokalkauf | #ichkaufelokal </title>
<meta name="description" content="Ich kaufe lokal!"/>
<meta property="twitter:title" content="lokalkauf | #ichkaufelokal"/>
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:description" content="Ich kaufe lokal!"/>
<meta name="twitter:image" content="https://www.lokalkauf.org/assets/lokalkauf-logo.svg"/>
<meta name="twitter:site" content="@loaklkauf"/>
<meta name="twitter:creator" content="@lokalkauf"/>
<meta property="og:title" content="lokalkauf | #ichkaufelokal"/>
<meta property="og:image" itemprop="image" content="https://www.lokalkauf.org/assets/lokalkaufSocialMedia.png"/>
<meta property="og:image:width" content="926"/>
<meta property="og:image:height" content="1079"/>
<meta property="og:type" content="web app"/>
<meta property="og:description" content="Ich kaufe lokal!"/>
<link rel="icon" href="https://www.lokalkauf.org/assets/lokalkaufSocialMedia.png"/>
</head><body>
<script>window.location.replace("${url}/bookmarks-public-redirect/${merklisteId}");</script>
</body></html>`
}

return html;
}
Loading