From c5783feca9c420d81178f4ce149d554ca3dfe860 Mon Sep 17 00:00:00 2001 From: mntmn Date: Sun, 15 Apr 2018 00:23:52 +0200 Subject: [PATCH] fix some artifact serialization trouble; fix login error --- helpers/artifact_converter.js | 6 +++++- locales/de.js | 2 +- locales/en.js | 5 ++--- locales/fr.js | 4 ++-- models/db.js | 12 ++++++------ public/javascripts/spacedeck_board_artifacts.js | 9 +++++---- routes/api/sessions.js | 7 ++++--- routes/api/space_artifacts.js | 12 +++--------- 8 files changed, 28 insertions(+), 29 deletions(-) diff --git a/helpers/artifact_converter.js b/helpers/artifact_converter.js index 76c22e1..450ca43 100644 --- a/helpers/artifact_converter.js +++ b/helpers/artifact_converter.js @@ -37,7 +37,7 @@ const convertableAudioTypes = [ "application/ogg", "audio/amr", "audio/3ga", - "audio/wav", + "audio/wave", "audio/3gpp", "audio/x-wav", "audio/aiff", @@ -263,6 +263,8 @@ var resizeAndUploadImage = function(a, mimeType, size, fileName, fileNameOrg, im a.h = Math.round(size.height*factor); a.updated_at = new Date(); + db.packArtifact(a); + a.save().then(function() { fs.unlink(originalFilePath, function (err) { if (err){ @@ -328,6 +330,8 @@ module.exports = { a.h = Math.round(size.height*factor); a.updated_at = new Date(); + db.packArtifact(a); + a.save().then(function() { fs.unlink(localFilePath, function (err) { if (err){ diff --git a/locales/de.js b/locales/de.js index 05b2605..4a632d6 100644 --- a/locales/de.js +++ b/locales/de.js @@ -46,7 +46,7 @@ "specify": "Bitte spezifiziere", "confirm": "Bitte bestätige", "signup_google": "Mit Google anmelden", - "error_unknown_email": "Unbekannte Kombination von Email und Passwort. Oder versuche dich mit Google anzumelden.", + "error_unknown_email": "Unbekannte Kombination von Email und Passwort.", "error_password_confirmation": "Die beiden Passwörter stimmen nicht überein.", "error_domain_blocked": "Diese Domain ist gesperrt.", "error_user_email_already_used": "Diese Email-Adresse ist bereits registriert.", diff --git a/locales/en.js b/locales/en.js index be30cf8..df5e158 100644 --- a/locales/en.js +++ b/locales/en.js @@ -44,8 +44,7 @@ "sure": "Are you sure?", "specify": "Please Specify", "confirm": "Please Confirm", - "signup_google": "Sign In with Google", - "error_unknown_email": "This email/password combination is unknown. Try login with Google.", + "error_unknown_email": "This email/password combination is unknown.", "error_password_confirmation": "The entered passwords don't match.", "error_domain_blocked": "Your domain is blocked.", "error_user_email_already_used": "This email address is already in use.", @@ -322,4 +321,4 @@ "mute_present": "Unfollow", "follow_present_help": "If someone else is presenting this Space, the other members automatically follow the presentation. Switch following on or off with this button.", "export": "export" -} \ No newline at end of file +} diff --git a/locales/fr.js b/locales/fr.js index 99d5faf..c738b6b 100644 --- a/locales/fr.js +++ b/locales/fr.js @@ -46,7 +46,7 @@ "specify": "Veuillez préciser:", "confirm": "Veuillez confirmer", "signup_google": "S'inscrire avec Google", - "error_unknown_email": "Combinaison inconnue de l'email et mot de passe. Ou essayer de signer avec Google.", + "error_unknown_email": "Combinaison inconnue de l'email et mot de passe.", "error_password_confirmation": "Les deux mots de passe ne correspondent pas.", "error_domain_blocked": "Ce domaine a été désactivé.", "error_user_email_already_used": "Cette adresse email est déjà enregistré.", @@ -315,4 +315,4 @@ "follow_present": "Suivre", "mute_present": "Pas suivre", "follow_present_help": "follow_present_help" -} \ No newline at end of file +} diff --git a/models/db.js b/models/db.js index 70e8f19..4874647 100644 --- a/models/db.js +++ b/models/db.js @@ -320,26 +320,26 @@ module.exports = { }, unpackArtifact: (a) => { - if (a.tags) { + if (a.tags && (typeof a.tags)=="string") { a.tags = JSON.parse(a.tags); } - if (a.control_points) { + if (a.control_points && (typeof a.control_points)=="string") { a.control_points = JSON.parse(a.control_points); } - if (a.payload_alternatives) { + if (a.payload_alternatives && (typeof a.payload_alternatives)=="string") { a.payload_alternatives = JSON.parse(a.payload_alternatives); } return a; }, packArtifact: (a) => { - if (a.tags) { + if (a.tags && (typeof a.tags)!="string") { a.tags = JSON.stringify(a.tags); } - if (a.control_points) { + if (a.control_points && (typeof a.control_points)!="string") { a.control_points = JSON.stringify(a.control_points); } - if (a.payload_alternatives) { + if (a.payload_alternatives && (typeof a.payload_alternatives)!="string") { a.payload_alternatives = JSON.stringify(a.payload_alternatives); } return a; diff --git a/public/javascripts/spacedeck_board_artifacts.js b/public/javascripts/spacedeck_board_artifacts.js index 2915f99..4ed0277 100644 --- a/public/javascripts/spacedeck_board_artifacts.js +++ b/public/javascripts/spacedeck_board_artifacts.js @@ -41,7 +41,7 @@ var SpacedeckBoardArtifacts = { if ("medium_for_object" in this) { var medium = this.medium_for_object[a._id]; if (medium && a._id != this.editing_artifact_id) { - medium.value(a.description); + medium.value(a.description.toString()); } } }, @@ -88,10 +88,11 @@ var SpacedeckBoardArtifacts = { }, artifact_is_text_blank: function(a) { - if(a.description){ - var filtered = a.description.replace(/<[^>]+>/g,"").replace(/\s/g,""); + if (a.description) { + desc = a.description.toString(); + var filtered = desc.replace(/<[^>]+>/g,"").replace(/\s/g,""); return (filtered.length<1); - }else{ + } else { return false; } }, diff --git a/routes/api/sessions.js b/routes/api/sessions.js index 8c2fdba..19de250 100644 --- a/routes/api/sessions.js +++ b/routes/api/sessions.js @@ -26,9 +26,10 @@ router.post('/', function(req, res) { //res.status(400).json({"error":"session.users"}); }) .then(user => { - console.log("!!! user: ",user.password_hash); - - if (bcrypt.compareSync(password, user.password_hash)) { + if (!user) { + res.sendStatus(404); + } + else if (bcrypt.compareSync(password, user.password_hash)) { crypto.randomBytes(48, function(ex, buf) { var token = buf.toString('hex'); console.log("!!! token: ",token); diff --git a/routes/api/space_artifacts.js b/routes/api/space_artifacts.js index c11b8ce..876d2e5 100644 --- a/routes/api/space_artifacts.js +++ b/routes/api/space_artifacts.js @@ -53,15 +53,8 @@ router.get('/', (req, res) => { space_id: req.space._id }}).then(artifacts => { async.map(artifacts, (a, cb) => { - //a = a.toObject(); TODO + db.unpackArtifact(a); - if (a.control_points) { - a.control_points = JSON.parse(a.control_points); - } - if (a.payload_alternatives) { - a.payload_alternatives = JSON.parse(a.payload_alternatives); - } - if (a.user_id) { // FIXME JOIN /*User.findOne({where: { @@ -131,7 +124,8 @@ router.post('/:artifact_id/payload', function(req, res, next) { var stream = req.pipe(writeStream); var progress_callback = function(progress_msg) { - a.description = progress_msg; + a.description = progress_msg.toString(); + db.packArtifact(a); a.save(); redis.sendMessage("update", a, a.toJSON(), req.channelId); };