-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Function to queue up modified documents.
- Loading branch information
1 parent
bdd53ed
commit bf1c923
Showing
6 changed files
with
245 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import * as admin from "firebase-admin"; | ||
export {onUserDocWritten} from "./on-user-doc-written"; | ||
export {atMidnight} from "./at-midnight"; | ||
export {onAnalyzableDocWritten} from "./on-analyzable-doc-written"; | ||
|
||
admin.initializeApp(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {onDocumentWritten} from "firebase-functions/v2/firestore"; | ||
import {getDatabase} from "firebase-admin/database"; | ||
import * as logger from "firebase-functions/logger"; | ||
// import * as admin from "firebase-admin"; | ||
|
||
// This is one of what will likely be multiple functions for AI analysis of documents: | ||
// 1. (This function) watch for changes to the lastUpdatedAt metadata field and write a queue of docs to process | ||
// 2. Create screenshots of those documents | ||
// 3. Send those screenshots to the AI service for processing, and create document comments with the results | ||
|
||
// For now, restrict processing to a particular root for testing. | ||
// TODO later this will be a parameter. | ||
const root = "demo/AI/portals/demo"; | ||
|
||
// Location of the queue of documents to process, relative to the root | ||
const queuePath = "aiProcessingQueue"; | ||
|
||
export const onAnalyzableDocWritten = | ||
onDocumentWritten(`${root}/classes/{classId}/users/{userId}/documentMetadata/{docId}/lastUpdatedAt`, | ||
async (event) => { | ||
const {classId, userId, docId} = event.params; | ||
const database = getDatabase(); | ||
logger.info("Document update noticed", event.document, classId, userId, docId); | ||
|
||
const timestamp = await database.ref(event.document).once("value").then((snap) => { | ||
return snap.val(); | ||
}, | ||
(error) => { | ||
logger.error("Error reading document", error); | ||
}); | ||
getDatabase().ref(`${root}/${queuePath}`).update({ | ||
[docId]: { | ||
metadataPath: `classes/${classId}/users/${userId}/documentMetadata/${docId}`, | ||
updated: timestamp, | ||
status: "unanalyzed", | ||
}, | ||
}); | ||
}); | ||
|
||
|
Oops, something went wrong.