WIP first partially working version without mongodb, using sqlite/sequelize
This commit is contained in:
@@ -4,11 +4,15 @@ const exec = require('child_process');
|
||||
const gm = require('gm');
|
||||
const async = require('async');
|
||||
const fs = require('fs');
|
||||
const Models = require('../models/schema');
|
||||
const Models = require('../models/db');
|
||||
const uploader = require('../helpers/uploader');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
|
||||
const db = require('../models/db');
|
||||
const Sequelize = require('sequelize');
|
||||
const Op = Sequelize.Op;
|
||||
|
||||
const fileExtensionMap = {
|
||||
".amr" : "audio/AMR",
|
||||
".ogg" : "audio/ogg",
|
||||
@@ -301,25 +305,20 @@ var resizeAndUploadImage = function(a, mime, size, fileName, fileNameOrg, imageF
|
||||
a.payload_uri = results.original;
|
||||
|
||||
var factor = 320/size.width;
|
||||
var newBoardSpecs = a.board;
|
||||
newBoardSpecs.w = Math.round(size.width*factor);
|
||||
newBoardSpecs.h = Math.round(size.height*factor);
|
||||
a.board = newBoardSpecs;
|
||||
a.w = Math.round(size.width*factor);
|
||||
a.h = Math.round(size.height*factor);
|
||||
|
||||
a.updated_at = new Date();
|
||||
a.save(function(err) {
|
||||
if(err) payloadCallback(err, null);
|
||||
else {
|
||||
fs.unlink(originalFilePath, function (err) {
|
||||
if (err){
|
||||
console.error(err);
|
||||
payloadCallback(err, null);
|
||||
} else {
|
||||
console.log('successfully deleted ' + originalFilePath);
|
||||
payloadCallback(null, a);
|
||||
}
|
||||
});
|
||||
}
|
||||
a.save().then(function() {
|
||||
fs.unlink(originalFilePath, function (err) {
|
||||
if (err){
|
||||
console.error(err);
|
||||
payloadCallback(err, null);
|
||||
} else {
|
||||
console.log('successfully deleted ' + originalFilePath);
|
||||
payloadCallback(null, a);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -371,25 +370,20 @@ module.exports = {
|
||||
a.payload_uri = url;
|
||||
|
||||
var factor = 320/size.width;
|
||||
var newBoardSpecs = a.board;
|
||||
newBoardSpecs.w = Math.round(size.width*factor);
|
||||
newBoardSpecs.h = Math.round(size.height*factor);
|
||||
a.board = newBoardSpecs;
|
||||
a.w = Math.round(size.width*factor);
|
||||
a.h = Math.round(size.height*factor);
|
||||
|
||||
a.updated_at = new Date();
|
||||
a.save(function(err){
|
||||
if(err) payloadCallback(err, null);
|
||||
else {
|
||||
fs.unlink(localFilePath, function (err) {
|
||||
if (err){
|
||||
console.error(err);
|
||||
payloadCallback(err, null);
|
||||
} else {
|
||||
console.log('successfully deleted ' + localFilePath);
|
||||
payloadCallback(null, a);
|
||||
}
|
||||
});
|
||||
}
|
||||
a.save().then(function() {
|
||||
fs.unlink(localFilePath, function (err) {
|
||||
if (err){
|
||||
console.error(err);
|
||||
payloadCallback(err, null);
|
||||
} else {
|
||||
console.log('successfully deleted ' + localFilePath);
|
||||
payloadCallback(null, a);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -483,6 +477,8 @@ module.exports = {
|
||||
];
|
||||
}
|
||||
|
||||
db.packArtifact(a);
|
||||
|
||||
a.updated_at = new Date();
|
||||
a.save(function(err) {
|
||||
if (err) payloadCallback(err, null);
|
||||
@@ -564,19 +560,19 @@ module.exports = {
|
||||
];
|
||||
|
||||
a.updated_at = new Date();
|
||||
a.save(function(err){
|
||||
if(err) payloadCallback(err, null);
|
||||
else {
|
||||
fs.unlink(localFilePath, function (err) {
|
||||
if (err){
|
||||
console.error(err);
|
||||
payloadCallback(err, null);
|
||||
} else {
|
||||
console.log('successfully deleted ' + localFilePath);
|
||||
payloadCallback(null, a);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
db.packArtifact(a);
|
||||
|
||||
a.save().then(function(){
|
||||
fs.unlink(localFilePath, function (err) {
|
||||
if (err){
|
||||
console.error(err);
|
||||
payloadCallback(err, null);
|
||||
} else {
|
||||
console.log('successfully deleted ' + localFilePath);
|
||||
payloadCallback(null, a);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -594,13 +590,10 @@ module.exports = {
|
||||
a.payload_uri = url;
|
||||
|
||||
a.updated_at = new Date();
|
||||
a.save(function(err) {
|
||||
if(err) payloadCallback(err, null);
|
||||
else {
|
||||
fs.unlink(localFilePath, function (err) {
|
||||
payloadCallback(null, a);
|
||||
});
|
||||
}
|
||||
a.save().then(function() {
|
||||
fs.unlink(localFilePath, function (err) {
|
||||
payloadCallback(null, a);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ const config = require('config')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
require('../models/schema')
|
||||
require('../models/db')
|
||||
|
||||
module.exports = {
|
||||
importZIP: function(user, zipPath) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
require('../models/schema');
|
||||
require('../models/db');
|
||||
var config = require('config');
|
||||
var phantom = require('node-phantom-simple');
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
'use strict';
|
||||
require('../models/schema');
|
||||
|
||||
const db = require('../models/db');
|
||||
const Sequelize = require('sequelize');
|
||||
const Op = Sequelize.Op;
|
||||
|
||||
const config = require('config');
|
||||
|
||||
@@ -8,7 +11,6 @@ const WebSocketServer = require('ws').Server;
|
||||
const RedisConnection = require('ioredis');
|
||||
const async = require('async');
|
||||
const _ = require("underscore");
|
||||
const mongoose = require("mongoose");
|
||||
const crypto = require('crypto');
|
||||
|
||||
const redisMock = require("./redis.js");
|
||||
@@ -45,11 +47,11 @@ module.exports = {
|
||||
const editorAuth = msg.editor_auth;
|
||||
const spaceId = msg.space_id;
|
||||
|
||||
Space.findOne({"_id": spaceId}).populate('creator').exec((err, space) => {
|
||||
db.Space.findOne({where: {"_id": spaceId}}).then(space => {
|
||||
if (space) {
|
||||
const upgradeSocket = function() {
|
||||
if (token) {
|
||||
User.findBySessionToken(token, function(err, user) {
|
||||
db.findUserBySessionToken(token, function(err, user) {
|
||||
if (err) {
|
||||
console.error(err, user);
|
||||
} else {
|
||||
@@ -268,10 +270,10 @@ module.exports = {
|
||||
},
|
||||
|
||||
distributeUsers: function(spaceId) {
|
||||
if(!spaceId)
|
||||
if (!spaceId)
|
||||
return;
|
||||
|
||||
this.state.smembers("space_" + spaceId, function(err, list) {
|
||||
/*this.state.smembers("space_" + spaceId, function(err, list) {
|
||||
async.map(list, function(item, callback) {
|
||||
this.state.get(item, function(err, userId) {
|
||||
console.log(item, "->", userId);
|
||||
@@ -292,16 +294,14 @@ module.exports = {
|
||||
return {nickname: realNickname, email: null, avatar_thumbnail_uri: null };
|
||||
});
|
||||
|
||||
User.find({"_id" : { "$in" : validUserIds }}, { "nickname" : 1 , "email" : 1, "avatar_thumbnail_uri": 1 }, function(err, users) {
|
||||
if (err)
|
||||
console.error(err);
|
||||
else {
|
||||
db.User.findAll({where: {
|
||||
"_id" : { "$in" : validUserIds }}, attributes: ["nickname","email","avatar_thumbnail_uri"]})
|
||||
.then(users) {
|
||||
const allUsers = users.concat(anonymousUsers);
|
||||
const strUsers = JSON.stringify({users: allUsers, space_id: spaceId});
|
||||
this.state.publish("users", strUsers);
|
||||
}
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
}.bind(this));*/
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user