Skip to content

Commit

Permalink
created synthesis generation/storing pipeline on creation
Browse files Browse the repository at this point in the history
Mongodb does not support cascade deletion so some work needs to be done to delete the audio files as well when a story is deleted
  • Loading branch information
DavidMockler committed Aug 8, 2024
1 parent f459f7e commit 4019c2e
Show file tree
Hide file tree
Showing 17 changed files with 481 additions and 407 deletions.
File renamed without changes.
68 changes: 0 additions & 68 deletions api/src/endpoint/drStory/countGrammarErrors.js

This file was deleted.

63 changes: 0 additions & 63 deletions api/src/endpoint/drStory/feedbackAudio.js

This file was deleted.

59 changes: 59 additions & 0 deletions api/src/endpoint/drStory/storeSynthAudio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { API500Error } from "../../utils/APIError";

const DigitalReaderSentenceAudio = require('../../models/drSentenceAudio');
//const User = require('../../models/user');
const mongoose = require('mongoose');
const {API404Error} = require('../../utils/APIError');

const handler = async (req, res) => {

function yes() {
res.status(200).json({id: audio._id});
}
function no(status=404, msg='not found') {
res.status(status).json(msg);
}

console.log(req.body);

//if (!req.body.audioPromise) return no(501, 'no audio promise provided');
if (!req.body.audioUrl) return no(501, 'no audio url provided');
if (!req.body.audioTiming) return no(501, 'no audio timing provided');
if (!req.body.drStoryId) return no(501, 'no story id provided');
if (req.body.sentId === undefined) return no(501, 'no sentence id provided');
if (!req.body.voice) return no(501, 'no voice code parameter provided');

// check that the current user owns the provided story (or is an admin) (?)

let audio;

//const audioPromise:Promise<any> = req.body.audioPromise;
//console.log(audioPromise);

//audioPromise.then(
//async (response:any) => {
//console.log(response);
//const audioUrl = response.audioContent;
//const timing = response.timing;
//console.log(audioUrl);
//if (audioUrl) {
audio = await DigitalReaderSentenceAudio.create({
drStoryId: req.body.storyId,
sentenceId: req.body.sentId,
voice: req.body.voice,
audioUrl: req.body.audioUrl,
timing: req.body.audioTiming,
});
if (!audio) {
throw new API500Error('Unable to save audio file to DB. It may be too large');
}
yes();
//}
//}
//);

return no();

};

export = handler;
28 changes: 0 additions & 28 deletions api/src/endpoint/drStory/viewFeedback.js

This file was deleted.

26 changes: 0 additions & 26 deletions api/src/endpoint/drStory/withId.js

This file was deleted.

29 changes: 29 additions & 0 deletions api/src/models/drSentenceAudio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const DigitalReaderSentenceAudio = new Schema(
{
drStoryId: {
type: mongoose.Types.ObjectId,
index: true,
},
sentenceId: {
type: Number,
},
voice: {
type: String,
},
timing: {
type: Array,
},
audioUrl: {
type: String,
},
},
{
collection: 'drSentenceAudio',
timestamps: true
},
);

export = mongoose.model('DigitalReaderSentenceAudio', DigitalReaderSentenceAudio);
22 changes: 12 additions & 10 deletions api/src/routes/drStory.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ let storyRoutes;

// POST
const create = require("../endpoint/drStory/create");
const storeSynthAudio = require("../endpoint/drStory/storeSynthAudio");
/*const viewFeedback = require("../endpoint/story/viewFeedback");
const updateStoryAndCheckGrammar = require("../endpoint/story/updateStoryAndCheckGrammar");
const averageWordCount = require("../endpoint/story/averageWordCount");
Expand All @@ -60,6 +61,7 @@ let storyRoutes;
post: {
"/create": create,
"/getMatchingWords": getMatchingWords,
"/storeSynthAudio": storeSynthAudio,
//"/viewFeedback/:id": viewFeedback,
//"/updateStoryAndCheckGrammar": updateStoryAndCheckGrammar,
/*"/averageWordCount/:studentId": averageWordCount,
Expand All @@ -74,7 +76,7 @@ let storyRoutes;
* @param {Object} req params: Date classroom created
* @return {Object} List of stories
*/
storyRoutes
/*storyRoutes
.route("/getStoriesForClassroom/:owner/:date")
.get(function (req, res) {
const conditions = { owner: req.params.owner };
Expand All @@ -91,15 +93,15 @@ storyRoutes
res.json(stories);
}
});
});
});*/

/**
* Get total number of stories for a given user (owner) with optional classroom creation date filter
* @param {Object} req params: User ID
* @param {Object} req params: Date classroom created
* @return {Object} List of stories
*/
storyRoutes.route("/getNumberOfStories/:owner/:date").get(function (req, res) {
/*storyRoutes.route("/getNumberOfStories/:owner/:date").get(function (req, res) {
const conditions = { owner: req.params.owner };
if (req.params.date != "empty") {
conditions["date"] = {
Expand All @@ -114,14 +116,14 @@ storyRoutes.route("/getNumberOfStories/:owner/:date").get(function (req, res) {
res.json(count);
}
});
});
});*/

/**
* Get a story by ID
* @param {Object} req params: Story ID
* @return {Object} Story object
*/
storyRoutes.route("/viewStory/:id").get(function (req, res) {
/*storyRoutes.route("/viewStory/:id").get(function (req, res) {
Story.find({ _id: req.params.id }, (err, story) => {
if (err) {
console.log(err);
Expand All @@ -130,15 +132,15 @@ storyRoutes.route("/viewStory/:id").get(function (req, res) {
res.json(story);
}
});
});
});*/

/**
* Update story information
* @param {Object} req params: Story ID
* @param {Object} req body: new story data
* @return {Object} Success or error message
*/
storyRoutes.route("/update/:id").post((req, res) => {
/*storyRoutes.route("/update/:id").post((req, res) => {
Story.findById(req.params.id, function (err, story) {
if (err) {
console.log(err);
Expand All @@ -163,15 +165,15 @@ storyRoutes.route("/update/:id").post((req, res) => {
(err) => res.status(400).json(err)
);
});
});
});*/

/**
* Update story title
* @param {Object} req params: Story ID
* @param {Object} req body: new story title
* @return {Object} Success or error message
*/
storyRoutes.route("/updateTitle/:id").post((req, res) => {
/*storyRoutes.route("/updateTitle/:id").post((req, res) => {
Story.findById(req.params.id, function (err, story) {
if (err) {
console.log(err);
Expand All @@ -189,7 +191,7 @@ storyRoutes.route("/updateTitle/:id").post((req, res) => {
(err) => res.status(400).json(err)
);
});
});
});*/

/**
* Delete a story by ID
Expand Down
Loading

0 comments on commit 4019c2e

Please sign in to comment.