Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
MoatzAtteya authored Oct 30, 2022
1 parent c39b16e commit 5d16e49
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,38 @@
# How to install:
* Download the project and connect it to your firebase.
* It would be better if your project is (Blaze plan) because the project uses functions and you need to upload this code.
```
const functions = require("firebase-functions");
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firestore);
exports.scheduledFunction = functions.pubsub.schedule('every 30 minutes').onRun((context) => {
// current time in miilis
const timeMillis = admin.firestore.Timestamp.now().toMillis();
console.log(timeMillis);
admin.firestore().collection('Stories').where('expiryDate', '<=', timeMillis).get()
.then((snapshot) => {
snapshot.docs.forEach((data) => {
console.log("Name: " + data.get('username'));
console.log("ID: " + data.get('id'));
console.log("UID: " + data.get('uid'));
admin.firestore().collection('Stories').doc(data.id).delete();
});
}).catch((error) => {
console.log("Error: " + error);
});
return null;
});
exports.onStoryUpload = functions.firestore.document('Stories/{storyID}')
.onCreate((snapshot, context) => {
var data = snapshot.data();
const timeMillis = admin.firestore.Timestamp.now().toMillis();
const expiryDate = timeMillis + (24 * 60 * 60 * 1000);
admin.firestore().collection('Stories').doc(data.id).update({
"expiryDate": expiryDate,
});
});
```
* If your plan is spark the project will work fine **except that the users stories will be always available not only for 24 hours**.

# Technologies & Open-source libraries
Expand Down

0 comments on commit 5d16e49

Please sign in to comment.