Last active
October 15, 2022 05:06
-
-
Save rootasjey/2b9fb6e03729f1474af0da6c60106f93 to your computer and use it in GitHub Desktop.
A function to fetch a markdown post file in Firebase Storage from Cloud Function (old way).
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
/** | |
* Save a project content | |
* (with accessibility check). | |
*/ | |
export const save = functions | |
.region(cloudRegions.eu) | |
.https | |
.onCall(async (data) => { | |
const projectId: string = data.projectId; | |
const jwt: string = data.jwt; | |
const content: string = data.content; | |
if (!content || !projectId) { | |
throw new functions.https.HttpsError( | |
"invalid-argument", | |
`The function must be called | |
with two (string) arguments "projecId": | |
the project to save, "content": the project's content.`, | |
); | |
} | |
// Check this helper function in its dedicated gist. | |
// [firebase_functions_helper_post_acl.ts](https://gist.github.com/rootasjey/6b8594cd4da10822c5029a6997f1b8c6) | |
await checkAccessControl({projectId, jwt}); | |
const projectFile = storage | |
.bucket() | |
.file(`blog/projects/${projectId}/post.md`); | |
try { | |
await projectFile.save(content); | |
return {success: true}; | |
} catch (error) { | |
return {success: false, error: error}; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment