Skip to content

Commit a5ae2ce

Browse files
camera image display problem fixed, readme updates
1 parent 79a130a commit a5ae2ce

File tree

10 files changed

+718
-1265
lines changed

10 files changed

+718
-1265
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ private getGoogleMaps(): Promise<any> {
119119

120120
## Status & To-do list
121121

122-
* Status: working 95%. Bookings can be made and new places added to offers page. If a different user is logged in they cannot book their own places (the booking button does not show) - which is correct.
123-
* To-do: correct issues: Camera image does not display. Bookable place list is the same as the 'All Places' list - bookable places should not include the logged in users' places. 'My Offers' includes everyones places. 'Your Bookings' does not work - check path.
122+
* Status: working. Bookings can be made and new places added to offers page. If a different user is logged in they cannot book their own places (the booking button does not show) - which is correct. Camera images now show.
123+
* To-do: Bookable place list is the same as the 'All Places' list - bookable places should not include the logged in users' places. 'My Offers' includes everyones places. 'Your Bookings' does not work - check path - fix error with create-booking component. Fix error with svg calender icon - appears every time but the icon is displayed.
124124

125125
## Inspiration
126126

functions/index.js

+34-14
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,34 @@ const os = require('os');
55
const path = require('path');
66
const fs = require('fs');
77
const uuid = require('uuid/v4');
8+
const fbAdmin = require('firebase-admin');
89

910
const { Storage } = require('@google-cloud/storage');
1011

1112
const storage = new Storage({
1213
projectId: 'ionic-maps-api-1565705298126'
1314
});
1415

16+
fbAdmin.initializeApp({
17+
credential: fbAdmin.credential.cert(require('firebase-key-here'))
18+
});
19+
1520
exports.storeImage = functions.https.onRequest((req, res) => {
1621
return cors(req, res, () => {
1722
if (req.method !== 'POST') {
1823
return res.status(500).json({ message: 'Not allowed.' });
1924
}
25+
26+
if (
27+
!req.headers.authorization ||
28+
!req.headers.authorization.startsWith('Bearer ')
29+
) {
30+
return res.status(401).json({ error: 'Unauthorized!' });
31+
}
32+
33+
let idToken;
34+
idToken = req.headers.authorization.split('Bearer ')[1];
35+
2036
const busboy = new Busboy({ headers: req.headers });
2137
let uploadData;
2238
let oldImagePath;
@@ -37,21 +53,25 @@ exports.storeImage = functions.https.onRequest((req, res) => {
3753
if (oldImagePath) {
3854
imagePath = oldImagePath;
3955
}
40-
41-
console.log(uploadData.type);
42-
return storage
43-
.bucket('ionic-maps-api-1565705298126.appspot.com')
44-
.upload(uploadData.filePath, {
45-
uploadType: 'media',
46-
destination: imagePath,
47-
metadata: {
48-
metadata: {
49-
contentType: uploadData.type,
50-
firebaseStorageDownloadTokens: id
51-
}
52-
}
56+
57+
return fbAdmin
58+
.auth()
59+
.verifyIdToken(idToken)
60+
.then(decodedToken => {
61+
console.log(uploadData.type);
62+
return storage
63+
.bucket('ionic-maps-api-1565705298126.appspot.com')
64+
.upload(uploadData.filePath, {
65+
uploadType: 'media',
66+
destination: imagePath,
67+
metadata: {
68+
metadata: {
69+
contentType: uploadData.type,
70+
firebaseStorageDownloadTokens: id
71+
}
72+
}
73+
});
5374
})
54-
5575
.then(() => {
5676
return res.status(201).json({
5777
imageUrl:

0 commit comments

Comments
 (0)