/** * Retrieve a project's content in markdown format * (with accessibility check). */ export const fetch = functions .region(cloudRegions.eu) .https .onCall(async (data) => { const projectId: string = data.projectId; /** Used if the project is a draft or restricted to some members. */ const jwt: string = data.jwt; if (!projectId) { throw new functions.https.HttpsError( "invalid-argument", `The function must be called with one (string) argument "projectId" which is the project to fetch.`, ); } await checkAccessControl({projectId, jwt}); // Retrieve content (access control OK) const projectFile = storage .bucket() .file(`blog/projects/${projectId}/post.md`); let projectContent = ""; const stream = projectFile.createReadStream(); stream.on("data", (chunck) => { projectContent = projectContent.concat(chunck.toString()); }); await new Promise((fulfill) => stream.on("end", fulfill)); stream.destroy(); return {project: projectContent}; });