☙◦ The Tablet ❀ GamerGirlandCo ◦❧
c8bdcc0ec3
`bodyHandler` takes a request body and returns the chapter content as a string `formChapterTransform` serializes a chapter-like object supplied in a request body to an actual proper chapter object `getBucket` retrieves the story content gridfs bucket `replaceGridFS` either creates or updates (deletes + reuploads) a gridfs file
20 lines
518 B
TypeScript
20 lines
518 B
TypeScript
import getBucket from "./getBucket";
|
|
import { Readable } from "stream";
|
|
export default async function replaceGridFS(
|
|
chapterID: number | undefined,
|
|
content: string,
|
|
) {
|
|
let filename = `/stories/${chapterID}.txt`;
|
|
const bucket = getBucket();
|
|
if (chapterID) {
|
|
const curs = bucket.find({ filename }).limit(1);
|
|
for await (const d of curs) {
|
|
await bucket.delete(d._id);
|
|
}
|
|
}
|
|
const readable = new Readable();
|
|
readable.push(content);
|
|
readable.push(null);
|
|
readable.pipe(bucket.openUploadStream(filename));
|
|
}
|