2 Commits

Author SHA1 Message Date
greenkeeper[bot]
f7df0b7f43 docs(readme): add Greenkeeper badge
https://greenkeeper.io/
2017-04-07 07:55:54 +00:00
greenkeeper[bot]
d11eab4038 chore(package): update dependencies
https://greenkeeper.io/
2017-04-07 07:55:51 +00:00
77 changed files with 19258 additions and 18896 deletions

View File

@@ -1,14 +0,0 @@
.DS_Store
.git
logs
*.log
scripts
pids
*.pid
*.seed
lib-cov
coverage
.grunt
.lock-wscript
build/Release
node_modules

3
.gitignore vendored
View File

@@ -1,6 +1,5 @@
node_modules
public/stylesheets/*
javascripts/maps
javascripts/spacedeck.js
*.swp
*~

View File

@@ -1,29 +0,0 @@
FROM spacedeck/docker-baseimage:latest
ENV NODE_ENV production
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
RUN npm install
RUN npm install gulp-rev-replace gulp-clean gulp-fingerprint gulp-rev gulp-rev-all gulp-rev-replace
RUN npm install -g --save-dev gulp
COPY app.js Dockerfile Gulpfile.js LICENSE /usr/src/app/
COPY config /usr/src/app/config
COPY helpers /usr/src/app/helpers
COPY locales /usr/src/app/locales
COPY middlewares /usr/src/app/middlewares
COPY models /usr/src/app/models
COPY public /usr/src/app/public
COPY routes /usr/src/app/routes
COPY styles /usr/src/app/styles
COPY views /usr/src/app/views
RUN gulp all
RUN npm cache clean
CMD [ "node", "app.js" ]
EXPOSE 9666

View File

@@ -1,6 +1,43 @@
var gulp = require('gulp');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var server = require('gulp-express');
var nodemon = require('gulp-nodemon');
var revReplace = require("gulp-rev-replace");
var clean = require('gulp-clean');
var child_process = require('child_process');
var path = require('path');
var uglify = require('gulp-uglify');
var fingerprint = require('gulp-fingerprint');
var rev = require('gulp-rev');
var RevAll = require('gulp-rev-all');
gulp.task('rev', () => {
var revAll = new RevAll();
return gulp.src(['public/**'])
.pipe(gulp.dest('build/assets'))
.pipe(revAll.revision())
.pipe(gulp.dest('build/assets'))
.pipe(revAll.manifestFile())
.pipe(gulp.dest('build/assets'));
});
gulp.task("all", ["styles", "uglify", "rev", "copylocales"], function(){
var manifest = gulp.src("./build/assets/rev-manifest.json");
return gulp.src("./views/**/*")
.pipe(revReplace({manifest: manifest}))
.pipe(gulp.dest("./build/views"));
});
gulp.task('copylocales', function(){
return gulp.src('./locales/*.js').pipe(gulp.dest('./build/locales'));
});
gulp.task('clean', function () {
return gulp.src('./build').pipe(clean());
});
gulp.task('styles', function() {
gulp.src('styles/**/*.scss')
@@ -11,3 +48,15 @@ gulp.task('styles', function() {
.pipe(concat('style.css'));
});
gulp.task('uglify', () => {
child_process.exec('sed -n \'s/.*script minify src="\\(.*\\)".*/.\\/public\\/\\1/p\' views/spacedeck.html',
function (error, stdout, stderr) {
var scripts = stdout.split('\n').map(function(p){return path.normalize(p)}).filter(function(p){return p!='.'});
console.log("scripts: ",scripts);
gulp.src(scripts)
.pipe(uglify({output:{beautify:true}}))
.pipe(concat('spacedeck.js'))
.pipe(gulp.dest('public/javascripts'));
});
});

View File

@@ -1,18 +1,18 @@
# Spacedeck Open
This is the free and open source version of Spacedeck, a web based, real time, collaborative whiteboard application with rich media support. Spacedeck was developed in 6 major releases during Autumn 2011 until the end of 2016 and was originally a commercial SaaS. The developers were Lukas F. Hartmann (mntmn) and Martin GĂĽther (magegu).
[![Greenkeeper badge](https://badges.greenkeeper.io/spacedeck/spacedeck-open.svg)](https://greenkeeper.io/)
The spacedeck.com online service was shut down on May 1st 2018. We decided to open-source Spacedeck to allow educational and other organizations who currently rely on Spacedeck to migrate to a self-hosted or local version.
This is the free and open source version of Spacedeck, a web based, real time, collaborative whiteboard application with rich media support. Spacedeck was developed in 6 major releases during Autumn 2011 until the end of 2016 and was originally a commercial SaaS. The developers were Lukas F. Hartmann (mntmn) and Martin GĂĽther (magegu). All icons and large parts of the CSS were designed by Thomas Helbig (dergraph).
As we plan to retire the subscription based service at spacedeck.com in late 2017, we decided to open-source Spacedeck to allow educational and other organizations who currently rely on Spacedeck to migrate to a self-hosted version.
Data migration features will be added soon.
We appreciate filed issues, pull requests and general discussion.
**Windows users:** Try the one-click release at https://github.com/spacedeck/spacedeck-open/releases/tag/v0.9
Desktop releases for Linux and Mac will be published here soon. In the meantime, you have to install Node.JS to run Spacedeck.
# Features
- Create virtual whiteboards called *Spaces* with virtually unlimited size
- Create virtual whiteboards called "Spaces" with virtually unlimited size
- Drag & drop images, videos and audio from your computer or the web
- Write and format text with full control over fonts, colors and style
- Draw, annotate and highlight with included graphical shapes
@@ -21,70 +21,40 @@ Desktop releases for Linux and Mac will be published here soon. In the meantime,
- Share Spaces on the web or via email
- Export your work as printable PDF or ZIP
# Data Import from Spacedeck.com
Spacedeck Open has a data import feature that you can use to migrate your ZIP export from Spacedeck.com.
1. Just copy your downloaded ZIP file into the spacedeck root folder. Don't extract it.
2. Start your local Spacedeck.
3. Navigate to *Account / Profile* (person icon in the top right corner).
4. Click the *Import* button next to the ZIP file name. It is on the bottom of the page.
5. Wait until console output has finished and you're done.
# Requirements, Installation
Spacedeck requires:
Spacedeck uses the following major building blocks:
- Node.js 9.x: Web Server / API. Download: https://nodejs.org
- Node.js 4.x (Backend / API)
- MongoDB 3.x (Datastore)
- Redis 3.x (Datastore for realtime channels)
- Vue.js (Frontend)
To run Spacedeck, you only need Node.JS 9.x.
It also has some binary dependencies for media conversion and PDF export:
To install all node dependencies, run (do this once):
- imagemagick
Currently, media files are stored in Amazon S3, so you need an Amazon AWS account and have the ```AWS_ACCESS_KEY_ID``` and ```AWS_SECRET_ACCESS_KEY``` environment variables defined. For sending emails, Amazon SES is required.
To install Spacedeck, you need node.js 4.x and a running MongoDB instance. Then, to install all node dependencies, run
npm install
# Configuration
See [config/default.json](config/default.json)
# Run (web server)
node spacedeck.js
Then open http://localhost:9666 in a web browser.
# Run (desktop app with integrated web server)
electron .
# Optional Dependencies
For advanced media conversion:
- ffmpeg and ffprobe for video/audio conversion. Download: https://www.ffmpeg.org/download.html
- audiowaveform for audio waveform rendering. Download: https://github.com/bbcrd/audiowaveform
- ghostscript for PDF import. Download: https://www.ghostscript.com/download/gsdnld.html
# Data Storage
By default, media files are uploaded to the ```storage``` folder.
The database is stored in ```database.sqlite``` by default.
# Hacking
To rebuild the frontend CSS styles:
To rebuild the frontend CSS styles (you need to do this at least once):
gulp styles
# Run
export NODE_ENV=development
npm start
# License
The Spacedeck logo and brand assets are registered trademarks of Spacedeck GmbH. All rights reserved.
Spacedeck Open source code is released under the GNU Affero General Public License Version 3 (GNU AGPLv3).
Spacedeck Open is released under the GNU Affero General Public License Version 3 (GNU AGPLv3).
Spacedeck Open - Web-based Collaborative Whiteboard For Rich Media
Copyright (C) 2011-2018 Lukas F. Hartmann, Martin GĂĽther
Icons and original CSS design copyright by Thomas Helbig
Copyright (C) 2011-2017 Lukas F. Hartmann, Martin GĂĽther, Thomas Helbig
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as

192
app.js
View File

@@ -1,33 +1,173 @@
const spacedeck = require('./spacedeck')
"use strict";
const electron = require('electron')
const electronApp = electron.app
const BrowserWindow = electron.BrowserWindow
let mainWindow
require('./models/schema');
require("log-timestamp");
function createWindow () {
mainWindow = new BrowserWindow({width: 1200, height: 700})
mainWindow.loadURL("http://localhost:9666")
mainWindow.on('closed', function () {
mainWindow = null
})
const config = require('config');
const redis = require('./helpers/redis');
const websockets = require('./helpers/websockets');
const http = require('http');
const path = require('path');
const _ = require('underscore');
const favicon = require('serve-favicon');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const swig = require('swig');
const i18n = require('i18n-2');
const helmet = require('helmet');
const express = require('express');
const app = express();
const isProduction = app.get('env') === 'production';
console.log("Booting Spacedeck Open… (environment: " + app.get('env') + ")");
app.use(logger(isProduction ? 'combined' : 'dev'));
i18n.expressBind(app, {
locales: ["en", "de", "fr"],
defaultLocale: "en",
cookieName: "spacedeck_locale",
devMode: (app.get('env') == 'development')
});
swig.setDefaults({
varControls: ["[[", "]]"] // otherwise it's not compatible with vue.js
});
swig.setFilter('cdn', function(input, idx) {
return input;
});
app.engine('html', swig.renderFile);
app.set('view engine', 'html');
if (app.get('env') != 'development') {
app.set('views', path.join(__dirname, 'build', 'views'));
app.use(favicon(path.join(__dirname, 'build', 'assets', 'images', 'favicon.png')));
app.use(express.static(path.join(__dirname, 'build', 'assets')));
} else {
app.set('views', path.join(__dirname, 'views'));
app.use(favicon(path.join(__dirname, 'public', 'images', 'favicon.png')));
app.use(express.static(path.join(__dirname, 'public')));
}
electronApp.on('ready', createWindow)
app.use(bodyParser.json({
limit: '50mb'
}));
// Quit when all windows are closed.
electronApp.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
electronApp.quit()
}
})
app.use(bodyParser.urlencoded({
extended: false,
limit: '50mb'
}));
electronApp.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow()
app.use(cookieParser());
app.use(helmet.noCache())
app.use(helmet.frameguard())
app.use(helmet.xssFilter())
app.use(helmet.hsts({
maxAge: 7776000000,
includeSubdomains: true
}))
app.disable('x-powered-by');
app.use(helmet.noSniff())
// CUSTOM MIDDLEWARES
app.use(require("./middlewares/templates"));
app.use(require("./middlewares/error_helpers"));
app.use(require("./middlewares/setuser"));
app.use(require("./middlewares/subdomain"));
app.use(require("./middlewares/cors"));
app.use(require("./middlewares/i18n"));
app.use("/api", require("./middlewares/api_helpers"));
app.use('/api/spaces/:id', require("./middlewares/space_helpers"));
app.use('/api/spaces/:id/artifacts/:artifact_id', require("./middlewares/artifact_helpers"));
app.use('/api/teams', require("./middlewares/team_helpers"));
// REAL ROUTES
app.use('/api/users', require('./routes/api/users'));
app.use('/api/memberships', require('./routes/api/memberships'));
const spaceRouter = require('./routes/api/spaces');
app.use('/api/spaces', spaceRouter);
spaceRouter.use('/:id/artifacts', require('./routes/api/space_artifacts'));
spaceRouter.use('/:id/memberships', require('./routes/api/space_memberships'));
spaceRouter.use('/:id/messages', require('./routes/api/space_messages'));
spaceRouter.use('/:id/digest', require('./routes/api/space_digest'));
spaceRouter.use('/:id', require('./routes/api/space_exports'));
app.use('/api/sessions', require('./routes/api/sessions'));
app.use('/api/teams', require('./routes/api/teams'));
app.use('/api/webgrabber', require('./routes/api/webgrabber'));
app.use('/', require('./routes/root'));
// catch 404 and forward to error handler
app.use(require('./middlewares/404'));
if (app.get('env') == 'development') {
app.set('view cache', false);
swig.setDefaults({cache: false});
} else {
app.use(require('./middlewares/500'));
}
module.exports = app;
// CONNECT TO DATABASE
const mongoHost = process.env.MONGO_PORT_27017_TCP_ADDR || 'localhost';
mongoose.connect('mongodb://' + mongoHost + '/spacedeck');
// START WEBSERVER
const port = 9000;
const server = http.Server(app).listen(port, () => {
if ("send" in process) {
process.send('online');
}
})
}).on('listening', () => {
const host = server.address().address;
const port = server.address().port;
console.log('Spacedeck Open listening at http://%s:%s', host, port);
}).on('error', (error) => {
if (error.syscall !== 'listen') {
throw error;
}
const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port;
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
});
//WEBSOCKETS & WORKER
websockets.startWebsockets(server);
redis.connectRedis();
process.on('message', (message) => {
console.log("Process message:", message);
if (message === 'shutdown') {
console.log("Exiting spacedeck.");
process.exit(0);
}
});

View File

@@ -1,20 +1,7 @@
{
//"endpoint": "http://localhost:9000",
"endpoint": "http://localhost:9666",
"storage_region": "eu-central-1",
//"storage_bucket": "sdeck-development",
//"storage_cdn": "http://localhost:9123/sdeck-development",
//"storage_endpoint": "http://storage:9000",
"storage_bucket": "my_spacedeck_bucket",
"storage_cdn": "/storage",
"storage_local_path": "./storage",
"redis_mock": true,
"mongodb_host": "localhost",
"redis_host": "localhost",
"endpoint": "http://localhost:9000",
"storage_bucket": "my_spacedeck_s3_bucket",
"storage_cdn": "xyz.cloudfront.net",
"google_access" : "",
"google_secret" : "",
"admin_pass": "very_secret_admin_password",

View File

@@ -1,17 +0,0 @@
# Windows Electron Build
sqlite3 needs to be manually built for the iojs version that electron ships. The following code assumes electron v1.8.4.
````
npm -g install windows-build-tools
cd node_modules\sqlite3
node-gyp configure --module_name=node_sqlite3 --module_path=../lib/binding/electron-v1.8-win32-x64
node-gyp rebuild --target=1.8.4 --target_platform=win32 --dist-url=https://atom.io/download/atom-shell --module_name=node_sqlite3 --module_path=../lib/binding/electron-v1.8-win32-x64 --msvs_version=2015
cd ..\..
````

View File

@@ -4,18 +4,51 @@ const exec = require('child_process');
const gm = require('gm');
const async = require('async');
const fs = require('fs');
const Models = require('../models/db');
const Models = require('../models/schema');
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 mime = require('mime-types');
const fileType = require('file-type');
const readChunk = require('read-chunk');
const fileExtensionMap = {
".amr" : "audio/AMR",
".ogg" : "audio/ogg",
".aac" : "audio/aac",
".mp3" : "audio/mpeg",
".mpg" : "video/mpeg",
".3ga" : "audio/3ga",
".mp4" : "video/mp4",
".wav" : "audio/wav",
".mov" : "video/quicktime",
".doc" : "application/msword",
".dot" : "application/msword",
".docx" : "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
".dotx" : "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
".docm" : "application/vnd.ms-word.document.macroEnabled.12",
".dotm" : "application/vnd.ms-word.template.macroEnabled.12",
".xls" : "application/vnd.ms-excel",
".xlt" : "application/vnd.ms-excel",
".xla" : "application/vnd.ms-excel",
".xlsx" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
".xltx" : "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
".xlsm" : "application/vnd.ms-excel.sheet.macroEnabled.12",
".xltm" : "application/vnd.ms-excel.template.macroEnabled.12",
".xlam" : "application/vnd.ms-excel.addin.macroEnabled.12",
".xlsb" : "application/vnd.ms-excel.sheet.binary.macroEnabled.12",
".ppt" : "application/vnd.ms-powerpoint",
".pot" : "application/vnd.ms-powerpoint",
".pps" : "application/vnd.ms-powerpoint",
".ppa" : "application/vnd.ms-powerpoint",
".pptx" : "application/vnd.openxmlformats-officedocument.presentationml.presentation",
".potx" : "application/vnd.openxmlformats-officedocument.presentationml.template",
".ppsx" : "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
".ppam" : "application/vnd.ms-powerpoint.addin.macroEnabled.12",
".pptm" : "application/vnd.ms-powerpoint.presentation.macroEnabled.12",
".potm" : "application/vnd.ms-powerpoint.template.macroEnabled.12",
".ppsm" : "application/vnd.ms-powerpoint.slideshow.macroEnabled.12",
".key" : "application/x-iwork-keynote-sffkey",
".pages" : "application/x-iwork-pages-sffpages",
".numbers" : "application/x-iwork-numbers-sffnumbers",
".ttf" : "application/x-font-ttf"
};
const convertableImageTypes = [
"image/png",
@@ -35,9 +68,9 @@ const convertableVideoTypes = [
const convertableAudioTypes = [
"application/ogg",
"audio/amr",
"audio/AMR",
"audio/3ga",
"audio/wave",
"audio/wav",
"audio/3gpp",
"audio/x-wav",
"audio/aiff",
@@ -92,14 +125,14 @@ function createWaveform(fileName, localFilePath, callback){
});
}
function convertVideo(fileName, filePath, codec, callback, progressCallback) {
function convertVideo(fileName, filePath, codec, callback, progress_callback) {
var ext = path.extname(fileName);
var presetMime = mime.lookup(fileName);
var presetMime = fileExtensionMap[ext];
var newExt = codec == "mp4" ? "mp4" : "ogv";
var convertedPath = filePath + "." + newExt;
console.log("converting", filePath, "to", convertedPath);
console.log("converting", filePath, "to", convertedPath, "progress_cb:",progress_callback);
var convertArgs = (codec == "mp4") ? [
"-i", filePath,
@@ -134,8 +167,8 @@ function convertVideo(fileName, filePath, codec, callback, progressCallback) {
ff.stderr.on('data', function (data) {
console.log('[ffmpeg-video] stderr: ' + data);
if (progressCallback) {
progressCallback(data);
if (progress_callback) {
progress_callback(data);
}
});
@@ -152,7 +185,7 @@ function convertVideo(fileName, filePath, codec, callback, progressCallback) {
function convertAudio(fileName, filePath, codec, callback) {
var ext = path.extname(fileName);
var presetMime = mime.lookup(fileName);
var presetMime = fileExtensionMap[ext];
var newExt = codec == "mp3" ? "mp3" : "ogg";
var convertedPath = filePath + "." + newExt;
@@ -189,14 +222,22 @@ function createThumbnailForVideo(fileName, filePath, callback) {
function getMime(fileName, filePath, callback) {
var ext = path.extname(fileName);
var presetMime = mime.lookup(fileName);
var presetMime = fileExtensionMap[ext];
if (presetMime) {
callback(null, presetMime);
} else {
const buffer = readChunk.sync(filePath, 0, 4100);
var mimeType = fileType(buffer);
callback(null, mimeType);
exec.execFile("file", ["-b","--mime-type", filePath], {}, function(error, stdout, stderr) {
console.log("file stdout: ",stdout);
if (stderr === '' && error == null) {
//filter special chars from commandline
var mime = stdout.replace(/[^a-zA-Z0-9\/\-]/g,'');
callback(null, mime);
} else {
console.log("getMime file error: ", error);
callback(error, null);
}
});
}
}
@@ -204,12 +245,13 @@ function resizeAndUpload(a, size, max, fileName, localFilePath, callback) {
if (max>320 || size.width > max || size.height > max) {
var resizedFileName = max + "_"+fileName;
var s3Key = "s"+ a.space_id.toString() + "/a" + a._id.toString() + "/" + resizedFileName;
var localResizedFilePath = os.tmpdir()+"/"+resizedFileName;
var localResizedFilePath = "/tmp/"+resizedFileName;
gm(localFilePath).resize(max, max).autoOrient().write(localResizedFilePath, function (err) {
if(!err) {
uploader.uploadFile(s3Key, "image/jpeg", localResizedFilePath, function(err, url) {
if (err) callback(err);
else{
console.log(localResizedFilePath);
fs.unlink(localResizedFilePath, function (err) {
if (err) {
console.error(err);
@@ -230,7 +272,7 @@ function resizeAndUpload(a, size, max, fileName, localFilePath, callback) {
}
var resizeAndUploadImage = function(a, mimeType, size, fileName, fileNameOrg, imageFilePath, originalFilePath, payloadCallback) {
var resizeAndUploadImage = function(a, mime, size, fileName, fileNameOrg, imageFilePath, originalFilePath, payloadCallback) {
async.parallel({
small: function(callback){
resizeAndUpload(a, size, 320, fileName, imageFilePath, callback);
@@ -243,13 +285,13 @@ var resizeAndUploadImage = function(a, mimeType, size, fileName, fileNameOrg, im
},
original: function(callback){
var s3Key = "s"+ a.space_id.toString() + "/a" + a._id + "/" + fileNameOrg;
uploader.uploadFile(s3Key, mimeType, originalFilePath, function(err, url){
uploader.uploadFile(s3Key, mime, originalFilePath, function(err, url){
callback(null, url);
});
}
}, function(err, results) {
a.state = "idle";
a.mime = mimeType;
a.mime = mime;
var stats = fs.statSync(originalFilePath);
a.payload_size = stats["size"];
@@ -259,43 +301,46 @@ var resizeAndUploadImage = function(a, mimeType, size, fileName, fileNameOrg, im
a.payload_uri = results.original;
var factor = 320/size.width;
a.w = Math.round(size.width*factor);
a.h = Math.round(size.height*factor);
var newBoardSpecs = a.board;
newBoardSpecs.w = Math.round(size.width*factor);
newBoardSpecs.h = Math.round(size.height*factor);
a.board = newBoardSpecs;
a.updated_at = new Date();
db.packArtifact(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);
}
});
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);
}
});
}
});
});
};
module.exports = {
convert: function(a, fileName, localFilePath, payloadCallback, progressCallback) {
getMime(fileName, localFilePath, function(err, mimeType){
console.log("[convert] fn: "+fileName+" local: "+localFilePath+" mimeType:", mimeType);
convert: function(a, fileName, localFilePath, payloadCallback, progress_callback) {
getMime(fileName, localFilePath, function(err, mime){
console.log("[convert] fn: "+fileName+" local: "+localFilePath+" mime:", mime);
if (!err) {
if (convertableImageTypes.indexOf(mimeType) > -1) {
if (convertableImageTypes.indexOf(mime) > -1) {
gm(localFilePath).size(function (err, size) {
console.log("[convert] gm:", err, size);
if (!err) {
if(mimeType == "application/pdf") {
if(mime == "application/pdf") {
var firstImagePath = localFilePath + ".jpeg";
exec.execFile("gs", ["-sDEVICE=jpeg","-dNOPAUSE", "-dJPEGQ=80", "-dBATCH", "-dFirstPage=1", "-dLastPage=1", "-sOutputFile=" + firstImagePath, "-r90", "-f", localFilePath], {}, function(error, stdout, stderr) {
if(error === null) {
resizeAndUploadImage(a, mimeType, size, fileName + ".jpeg", fileName, firstImagePath, localFilePath, function(err, a) {
resizeAndUploadImage(a, mime, size, fileName + ".jpeg", fileName, firstImagePath, localFilePath, function(err, a) {
fs.unlink(firstImagePath, function (err) {
payloadCallback(err, a);
});
@@ -305,19 +350,19 @@ module.exports = {
}
});
} else if(mimeType == "image/gif") {
} else if(mime == "image/gif") {
//gifs are buggy after convertion, so we should not convert them
var s3Key = "s"+ a.space_id.toString() + "/a" + a._id.toString() + "/" + fileName;
uploader.uploadFile(s3Key, "image/gif", localFilePath, function(err, url) {
if (err) payloadCallback(err);
else {
if(err)callback(err);
else{
console.log(localFilePath);
var stats = fs.statSync(localFilePath);
a.state = "idle";
a.mime = mimeType;
a.mime = mime;
a.payload_size = stats["size"];
a.payload_thumbnail_web_uri = url;
@@ -326,39 +371,42 @@ module.exports = {
a.payload_uri = url;
var factor = 320/size.width;
a.w = Math.round(size.width*factor);
a.h = Math.round(size.height*factor);
var newBoardSpecs = a.board;
newBoardSpecs.w = Math.round(size.width*factor);
newBoardSpecs.h = Math.round(size.height*factor);
a.board = newBoardSpecs;
a.updated_at = new Date();
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);
}
});
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);
}
});
}
});
}
});
} else {
resizeAndUploadImage(a, mimeType, size, fileName, fileName, localFilePath, localFilePath, payloadCallback);
resizeAndUploadImage(a, mime, size, fileName, fileName, localFilePath, localFilePath, payloadCallback);
}
} else payloadCallback(err);
});
} else if (convertableVideoTypes.indexOf(mimeType) > -1) {
} else if (convertableVideoTypes.indexOf(mime) > -1) {
async.parallel({
thumbnail: function(callback) {
createThumbnailForVideo(fileName, localFilePath, function(err, created){
console.log("thumbnail created: ", err, created);
if (err) callback(err);
else {
if(err) callback(err);
else{
var keyName = "s" + a.space_id.toString() + "/a" + a._id.toString() + "/" + fileName + ".jpg" ;
uploader.uploadFile(keyName, "image/jpeg", created, function(err, url){
if (err) callback(err);
@@ -368,7 +416,7 @@ module.exports = {
});
},
ogg: function(callback) {
if (mimeType == "video/ogg") {
if (mime == "video/ogg") {
callback(null, "org");
} else {
convertVideo(fileName, localFilePath, "ogg", function(err, file) {
@@ -380,11 +428,11 @@ module.exports = {
else callback(null, url);
});
}
}, progressCallback);
}, progress_callback);
}
},
mp4: function(callback) {
if (mimeType == "video/mp4") {
if (mime == "video/mp4") {
callback(null, "org");
} else {
convertVideo(fileName, localFilePath, "mp4", function(err, file) {
@@ -396,21 +444,21 @@ module.exports = {
else callback(null, url);
});
}
}, progressCallback);
}, progress_callback);
}
},
original: function(callback){
uploader.uploadFile(fileName, mimeType, localFilePath, function(err, url){
uploader.uploadFile(fileName, mime, localFilePath, function(err, url){
callback(null, url);
});
}
}, function(err, results) {
}, function(err, results){
console.log(err, results);
if (err) payloadCallback(err, a);
else {
a.state = "idle";
a.mime = mimeType;
a.mime = mime;
var stats = fs.statSync(localFilePath);
a.payload_size = stats["size"];
@@ -419,7 +467,7 @@ module.exports = {
a.payload_thumbnail_big_uri = results.thumbnail;
a.payload_uri = results.original;
if (mimeType == "video/mp4") {
if (mime == "video/mp4") {
a.payload_alternatives = [
{
mime: "video/ogg",
@@ -435,24 +483,25 @@ module.exports = {
];
}
db.packArtifact(a);
a.updated_at = new Date();
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);
}
});
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);
}
});
}
});
}
});
} else if (convertableAudioTypes.indexOf(mimeType) > -1) {
} else if (convertableAudioTypes.indexOf(mime) > -1) {
async.parallel({
ogg: function(callback) {
@@ -490,7 +539,7 @@ module.exports = {
},
original: function(callback) {
var keyName = "s" + a.space_id.toString() + "/a" + a._id.toString() + "/" + fileName;
uploader.uploadFile(keyName, mimeType, localFilePath, function(err, url){
uploader.uploadFile(keyName, mime, localFilePath, function(err, url){
callback(null, url);
});
}
@@ -501,7 +550,7 @@ module.exports = {
else {
a.state = "idle";
a.mime = mimeType;
a.mime = mime;
var stats = fs.statSync(localFilePath);
a.payload_size = stats["size"];
@@ -515,40 +564,43 @@ module.exports = {
];
a.updated_at = new Date();
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);
}
});
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);
}
});
}
});
}
});
} else {
console.log("mimeType not matched for conversion, storing file");
console.log("mime not matched for conversion, storing file");
var keyName = "s" + a.space_id.toString() + "/a" + a._id.toString() + "/" + fileName;
uploader.uploadFile(keyName, mimeType, localFilePath, function(err, url) {
uploader.uploadFile(keyName, mime, localFilePath, function(err, url) {
a.state = "idle";
a.mime = mimeType;
a.mime = mime;
var stats = fs.statSync(localFilePath);
a.payload_size = stats["size"];
a.payload_uri = url;
a.updated_at = new Date();
a.save().then(function() {
fs.unlink(localFilePath, function (err) {
payloadCallback(null, a);
});
a.save(function(err) {
if(err) payloadCallback(err, null);
else {
fs.unlink(localFilePath, function (err) {
payloadCallback(null, a);
});
}
});
});
}

View File

@@ -1,128 +0,0 @@
'use strict';
const extract = require('extract-zip')
const config = require('config')
const fs = require('fs')
const path = require('path')
const db = require('../models/db')
const Sequelize = require('sequelize')
const Op = Sequelize.Op
const uuidv4 = require('uuid/v4')
require('../models/db')
module.exports = {
importZIP: function(user, zipPath) {
// 1. extract zip to local storage folder
// 2. read spaces.json from this folder
// 3. iterate through spaces and read all their artifact jsons
// 4. fixup storage paths
// 5. replace creator id by user._id
let relativeImportDir = 'import_'+user._id
let importDir = path.resolve(config.get('storage_local_path')+'/'+config.get('storage_bucket')+'/'+relativeImportDir)
if (!fs.existsSync(importDir)) {
fs.mkdirSync(importDir)
}
extract(zipPath, {dir: importDir}, function(err) {
if (err) {
console.log(err)
return
}
console.log('[import] extracted to',importDir)
let spacesJson = fs.readFileSync(importDir+'/spaces.json')
let spaces = JSON.parse(spacesJson)
var homeFolderId = null
console.log('[import] spaces:',spaces.length)
// pass 1: find homefolder
for (var i=0; i<spaces.length; i++) {
let space = spaces[i]
if (!space.parent_space_id) {
homeFolderId = space._id
break
}
}
console.log("[import] homeFolderId:",homeFolderId)
for (var i=0; i<spaces.length; i++) {
let space = spaces[i]
if (space.parent_space_id) {
let artifacts = JSON.parse(fs.readFileSync(importDir+'/'+space._id+'_artifacts.json'))
console.log('[import] space',space._id,'artifacts:',artifacts.length)
//let q = {where: {_id: space._id}}
space.creator_id = user._id
delete space.__v
// transplant homefolder
console.log("parent:",space.parent_space_id)
if (space.parent_space_id+"" == homeFolderId+"") {
space.parent_space_id = user.home_folder_id
}
// move nested attrs
console.log(space)
for (k in space.advanced) {
space[k] = space.advanced[k]
}
db.Space.create(space)
.error((err) => {
console.error("[import] space upsert err:",err)
})
for (var j=0; j<artifacts.length; j++) {
let a = artifacts[j]
let q = {_id: a._id}
a.user_id = user._id
delete a.__v
delete a.payload_thumbnail_big_uri
// move nested attrs
for (k in a.style) {
a[k] = a.style[k]
}
for (k in a.meta) {
a[k] = a.meta[k]
}
for (k in a.board) {
a[k] = a.board[k]
}
let prefix = "/storage/"+relativeImportDir+"/"+space._id+"_files/"
if (a.thumbnail_uri && a.thumbnail_uri[0]!='/') a.thumbnail_uri = prefix + a.thumbnail_uri
if (a.payload_uri && a.payload_uri[0]!='/') a.payload_uri = prefix + a.payload_uri
if (a.payload_thumbnail_web_uri && a.payload_thumbnail_web_uri[0]!='/') a.payload_thumbnail_web_uri = prefix + a.payload_thumbnail_web_uri
if (a.payload_thumbnail_medium_uri && a.payload_thumbnail_medium_uri[0]!='/') a.payload_thumbnail_medium_uri = prefix + a.payload_thumbnail_medium_uri
if (a.payload_alternatives) {
for (var k=0; k<a.payload_alternatives.length; k++) {
let alt = a.payload_alternatives[k]
if (alt.payload_uri && alt.payload_uri[0]!='/') alt.payload_uri = prefix + alt.payload_uri
if (alt.payload_thumbnail_web_uri && alt.payload_thumbnail_web_uri[0]!='/') alt.payload_thumbnail_web_uri = prefix + alt.payload_thumbnail_web_uri
if (alt.payload_thumbnail_medium_uri && alt.payload_thumbnail_medium_uri[0]!='/') alt.payload_thumbnail_medium_uri = prefix + alt.payload_thumbnail_medium_uri
}
}
db.packArtifact(a)
db.Artifact.create(a).error(function(err) {
console.error("[import] artifact upsert err:",err)
})
}
}
}
})
}
}

View File

@@ -1,7 +1,7 @@
'use strict';
var swig = require('swig');
//var AWS = require('aws-sdk');
var AWS = require('aws-sdk');
module.exports = {
sendMail: (to_email, subject, body, options) => {
@@ -29,9 +29,9 @@ module.exports = {
options: options
});
//if (process.env.NODE_ENV === 'development') {
if (process.env.NODE_ENV === 'development') {
console.log("Email: to " + to_email + " in production.\nreply_to: " + reply_to + "\nsubject: " + subject + "\nbody: \n" + htmlText + "\n\n plaintext:\n" + plaintext);
/*} else {
} else {
AWS.config.update({region: 'eu-west-1'});
var ses = new AWS.SES();
@@ -53,9 +53,9 @@ module.exports = {
}
}
}, function(err, data) {
if (err) console.error("Error sending email:", err);
if(err) console.log('Email not sent:', err);
else console.log("Email sent.");
});
}*/
}
}
};

View File

@@ -1,9 +1,8 @@
'use strict';
const db = require('../models/db');
const config = require('config');
const phantom = require('node-phantom-simple');
const os = require('os');
require('../models/schema');
var config = require('config');
var phantom = require('node-phantom-simple');
module.exports = {
// type = "pdf" or "png"
@@ -11,7 +10,7 @@ module.exports = {
var spaceId = space._id;
var space_url = config.get("endpoint")+"/api/spaces/"+spaceId+"/html";
var export_path = os.tmpdir()+"/"+spaceId+"."+type;
var export_path = "/tmp/"+spaceId+"."+type;
var timeout = 5000;
if (type=="pdf") timeout = 30000;
@@ -25,7 +24,7 @@ module.exports = {
var on_exit = function(exit_code) {
if (exit_code>0) {
console.error("phantom abnormal exit for url "+space_url);
console.log("phantom abnormal exit for url "+space_url);
if (!on_success_called && on_error) {
on_error();
}
@@ -33,36 +32,31 @@ module.exports = {
};
phantom.create({ path: require('phantomjs-prebuilt').path }, function (err, browser) {
if (err) {
console.error(err);
} else {
return browser.createPage(function (err, page) {
console.log("page created, opening ",space_url);
return browser.createPage(function (err, page) {
console.log("page created, opening ",space_url);
if (type=="pdf") {
var psz = {
width: space.width+"px",
height: space.height+"px"
};
page.set('paperSize', psz);
}
if (type=="pdf") {
var psz = {
width: space.advanced.width+"px",
height: space.advanced.height+"px"
};
page.set('paperSize', psz);
}
page.set('settings.resourceTimeout',timeout);
page.set('settings.javascriptEnabled',false);
page.set('settings.resourceTimeout',timeout);
page.set('settings.javascriptEnabled',false);
return page.open(space_url, function (err,status) {
page.render(export_path, function() {
on_success_called = true;
if (on_success) {
on_success(export_path);
}
page.close();
browser.exit();
});
return page.open(space_url, function (err,status) {
page.render(export_path, function() {
on_success_called = true;
if (on_success) {
on_success(export_path);
}
page.close();
browser.exit();
});
});
}
});
});
}, {
onExit: on_exit
});

View File

@@ -1,111 +1,14 @@
'use strict';
const config = require('config');
// this is a mock version of the Redis API,
// emulating Redis if it is not available locally
var notRedis = {
state: {},
topics: {},
publish: function(topic, msg, cb) {
if (!this.topics[topic]) {
this.topics[topic] = {
subscribers: []
};
}
var t=this.topics[topic];
for (var i=0; i<t.subscribers.length; i++) {
var s=t.subscribers[i];
if (s.handler) {
s.handler(topic, msg);
}
}
if (cb) cb(null);
},
subscribe: function(topics, cb) {
var handle = {
handler: null,
on: function(evt, cb) {
if (evt == "message") {
this.handler = cb;
}
}
};
for (var i=0; i<topics.length; i++) {
var topic = topics[i];
if (!this.topics[topic]) {
this.topics[topic] = {
subscribers: []
};
}
var t=this.topics[topic];
t.subscribers.push(handle);
}
cb(null, topics.length);
return handle;
},
get: function(key, cb) {
cb(null, this.state[key]);
return this.state[key];
},
set: function(key, val, cb) {
this.state[key] = val;
cb();
},
del: function(key, cb) {
delete this.state[key];
cb(null);
},
sadd: function(key, skey, cb) {
if (!this.state[key]) this.state[key] = {};
this.state[key][skey] = true;
cb(null);
},
srem: function(key, skey, cb) {
if (this.state[key]) {
delete this.state[key][skey];
}
cb(null);
},
smembers: function(key, cb) {
cb(null, Object.keys(this.state[key]));
},
incr: function(key, cb) {
if (!this.state[key]) this.state[key] = 0;
this.state[key]++;
cb(null, this.state[key]);
},
expire: function() {
},
}
const RedisConnection = require('ioredis');
const websockets = require('./websockets');
module.exports = {
connectRedis: function() {
if (config.get("redis_mock")) {
this.connection = notRedis;
} else {
const redisHost = process.env.REDIS_PORT_6379_TCP_ADDR || 'sync';
this.connection = new RedisConnection(6379, redisHost);
}
connectRedis(){
const redisHost = process.env.REDIS_PORT_6379_TCP_ADDR || 'localhost';
this.connection = new RedisConnection(6379, redisHost);
},
getConnection: function() {
this.connectRedis();
return this.connection;
},
sendMessage: function(action, model, attributes, channelId) {
sendMessage(action, model, attributes, channelId) {
const data = JSON.stringify({
channel_id: channelId,
action: action,
@@ -114,12 +17,12 @@ module.exports = {
});
this.connection.publish('updates', data);
},
logIp: function(ip, cb) {
logIp(ip, cb) {
this.connection.incr("ip_"+ ip, (err, socketCounter) => {
cb();
});
},
rateLimit: function(namespace, ip, cb) {
rateLimit(namespace, ip, cb) {
const key = "limit_"+ namespace + "_"+ ip;
const redis = this.connection;
@@ -144,7 +47,7 @@ module.exports = {
}
});
},
isOnlineInSpace: function(user, space, cb) {
isOnlineInSpace(user, space, cb) {
this.connection.smembers("space_" + space._id.toString(), function(err, list) {
if (err) cb(err);
else {
@@ -156,6 +59,3 @@ module.exports = {
});
}
};
return module.exports;

View File

@@ -1,41 +1,16 @@
'use strict';
var AWS = require('aws-sdk');
AWS.config.region = 'eu-central-1';
var fs = require('fs');
var config = require('config');
var s3 = null;
// use AWS S3 or local folder depending on config
if (config.get("storage_local_path")) {
var AWS = require('mock-aws-s3');
AWS.config.basePath = config.get("storage_local_path");
s3 = new AWS.S3();
} else {
var AWS = require('aws-sdk');
var storage_endpoint = config.get("storage_endpoint");
const ep = new AWS.Endpoint(storage_endpoint);
AWS.config.update(new AWS.Config({
accessKeyId: process.env.MINIO_ACCESS_KEY,
secretAccessKey: process.env.MINIO_SECRET_KEY,
region: config.get("storage_region"),
s3ForcePathStyle: true,
signatureVersion: 'v4'
}));
s3 = new AWS.S3({
endpoint: ep
});
}
s3.createBucket({
Bucket: config.get("storage_bucket"),
ACL: "public-read",
GrantRead: "*"
}, (err,res) => {
console.log("createBucket",err,res);
});
module.exports = {
removeFile: (path, callback) => {
const s3 = new AWS.S3({
region: 'eu-central-1'
});
const bucket = config.get("storage_bucket");
s3.deleteObject({
Bucket: bucket, Key: path
@@ -53,7 +28,7 @@ module.exports = {
callback({error:"missing path"}, null);
return;
}
console.log("[storage] uploading", localFilePath, " to ", fileName);
console.log("[s3] uploading", localFilePath, " to ", fileName);
const bucket = config.get("storage_bucket");
const fileStream = fs.createReadStream(localFilePath);
@@ -64,6 +39,11 @@ module.exports = {
}
});
fileStream.on('open', function () {
// FIXME
var s3 = new AWS.S3({
region: 'eu-central-1'
});
s3.putObject({
Bucket: bucket,
Key: fileName,
@@ -73,8 +53,8 @@ module.exports = {
if (err){
console.error(err);
callback(err);
} else {
const url = config.get("storage_cdn") + "/" + fileName;
}else {
const url = "https://"+ config.get("storage_cdn") + "/" + fileName;
console.log("[s3]" + localFilePath + " to " + url);
callback(null, url);
}

View File

@@ -1,30 +1,20 @@
'use strict';
const db = require('../models/db');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
const config = require('config');
require('../models/schema');
const WebSocketServer = require('ws').Server;
//const RedisConnection = require('ioredis');
const Redis = require('ioredis');
const async = require('async');
const _ = require("underscore");
const mongoose = require("mongoose");
const crypto = require('crypto');
const redisMock = require("./redis.js");
module.exports = {
startWebsockets: function(server) {
startWebsockets: function(server){
this.setupSubscription();
if (!this.current_websockets) {
if (config.get("redis_mock")) {
this.state = redisMock.getConnection();
} else {
this.state = new RedisConnection(6379, process.env.REDIS_PORT_6379_TCP_ADDR || config.get("redis_host"));
}
this.state = new Redis(6379, process.env.REDIS_PORT_6379_TCP_ADDR || 'localhost');
if(!this.current_websockets){
this.current_websockets = [];
}
@@ -47,11 +37,11 @@ module.exports = {
const editorAuth = msg.editor_auth;
const spaceId = msg.space_id;
db.Space.findOne({where: {"_id": spaceId}}).then(space => {
Space.findOne({"_id": spaceId}).populate('creator').exec((err, space) => {
if (space) {
const upgradeSocket = function() {
if (token) {
db.findUserBySessionToken(token, function(err, user) {
User.findBySessionToken(token, function(err, user) {
if (err) {
console.error(err, user);
} else {
@@ -127,17 +117,10 @@ module.exports = {
},
setupSubscription: function() {
if (config.get("redis_mock")) {
this.cursorSubscriber = redisMock.getConnection().subscribe(['cursors', 'users', 'updates'], function (err, count) {
console.log("[redis-mock] websockets subscribed to " + count + " topics." );
});
} else {
this.cursorSubscriber = new RedisConnection(6379, process.env.REDIS_PORT_6379_TCP_ADDR || config.get("redis_host"));
this.cursorSubscriber.subscribe(['cursors', 'users', 'updates'], function (err, count) {
console.log("[redis] websockets subscribed to " + count + " topics." );
});
}
this.cursorSubscriber = new Redis(6379, process.env.REDIS_PORT_6379_TCP_ADDR || 'localhost');
this.cursorSubscriber.subscribe(['cursors', 'users', 'updates'], function (err, count) {
console.log("[redis] websockets to " + count + " topics." );
});
this.cursorSubscriber.on('message', function (channel, rawMessage) {
const msg = JSON.parse(rawMessage);
const spaceId = msg.space_id;
@@ -223,7 +206,7 @@ module.exports = {
console.log("websocket not found to remove");
}
this.state.del(ws.id+"", function(err, res) {
this.state.del(ws.id, function(err, res) {
if (err) console.error(err, res);
else {
this.removeUserInSpace(ws.space_id, ws, (err) => {
@@ -238,8 +221,7 @@ module.exports = {
addUserInSpace: function(username, space, ws, cb) {
console.log("[websockets] user "+username+" in "+space.access_mode +" space " + space._id + " with socket " + ws.id);
this.state.set(ws.id+"", username+"", function(err, res) {
this.state.set(ws.id, username, function(err, res) {
if(err) console.error(err, res);
else {
this.state.sadd("space_" + space._id, ws.id, function(err, res) {
@@ -256,7 +238,7 @@ module.exports = {
}.bind(this));
},
removeUserInSpace: function(spaceId, ws, cb) {
this.state.srem("space_" + spaceId, ws.id+"", function(err, res) {
this.state.srem("space_" + spaceId, ws.id, function(err, res) {
if (err) cb(err);
else {
console.log("[websockets] socket "+ ws.id + " went offline in space " + spaceId);
@@ -270,10 +252,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);
@@ -294,14 +276,16 @@ module.exports = {
return {nickname: realNickname, email: null, avatar_thumbnail_uri: null };
});
db.User.findAll({where: {
"_id" : { "$in" : validUserIds }}, attributes: ["nickname","email","avatar_thumbnail_uri"]})
.then(users) {
User.find({"_id" : { "$in" : validUserIds }}, { "nickname" : 1 , "email" : 1, "avatar_thumbnail_uri": 1 }, function(err, users) {
if (err)
console.error(err);
else {
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));
}
};

View File

@@ -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.",
"error_unknown_email": "Unbekannte Kombination von Email und Passwort. Oder versuche dich mit Google anzumelden.",
"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.",

View File

@@ -44,7 +44,8 @@
"sure": "Are you sure?",
"specify": "Please Specify",
"confirm": "Please Confirm",
"error_unknown_email": "This email/password combination is unknown.",
"signup_google": "Sign In with Google",
"error_unknown_email": "This email/password combination is unknown. Try login with Google.",
"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.",
@@ -321,4 +322,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"
}
}

View File

@@ -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.",
"error_unknown_email": "Combinaison inconnue de l'email et mot de passe. Ou essayer de signer avec Google.",
"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"
}
}

View File

@@ -1,6 +1,6 @@
'use strict';
require('../models/db');
require('../models/schema');
var config = require('config');
module.exports = (req, res, next) => {
@@ -16,4 +16,4 @@ module.exports = (req, res, next) => {
} else {
res.status(404).send("Not Found.");
}
}
}

View File

@@ -1,11 +1,9 @@
'use strict';
require('../models/db');
require('../models/schema');
var config = require('config');
const redis = require('../helpers/redis');
// FIXME TODO object.toJSON()
var saveAction = (actionKey, object) => {
if (object.constructor.modelName == "Space")
return;
@@ -15,14 +13,14 @@ var saveAction = (actionKey, object) => {
space: object.space_id || object.space,
user: object.user_id || object.user,
editor_name: object.editor_name,
object: object
object: object.toJSON()
};
/*let action = new Action(attr);
let action = new Action(attr);
action.save(function(err) {
if (err)
console.error("saved create action err:", err);
});*/
});
};
module.exports = (req, res, next) => {
@@ -34,21 +32,21 @@ module.exports = (req, res, next) => {
res['distributeCreate'] = function(model, object) {
if (!object) return;
redis.sendMessage("create", model, object, req.channelId);
this.status(201).json(object);
redis.sendMessage("create", model, object.toJSON(), req.channelId);
this.status(201).json(object.toJSON());
saveAction("create", object);
};
res['distributeUpdate'] = function(model, object) {
if (!object) return;
redis.sendMessage("update", model, object, req.channelId);
this.status(200).json(object);
redis.sendMessage("update", model, object.toJSON(), req.channelId);
this.status(200).json(object.toJSON());
saveAction("update", object);
};
res['distributeDelete'] = function(model, object) {
if (!object) return;
redis.sendMessage("delete", model, object, req.channelId);
redis.sendMessage("delete", model, object.toJSON(), req.channelId);
this.sendStatus(204);
saveAction("delete", object);
};

View File

@@ -1,20 +1,22 @@
'use strict';
const db = require('../models/db');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
require('../models/schema');
var config = require('config');
module.exports = (req, res, next) => {
var artifactId = req.params.artifact_id;
db.Artifact.findOne({where: {
Artifact.findOne({
"_id": artifactId
}}).then(artifact => {
if (artifact) {
req['artifact'] = artifact;
next();
}, (err, artifact) => {
if (err) {
res.status(400).json(err);
} else {
res.sendStatus(404);
if (artifact) {
req['artifact'] = artifact;
next();
} else {
res.sendStatus(404);
}
}
});
};
};

View File

@@ -1,6 +1,6 @@
'use strict';
require('../models/db');
require('../models/schema');
const config = require('config');
const url = require('url');
@@ -26,20 +26,20 @@ module.exports = (req, res, next) => {
const parsedUrl = url.parse(origin, true, true);
// FIXME
if (parsedUrl.hostname == "cdn.spacedeck.com") {
if (parsedUrl.hostname == "cdn.spacedeck.com") {
res.header('Cache-Control', "max-age");
res.header('Expires', "30d");
res.removeHeader("Pragma");
respond(origin, req, res, next);
} else {
//Team.getTeamForHost(parsedUrl.hostname, (err, team, subdomain) => {
//if (team) {
Team.getTeamForHost(parsedUrl.hostname, (err, team, subdomain) => {
if (team) {
respond(origin, req, res, next);
//} else {
} else {
next();
//}
//});
}
});
}
} else {

View File

@@ -1,6 +1,6 @@
'use strict';
require('../models/db');
require('../models/schema');
var config = require('config');
module.exports = (req, res, next) => {
@@ -10,8 +10,8 @@ module.exports = (req, res, next) => {
req.i18n.setLocaleFromCookie();
}
if (req.user && req.user.prefs_language) {
req.i18n.setLocale(req.user.prefs_language);
if (req.user && req.user.preferences.language) {
req.i18n.setLocale(req.user.preferences.language);
}
next();
}
}

View File

@@ -1,47 +0,0 @@
'use strict';
const db = require('../models/db');
var config = require('config');
module.exports = (req, res, next) => {
const token = req.cookies["sdsession"];
if (token && token != "null" && token != null) {
db.Session.findOne({where: {token: token}})
.then(session => {
if (!session) {
// session not found
next();
}
else db.User.findOne({where: {_id: session.user_id}})
.then(user => {
if (!user) {
var domain = (process.env.NODE_ENV == "production") ? new URL(config.get('endpoint')).hostname : req.headers.hostname;
res.clearCookie('sdsession', { domain: domain });
if (req.accepts("text/html")) {
res.send("Please clear your cookies and try again.");
} else if (req.accepts('application/json')) {
res.status(403).json({
"error": "token_not_found"
});
} else {
res.send("Please clear your cookies and try again.");
}
} else {
req["token"] = token;
req["user"] = user;
next();
}
});
})
.error(err => {
console.error("Session resolve error",err);
next();
});
} else {
next();
}
}

38
middlewares/setuser.js Normal file
View File

@@ -0,0 +1,38 @@
'use strict';
require('../models/schema');
var config = require('config');
module.exports = (req, res, next) => {
const token = req.cookies["sdsession"];
if (token && token != "null" && token !== null) {
User.findOne({
"sessions.token": token
}).populate('team').exec((err, user) => {
if (!user) {
// FIXME
var domain = "localhost";
res.clearCookie('sdsession', {
domain: domain
});
if (req.accepts("text/html")) {
res.redirect("/");
} else if (req.accepts('application/json')) {
res.status(403).json({
"error": "token_not_found"
});
} else {
res.redirect("/");
}
} else {
req["token"] = token;
req["user"] = user;
next();
}
});
} else {
next();
}
}

View File

@@ -1,6 +1,6 @@
'use strict';
const db = require('../models/db');
require('../models/schema');
var config = require('config');
module.exports = (req, res, next) => {
@@ -19,6 +19,50 @@ module.exports = (req, res, next) => {
}
};
var rolePerUser = (originalSpace, user, cb) => {
originalSpace.path = [];
if (originalSpace._id.equals(req.user.home_folder_id) || (originalSpace.creator && originalSpace.creator._id.equals(req.user._id))) {
cb("admin");
} else {
var findMembershipsForSpace = function(space, allMemberships, prevRole) {
Membership.find({
"space": space._id
}, function(err, parentMemberships) {
var currentMemberships = parentMemberships.concat(allMemberships);
if (space.parent_space_id) {
Space.findOne({
"_id": space.parent_space_id
}, function(err, parentSpace) {
findMembershipsForSpace(parentSpace, currentMemberships, prevRole);
});
} else {
// reached the top
var role = prevRole;
space.memberships = currentMemberships;
if(role == "none"){
if(originalSpace.access_mode == "public") {
role = "viewer";
}
}
currentMemberships.forEach(function(m, i) {
if (m.user && m.user.equals(user._id)) {
role = m.role;
}
});
cb(role);
}
});
};
findMembershipsForSpace(originalSpace, [], "none");
}
};
var finalizeAnonymousLogin = function(space, spaceAuth) {
var role = "none";
@@ -33,7 +77,7 @@ module.exports = (req, res, next) => {
}
if (req.user) {
db.getUserRoleInSpace(space, req.user, function(newRole) {
rolePerUser(space, req.user, function(newRole) {
if (newRole == "admin" && (role == "editor" || role == "viewer")) {
finalizeReq(space, newRole);
} else if (newRole == "editor" && (role == "viewer")) {
@@ -53,66 +97,64 @@ module.exports = (req, res, next) => {
'email': 1
};
db.Space.findOne({where: {
Space.findOne({
"_id": spaceId
}}).then(function(space) {
}).populate("creator", userMapping).exec(function(err, space) {
if (err) {
res.status(400).json(err);
} else {
if (space) {
//.populate("creator", userMapping)
//if (err) {
// res.status(400).json(err);
//} else {
if (space.access_mode == "public") {
if (space) {
if (space.access_mode == "public") {
if (space.password) {
if (req.spacePassword) {
if (req.spacePassword === space.password) {
finalizeAnonymousLogin(space, req["spaceAuth"]);
if (space.password) {
if (req.spacePassword) {
if (req.spacePassword === space.password) {
finalizeAnonymousLogin(space, req["spaceAuth"]);
} else {
res.status(403).json({
"error": "password_wrong"
});
}
} else {
res.status(403).json({
"error": "password_wrong"
res.status(401).json({
"error": "password_required"
});
}
} else {
res.status(401).json({
"error": "password_required"
});
finalizeAnonymousLogin(space, req["spaceAuth"]);
}
} else {
finalizeAnonymousLogin(space, req["spaceAuth"]);
}
// special permission for screenshot/pdf export from backend
if (req.query['api_token'] && req.query['api_token'] == config.get('phantom_api_secret')) {
finalizeReq(space, "viewer");
return;
}
} else {
// space is private
// special permission for screenshot/pdf export from backend
if (req.query['api_token'] && req.query['api_token'] == config.get('phantom_api_secret')) {
finalizeReq(space, "viewer");
return;
}
if (req.user) {
db.getUserRoleInSpace(space, req.user, function(role) {
if (role == "none") {
if (req.user) {
rolePerUser(space, req.user, function(role) {
if (role == "none") {
finalizeAnonymousLogin(space, req["spaceAuth"]);
} else {
finalizeReq(space, role);
}
});
} else {
if (req.spaceAuth && space.edit_hash) {
finalizeAnonymousLogin(space, req["spaceAuth"]);
} else {
finalizeReq(space, role);
res.status(403).json({
"error": "auth_required"
});
}
});
} else {
if (req.spaceAuth && space.edit_hash) {
finalizeAnonymousLogin(space, req["spaceAuth"]);
} else {
res.status(403).json({
"error": "auth_required"
});
}
}
} else {
res.status(404).json({
"error": "space_not_found"
});
}
} else {
res.status(404).json({
"error": "space_not_found"
});
}
});
}

33
middlewares/subdomain.js Normal file
View File

@@ -0,0 +1,33 @@
'use strict';
require('../models/schema');
var config = require('config');
module.exports = (req, res, next) => {
let host = req.headers.host;
Team.getTeamForHost(host, (err, team, subdomain) => {
if (subdomain) {
if (!err && team) {
req.subdomainTeam = team;
req.subdomain = subdomain;
next()
} else {
if (req.accepts('text/html')) {
res.status(404).render('not_found', {
title: 'Page Not Found.'
});
} else if (req.accepts('application/json')) {
res.status(404).json({
"error": "not_found"
});
} else {
res.status(404).render('not_found', {
title: 'Page Not Found.'
});
}
}
} else {
next();
}
});
}

View File

@@ -0,0 +1,23 @@
'use strict';
require('../models/schema');
var config = require('config');
module.exports = (req, res, next) => {
if (req.user) {
var isAdmin = req.user.team.admins.indexOf(req.user._id) >= 0;
var correctMethod = req.method == "GET" || (req.method == "DELETE" || req.method == "PUT" || req.method == "POST");
if (correctMethod && isAdmin) {
next();
} else {
res.status(403, {
"error": "not authorized"
});
}
} else {
res.status(403, {
"error": "not logged in"
});
}
}

31
middlewares/templates.js Normal file
View File

@@ -0,0 +1,31 @@
'use strict';
require('../models/schema');
var config = require('config');
var _ = require('underscore');
module.exports = (req, res, next) => {
res.oldRender = res.render;
res.render = function(template, params) {
var team = req.subdomainTeam;
if (team) {
team = _.pick(team.toObject(), ['_id', 'name', 'subdomain', 'avatar_original_uri']);
} else {
team = null;
}
const addParams = {
locale: req.i18n.locale,
config: config,
subdomain_team: team,
user: req.user,
csrf_token: "",
socket_auth: req.token
};
const all = _.extend(params, addParams);
res.oldRender(template, all);
};
next();
}

View File

@@ -1,7 +1,5 @@
'use strict';
// FIXME port this last model
var mongoose = require('mongoose');
var Schema = mongoose.Schema;

88
models/artifact.js Normal file
View File

@@ -0,0 +1,88 @@
'use strict';
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
module.exports.artifactSchema = mongoose.model('Artifact', {
mime: String,
thumbnail_uri: String,
space_id: Schema.Types.ObjectId,
user_id: {type: Schema.Types.ObjectId, ref: 'User' },
last_update_user_id: {type: Schema.Types.ObjectId, ref: 'User' },
editor_name: String,
last_update_editor_name: String,
description: String,
state: {type: String, default: "idle"},
meta: {
linked_to: [String],
title: String,
tags: [String],
search_text: String,
link_uri: String,
play_from: Number,
play_to: Number,
},
board: {
x: {type: Number, default: 0.0},
y: {type: Number, default: 0.0},
z: {type: Number, default: 0.0},
r: {type: Number, default: 0.0},
w: {type: Number, default: 100},
h: {type: Number, default: 100},
},
control_points: [{
dx: Number, dy: Number
}],
group:{type: String, default: ""},
locked: {type: Boolean, default: false},
payload_uri: String,
payload_thumbnail_web_uri: String,
payload_thumbnail_medium_uri: String,
payload_thumbnail_big_uri: String,
payload_size: Number, // file size in bytes
style: {
fill_color: {type: String, default: "transparent"},
stroke_color:{type: String, default: "#000000"},
text_color: String,
stroke: {type: Number, default: 0.0},
stroke_style: {type: String, default: "solid"},
alpha: {type: Number, default: 1.0},
order: {type: Number, default: 0},
crop: {
x: Number,
y: Number,
w: Number,
h: Number
},
shape: String,
shape_svg: String,
padding_left: Number,
padding_right: Number,
padding_top: Number,
padding_bottom: Number,
margin_left: Number,
margin_right: Number,
margin_top: Number,
margin_bottom: Number,
border_radius: Number,
align: {type: String, default: "left"},
valign: {type: String, default: "top"},
brightness: Number,
contrast: Number,
saturation: Number,
blur: Number,
hue: Number,
opacity: Number
},
payload_alternatives: [{
mime: String,
payload_uri: String,
payload_thumbnail_web_uri: String,
payload_thumbnail_medium_uri: String,
payload_thumbnail_big_uri: String,
payload_size: Number
}],
created_at: {type: Date, default: Date.now},
created_from_ip: {type: String},
updated_at: {type: Date, default: Date.now}
});

View File

@@ -1,364 +0,0 @@
const Umzug = require('umzug');
function sequel_log(a,b,c) {
console.log(a);
}
const Sequelize = require('sequelize');
const sequelize = new Sequelize('database', 'username', 'password', {
host: 'localhost',
dialect: 'sqlite',
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
// SQLite only
storage: 'database.sqlite',
logging: sequel_log,
// http://docs.sequelizejs.com/manual/tutorial/querying.html#operators
operatorsAliases: false
});
var User;
var Session;
var Space;
var Membership;
var Artifact;
var Message;
var Action;
module.exports = {
User: sequelize.define('user', {
_id: {type: Sequelize.STRING, primaryKey: true},
email: Sequelize.STRING,
password_hash: Sequelize.STRING,
nickname: Sequelize.STRING,
avatar_original_uri: Sequelize.STRING,
avatar_thumb_uri: Sequelize.STRING,
confirmation_token: Sequelize.STRING,
password_reset_token: Sequelize.STRING,
home_folder_id: Sequelize.STRING,
prefs_language: Sequelize.STRING,
prefs_email_notifications: Sequelize.STRING,
prefs_email_digest: Sequelize.STRING,
created_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW},
updated_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW}
}),
Session: sequelize.define('session', {
token: {type: Sequelize.STRING, primaryKey: true},
user_id: Sequelize.STRING,
expires: Sequelize.DATE,
created_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW},
device: Sequelize.STRING,
ip: Sequelize.STRING
}),
Space: sequelize.define('space', {
_id: {type: Sequelize.STRING, primaryKey: true},
name: {type: Sequelize.STRING, default: "New Space"},
space_type: {type: Sequelize.STRING, defaultValue: "space"},
creator_id: Sequelize.STRING,
parent_space_id: Sequelize.STRING,
access_mode: {type: Sequelize.STRING, default: "private"}, // "public" || "private"
password: Sequelize.STRING,
edit_hash: Sequelize.STRING,
edit_slug: Sequelize.STRING,
editors_locking: Sequelize.BOOLEAN,
thumbnail_uri: Sequelize.STRING,
width: Sequelize.INTEGER,
height: Sequelize.INTEGER,
background_color: Sequelize.STRING,
background_uri: Sequelize.STRING,
created_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW},
updated_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW},
thumbnail_url: Sequelize.STRING,
thumbnail_updated_at: {type: Sequelize.DATE}
}),
Membership: sequelize.define('membership', {
_id: {type: Sequelize.STRING, primaryKey: true},
space_id: Sequelize.STRING,
user_id: Sequelize.STRING,
role: Sequelize.STRING,
code: Sequelize.STRING,
state: {type: Sequelize.STRING, defaultValue: "pending"},
created_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW},
updated_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW}
}),
Message: sequelize.define('message', {
_id: {type: Sequelize.STRING, primaryKey: true},
space_id: Sequelize.STRING,
user_id: Sequelize.STRING,
editor_name: Sequelize.STRING,
message: Sequelize.TEXT,
created_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW},
updated_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW}
}),
Artifact: sequelize.define('artifact', {
_id: {type: Sequelize.STRING, primaryKey: true},
space_id: Sequelize.STRING,
user_id: Sequelize.STRING,
mime: Sequelize.STRING,
thumbnail_uri: Sequelize.STRING,
last_update_user_id: Sequelize.STRING,
editor_name: Sequelize.STRING,
last_update_editor_name: Sequelize.STRING,
description: Sequelize.TEXT,
state: {type: Sequelize.STRING, default: "idle"},
//linked_to: Sequelize.STRING,
title: Sequelize.STRING,
tags: Sequelize.TEXT,
search_text: Sequelize.STRING,
link_uri: Sequelize.STRING,
play_from: Sequelize.DECIMAL,
play_to: Sequelize.DECIMAL,
x: {type: Sequelize.DECIMAL, default: 0.0},
y: {type: Sequelize.DECIMAL, default: 0.0},
z: {type: Sequelize.DECIMAL, default: 0.0},
r: {type: Sequelize.DECIMAL, default: 0.0},
w: {type: Sequelize.DECIMAL, default: 100},
h: {type: Sequelize.DECIMAL, default: 100},
//control_points: [{
// dx: Number, dy: Number
//}],
control_points: Sequelize.TEXT,
group: Sequelize.STRING,
locked: {type: Sequelize.BOOLEAN, default: false},
payload_uri: Sequelize.STRING,
payload_thumbnail_web_uri: Sequelize.STRING,
payload_thumbnail_medium_uri: Sequelize.STRING,
payload_thumbnail_big_uri: Sequelize.STRING,
payload_size: Sequelize.INTEGER, // file size in bytes
fill_color: {type: Sequelize.STRING, default: "transparent"},
stroke_color: {type: Sequelize.STRING, default: "#000000"},
text_color: Sequelize.STRING,
stroke: {type: Sequelize.DECIMAL, default: 0.0},
stroke_style: {type: Sequelize.STRING, default: "solid"},
alpha: {type: Sequelize.DECIMAL, default: 1.0},
order: {type: Sequelize.INTEGER, default: 0},
crop_x: Sequelize.INTEGER,
crop_y: Sequelize.INTEGER,
crop_w: Sequelize.INTEGER,
crop_h: Sequelize.INTEGER,
shape: Sequelize.STRING,
shape_svg: Sequelize.STRING,
padding_left: Sequelize.INTEGER,
padding_right: Sequelize.INTEGER,
padding_top: Sequelize.INTEGER,
padding_bottom: Sequelize.INTEGER,
margin_left: Sequelize.INTEGER,
margin_right: Sequelize.INTEGER,
margin_top: Sequelize.INTEGER,
margin_bottom: Sequelize.INTEGER,
border_radius: Sequelize.INTEGER,
align: {type: Sequelize.STRING, default: "left"},
valign: {type: Sequelize.STRING, default: "top"},
brightness: Sequelize.DECIMAL,
contrast: Sequelize.DECIMAL,
saturation: Sequelize.DECIMAL,
blur: Sequelize.DECIMAL,
hue: Sequelize.DECIMAL,
opacity: Sequelize.DECIMAL,
payload_alternatives: Sequelize.TEXT,
/*payload_alternatives: [{
mime: String,
payload_uri: String,
payload_thumbnail_web_uri: String,
payload_thumbnail_medium_uri: String,
payload_thumbnail_big_uri: String,
payload_size: Number
}],*/
created_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW},
updated_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW}
}),
init: async function() {
User = this.User;
Session = this.Session;
Space = this.Space;
Artifact = this.Artifact;
Message = this.Message;
Membership = this.Membership;
Space.belongsTo(User, {
foreignKey: {
name: 'creator_id'
},
as: 'creator'
});
Membership.belongsTo(User, {
foreignKey: {
name: 'user_id'
},
as: 'user'
});
Membership.belongsTo(Space, {
foreignKey: {
name: 'space_id'
},
as: 'space'
});
Artifact.belongsTo(User, {
foreignKey: {
name: 'user_id'
},
as: 'user'
});
Artifact.belongsTo(Space, {
foreignKey: {
name: 'space_id'
},
as: 'space'
});
Message.belongsTo(User, {
foreignKey: {
name: 'user_id'
},
as: 'user'
});
Message.belongsTo(Space, {
foreignKey: {
name: 'space_id'
},
as: 'space'
});
await sequelize.sync();
var umzug = new Umzug({
storage: 'sequelize',
storageOptions: {
sequelize: sequelize
},
migrations: {
params: [
sequelize.getQueryInterface(),
Sequelize
],
path: './models/migrations',
pattern: /\.js$/
}
});
umzug.up().then(function(migrations) {
console.log('Migration complete up!');
});
},
getUserRoleInSpace: (originalSpace, user, cb) => {
originalSpace.path = [];
console.log("getUserRoleInSpace",originalSpace._id,user._id,user.home_folder_id);
if (originalSpace._id == user.home_folder_id || (originalSpace.creator_id && originalSpace.creator_id == user._id)) {
cb("admin");
} else {
var findMembershipsForSpace = function(space, allMemberships, prevRole) {
Membership.findAll({ where: {
"space": space._id
}}).then(function(parentMemberships) {
var currentMemberships = parentMemberships.concat(allMemberships);
if (space.parent_space_id) {
Space.findOne({ where: {
"_id": space.parent_space_id
}}, function(err, parentSpace) {
findMembershipsForSpace(parentSpace, currentMemberships, prevRole);
});
} else {
// reached the top
var role = prevRole;
space.memberships = currentMemberships;
if (role == "none") {
if (originalSpace.access_mode == "public") {
role = "viewer";
}
}
currentMemberships.forEach(function(m, i) {
if (m.user_id && m.user_id == user._id) {
role = m.role;
}
});
cb(role);
}
});
};
findMembershipsForSpace(originalSpace, [], "none");
}
},
spaceToObject: (space) => {
// FIXME TODO
return space;
},
findUserBySessionToken: (token, cb) => {
Session.findOne({where: {token: token}})
.then(session => {
if (!session) cb(null, null)
else User.findOne({where: {_id: session.user_id}})
.then(user => {
cb(null, user)
})
})
},
unpackArtifact: (a) => {
if (a.tags && (typeof a.tags)=="string") {
a.tags = JSON.parse(a.tags);
}
if (a.control_points && (typeof a.control_points)=="string") {
a.control_points = JSON.parse(a.control_points);
}
if (a.payload_alternatives && (typeof a.payload_alternatives)=="string") {
a.payload_alternatives = JSON.parse(a.payload_alternatives);
}
return a;
},
packArtifact: (a) => {
if (a.tags && (typeof a.tags)!="string") {
a.tags = JSON.stringify(a.tags);
}
if (a.control_points && (typeof a.control_points)!="string") {
a.control_points = JSON.stringify(a.control_points);
}
if (a.payload_alternatives && (typeof a.payload_alternatives)!="string") {
a.payload_alternatives = JSON.stringify(a.payload_alternatives);
}
return a;
}
}

21
models/domain.js Normal file
View File

@@ -0,0 +1,21 @@
'use strict';
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
module.exports.domainSchema = mongoose.Schema({
domain: String,
edu: Boolean,
created_at: {
type: Date,
default: Date.now
},
updated_at: {
type: Date,
default: Date.now
}
});
module.exports.domainSchema.index({
domain: 1
});

45
models/membership.js Normal file
View File

@@ -0,0 +1,45 @@
'use strict';
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
module.exports.membershipSchema = mongoose.Schema({
user: {
type: Schema.Types.ObjectId,
ref: 'User'
},
space: {
type: Schema.Types.ObjectId,
ref: 'Space'
},
team: {
type: Schema.Types.ObjectId,
ref: 'Team'
},
role: {
type: String,
default: "viewer"
},
state: {
type: String,
default: "active"
},
email_invited: String,
code: String,
created_at: {
type: Date,
default: Date.now
},
updated_at: {
type: Date,
default: Date.now
}
});
module.exports.membershipSchema.index({
user: 1,
space: 1,
team: 1,
code: 1
});

31
models/message.js Normal file
View File

@@ -0,0 +1,31 @@
'use strict';
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
module.exports.messageSchema = mongoose.Schema({
user: {
type: Schema.Types.ObjectId,
ref: 'User'
},
editor_name: String,
space: {
type: Schema.Types.ObjectId,
ref: 'Space'
},
message: String,
created_from_ip: {type: String},
created_at: {
type: Date,
default: Date.now
},
updated_at: {
type: Date,
default: Date.now
}
});
module.exports.messageSchema.index({
space: 1,
user: 1
});

View File

@@ -1,80 +0,0 @@
'use strict';
module.exports = {
up: function(migration, DataTypes) {
return [
migration.changeColumn('memberships', 'space_id',
{
type: DataTypes.STRING,
references: {
model: 'spaces',
key: '_id'
},
onDelete: 'CASCADE',
onUpdate: 'CASCADE'
}
),
migration.changeColumn('artifacts', 'space_id',
{
type: DataTypes.STRING,
references: {
model: 'spaces',
key: '_id'
},
onDelete: 'CASCADE',
onUpdate: 'CASCADE'
}
),
migration.changeColumn('messages', 'space_id',
{
type: DataTypes.STRING,
references: {
model: 'spaces',
key: '_id'
},
onDelete: 'CASCADE',
onUpdate: 'CASCADE'
}
)
]
},
down: function(migration, DataTypes) {
return [
migration.changeColumn('memberships', 'space_id',
{
type: DataTypes.STRING,
references: {
model: 'spaces',
key: '_id'
},
onDelete: 'CASCADE',
onUpdate: 'NO ACTION'
}
),
,
migration.changeColumn('artifacts', 'space_id',
{
type: DataTypes.STRING,
references: {
model: 'spaces',
key: '_id'
},
onDelete: 'CASCADE',
onUpdate: 'NO ACTION'
}
),
migration.changeColumn('messages', 'space_id',
{
type: DataTypes.STRING,
references: {
model: 'spaces',
key: '_id'
},
onDelete: 'CASCADE',
onUpdate: 'NO ACTION'
}
)
]
}
};

44
models/plan.js Normal file
View File

@@ -0,0 +1,44 @@
'use strict';
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
Plan = mongoose.model('Plan', {
key: String,
description: String,
limit_folders: {
type: Number,
default: 200
},
limit_spaces: {
type: Number,
default: 500
},
limit_storage_bytes: {
type: Number,
default: 10737418240
},
plan_type: {
type: String,
default: "org"
},
price: Number,
public: Boolean,
recurring: {
type: String,
default: "month"
},
title: String,
trial_days: Number,
voucher_code: String,
created_at: {
type: Date,
default: Date.now
},
updated_at: {
type: Date,
default: Date.now
}
});
exports.planModel = Plan;

12
models/schema.js Normal file
View File

@@ -0,0 +1,12 @@
//'use strict';
var mongoose = require('mongoose');
User = mongoose.model('User', require('./user').userSchema);
Action = mongoose.model('Action', require('./action').actionSchema);
Space = mongoose.model('Space', require('./space').spaceSchema);
Artifact = mongoose.model('Artifact', require('./artifact').artifactSchema);
Team = mongoose.model('Team', require('./team').teamSchema);
Message = mongoose.model('Message', require('./message').messageSchema);
Membership = mongoose.model('Membership', require('./membership').membershipSchema);
Domain = mongoose.model('Domain', require('./domain').domainSchema);

273
models/space.js Normal file
View File

@@ -0,0 +1,273 @@
'use strict';
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var async = require('async');
var _ = require("underscore");
var crypto = require('crypto');
module.exports.spaceSchema = Schema({
name: {type: String, default: "New Space"},
space_type: {type: String, default: "space"},
creator : { type: Schema.Types.ObjectId, ref: 'User' },
parent_space_id: Schema.Types.ObjectId,
access_mode: {type: String, default: "private"}, // "public" || "private"
password: String,
edit_hash: String,
edit_slug: String,
editors_locking: Boolean,
thumbnail_uri: String,
stats: {
num_children: Number,
total_spaces: Number,
total_folders: Number,
storage_bytes: Number,
},
advanced: {
type: {
width: Number,
height: Number,
margin: Number,
background_color: String,
background_uri: String,
background_repeat: Boolean,
grid_size: Number,
grid_divisions: Number,
gutter: Number,
columns: Number,
column_max_width: Number,
columns_responsive: Number,
row_max_height: Number,
padding_horz: Number,
padding_vert: Number
},
default: {
width: 200,
height: 400,
margin: 0,
background_color: "rgba(255,255,255,1)"
}
},
blocked_at: {type: Date, default: Date.now},
created_at: {type: Date, default: Date.now},
updated_at: {type: Date, default: Date.now},
thumbnail_updated_at: {type: Date},
thumbnail_url: String
});
module.exports.spaceSchema.index({ creator: 1, parent_space_id: 1, created_at: 1, updated_at: 1, edit_hash: 1});
module.exports.spaceSchema.statics.allForUser = function (user, callback) {
return this.find({user_id: user_id}, callback);
};
module.exports.spaceSchema.statics.getMemberships = function (err, callback) {
callback(null, {});
};
var getRecursiveSubspacesForSpace = (parentSpace, cb) => {
if (parentSpace.space_type == "folder") {
Space.find({
"parent_space_id": parentSpace._id
}).exec((err, subspaces) => {
async.map(subspaces, (space, innerCb) => {
getRecursiveSubspacesForSpace(space, (err, spaces) => {
innerCb(err, spaces);
});
}, (err, subspaces) => {
var flattenSubspaces = _.flatten(subspaces);
flattenSubspaces.push(parentSpace);
cb(null, flattenSubspaces);
});
});
} else {
cb(null, [parentSpace]);
}
};
module.exports.spaceSchema.statics.getRecursiveSubspacesForSpace = getRecursiveSubspacesForSpace;
var roleMapping = {
"none": 0,
"viewer": 1,
"editor": 2,
"admin": 3
}
module.exports.spaceSchema.statics.roleInSpace = (originalSpace, user, cb) => {
if (user.home_folder_id.toString() === originalSpace._id.toString()) {
cb(null, "admin");
return;
}
if (originalSpace.creator) {
if (originalSpace.creator._id.toString() === user._id.toString()) {
cb(null, "admin");
return;
}
}
var findMembershipsForSpace = function(space, allMemberships, prevRole) {
Membership.find({
"space": space._id
}, (err, parentMemberships) => {
var currentMemberships = parentMemberships.concat(allMemberships);
if (space.parent_space_id) {
Space.findOne({
"_id": space.parent_space_id
}, function(err, parentSpace) {
var role = prevRole;
if(role == "none"){
if(originalSpace.access_mode == "public") {
role = "viewer";
}
}
findMembershipsForSpace(parentSpace, currentMemberships, role);
});
} else {
// reached the top
var role = prevRole;
space.memberships = currentMemberships;
currentMemberships.forEach(function(m, i) {
if (m.user && m.user.equals(user._id)) {
if (m.role != null) {
if (roleMapping[m.role] > roleMapping[role]) {
role = m.role;
}
}
}
});
cb(err, role);
}
});
};
findMembershipsForSpace(originalSpace, [], "none");
}
module.exports.spaceSchema.statics.recursiveDelete = (space, cb) => {
space.remove(function(err) {
Action.remove({
space: space
}, function(err) {
if (err)
console.error("removed actions for space: ", err);
});
Membership.remove({
space: space
}, function(err) {
if (err)
console.error("removed memberships for space: ", err);
});
if (space.space_type === "folder") {
Space
.find({
parent_space_id: space._id
})
.exec(function(err, spaces) {
async.eachLimit(spaces, 10, function(subSpace, innerCb) {
module.exports.spaceSchema.statics.recursiveDelete(subSpace, function(err) {
innerCb(err);
});
}, function(err) {
cb(err);
});
});
} else {
Artifact.find({
space_id: space._id
}, function(err, artifacts) {
if (err) cb(err);
else {
async.eachLimit(artifacts, 20, function(a, innerCb) {
a.remove(function(err) {
innerCb(null, a);
});
}, function(err) {
cb(err);
});
}
});
}
});
};
var duplicateRecursiveSpace = (space, user, depth, cb, newParentSpace) => {
var newSpace = new Space(space);
newSpace._id = mongoose.Types.ObjectId();
if (newParentSpace) {
newSpace.parent_space_id = newParentSpace._id;
} else {
newSpace.name = newSpace.name + " (b)";
}
newSpace.creator = user;
newSpace.created_at = new Date();
newSpace.updated_at = new Date();
if (newSpace.space_type === "space") {
newSpace.edit_hash = crypto.randomBytes(64).toString('hex').substring(0, 7);
}
newSpace.save(function(err) {
if (newSpace.space_type === "folder" && depth < 10) {
Space
.find({
parent_space_id: space._id
})
.exec(function(err, spaces) {
async.eachLimit(spaces, 10, function(subSpace, innerCb) {
duplicateRecursiveSpace(subSpace, user, ++depth, function(err, newSubSpace) {
innerCb(err, newSubSpace);
}, newSpace);
}, function(err, allNewSubspaces) {
cb(err, newSpace);
});
});
} else {
Artifact.find({
space_id: space._id
}, function(err, artifacts) {
if (err) innerCb(err);
else {
async.eachLimit(artifacts, 20, function(a, innerCb) {
var newArtifact = new Artifact(a);
newArtifact._id = mongoose.Types.ObjectId();
newArtifact.space_id = newSpace._id;
newArtifact.created_at = new Date();
newArtifact.updated_at = new Date();
newArtifact.save(function(err) {
innerCb(null, newArtifact);
});
}, function(err, allNewArtifacts) {
cb(err, newSpace);
});
}
});
}
});
};
module.exports.spaceSchema.statics.duplicateSpace = duplicateRecursiveSpace;

70
models/team.js Normal file
View File

@@ -0,0 +1,70 @@
'use strict';
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
module.exports.teamSchema = mongoose.Schema({
name: String,
subdomain: String,
creator: {
type: Schema.Types.ObjectId,
ref: 'User'
},
admins: [{
type: Schema.Types.ObjectId,
ref: 'User'
}],
invitation_codes: [String],
avatar_thumb_uri: String,
avatar_uri: String,
payment_type: {
type: String,
default: "auto"
},
payment_plan_key: String,
payment_subscription_id: String,
blocked_at: {
type: Date
},
upgraded_at: {
type: Date
},
created_at: {
type: Date,
default: Date.now
},
updated_at: {
type: Date,
default: Date.now
}
});
module.exports.teamSchema.index({
creator: 1
});
module.exports.teamSchema.statics.getTeamForHost = (host, cb) => {
if (host != "127.0.0.1:9000") { //phantomjs check
let subDomainParts = host.split('.');
if (subDomainParts.length > 2) {
const subdomain = subDomainParts[0];
if (subdomain != "www") {
Team.findOne({
subdomain: subdomain
}).exec((err, team) => {
cb(err, team, subdomain)
});
} else {
cb(null, null)
}
} else {
cb(null, null);
}
} else {
cb(null, null);
}
}

53
models/user.js Normal file
View File

@@ -0,0 +1,53 @@
'use strict';
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
module.exports.userSchema = mongoose.Schema({
email: String,
password_hash: String,
nickname: String,
account_type: {type: String, default: "email"},
created_at: {type: Date, default: Date.now},
updated_at: {type: Date, default: Date.now},
avatar_original_uri: String,
avatar_thumb_uri: String,
src: String,
confirmation_token: String,
confirmed_at: Date,
password_reset_token: String,
home_folder_id: Schema.Types.ObjectId,
team : { type: Schema.Types.ObjectId, ref: 'Team' },
preferences: {
language: String,
email_notifications: {type: Boolean, default: true},
daily_digest_last_send: Date,
daily_digest: {type: Boolean, default: true}
},
sessions: [
{
token: String,
expires: Date,
device: String,
ip: String,
created_at: Date
}
],
payment_info: String,
payment_plan_key: {type: String, default: "free"},
payment_customer_id: String,
payment_subscription_id: String,
payment_notification_state: Number
});
module.exports.userSchema.index({
email: 1,
"sessions.token": 1,
team: 1,
created_at: 1,
home_folder_id: 1
});
module.exports.userSchema.statics.findBySessionToken = function (token, cb) {
return this.findOne({ "sessions.token": token}, cb);
};

View File

@@ -3,52 +3,84 @@
"version": "1.0.0",
"private": true,
"scripts": {
"start": "electron ."
},
"engines": {
"node": ">=7.8.0"
"start": "nodemon -e .js,.html bin/www",
"test": "mocha"
},
"dependencies": {
"archiver": "1.3.0",
"async": "2.3.0",
"aws-sdk": "2.39.0",
"basic-auth": "1.1.0",
"bcryptjs": "2.4.3",
"bcrypt": "*",
"body-parser": "~1.17.1",
"cheerio": "0.22.0",
"config": "1.25.1",
"cookie-parser": "~1.4.3",
"electron": "^1.8.4",
"csurf": "1.9.0",
"debug": "~2.6.3",
"execSync": "latest",
"express": "~4.13.0",
"file-type": "^7.6.0",
"express": "~4.15.2",
"glob": "7.1.1",
"gm": "1.23.0",
"googleapis": "18.0.0",
"gulp": "^3.9.0",
"gulp-concat": "2.6.1",
"gulp-eslint": "*",
"gulp-express": "0.3.5",
"gulp-nodemon": "*",
"gulp-sass": "^3.1.0",
"gulp-uglify": "^2.1.2",
"gulp-util": "^3.0.6",
"helmet": "^3.5.0",
"i18n-2": "0.6.3",
"ioredis": "2.5.0",
"lodash": "^4.3.0",
"log-timestamp": "latest",
"mock-aws-s3": "^2.6.0",
"moment": "^2.19.3",
"md5": "2.2.1",
"moment": "2.18.1",
"mongoose": "4.9.3",
"morgan": "1.8.1",
"node-sass-middleware": "0.11.0",
"pdfkit": "0.8.0",
"validator": "7.0.0",
"node-phantom-simple": "2.2.4",
"phantomjs-prebuilt": "2.1.14",
"read-chunk": "^2.1.0",
"pm2": "latest",
"qr-image": "3.2.0",
"raven": "1.2.0",
"request": "2.81.0",
"sanitize-html": "^1.11.1",
"sequelize": "^4.37.6",
"serve-favicon": "~2.4.2",
"serve-static": "^1.13.1",
"slug": "0.9.1",
"sqlite3": "^4.0.0",
"swig": "1.4.2",
"umzug": "^2.1.0",
"slug": "0.9.1",
"underscore": "1.8.3",
"uuid": "^3.2.1",
"validator": "7.0.0",
"weak": "1.0.1",
"ws": "2.2.3"
},
"main": "app.js",
"devDependencies": {
"express": "^4.13.3",
"gulp": "^3.9.0",
"gulp-clean": "^0.3.2",
"gulp-concat": "^2.6.0",
"gulp-eslint": "^3.0.1",
"gulp-express": "^0.3.0",
"gulp-fingerprint": "^0.3.2",
"gulp-nodemon": "^2.0.4",
"gulp-rev": "^7.1.2",
"gulp-rev-all": "^0.9.7",
"gulp-rev-replace": "^0.4.3",
"gulp-sass": "^3.1.0",
"gulp-uglify": "^2.1.2",
"mocha": "*",
"nodemon": "*",
"should": "^11.2.1",
"supertest": "^3.0.0",
"winston": "^2.3.1"
},
"description": "",
"directories": {},
"main": "Gulpfile.js",
"directories": {
},
"repository": {
"type": "git",
"url": "https://github.com/spacedeck/spacedeck-open.git"

View File

@@ -133,15 +133,7 @@ function load_spaces(id, is_home, on_success, on_error) {
}, on_error);
}
function load_importables(user, on_success, on_error) {
load_resource("get", "/users/"+user._id+"/importables", null, on_success, on_error);
}
function import_zip(user, filename, on_success, on_error) {
load_resource("get", "/users/"+user._id+"/import?zip="+filename, null, on_success, on_error);
}
function load_writable_folders(on_success, on_error) {
function load_writable_folders( on_success, on_error) {
load_resource("get", "/spaces?writablefolders=true", null, on_success, on_error);
}

File diff suppressed because it is too large Load Diff

View File

@@ -8,29 +8,24 @@ SpacedeckAccount = {
account_confirmed_sent: false,
account_tab: 'invoices',
password_change_error: null,
feedback_text: "",
importables: [], // spacedeck.com zip import files
feedback_text: ""
},
methods: {
show_account: function() {
show_account: function(user) {
this.activate_dropdown('account');
},
start_zip_import: function(f) {
if (confirm("Your archive will be imported in the background. This can take a few minutes. You can continue using Spacedeck in the meantime.")) {
import_zip(this.user, f);
}
this.load_subscription();
this.load_billing();
},
account_save_user_digest: function(val) {
this.user.prefs_email_digest = val;
this.save_user(function() {
this.user.preferences.daily_digest = val;
this.save_user(function(){
});
},
account_save_user_notifications: function(val) {
this.user.prefs_email_notifications = val;
this.save_user(function() {
this.user.preferences.email_notifications = val;
this.save_user(function(){
});
},
@@ -41,11 +36,13 @@ SpacedeckAccount = {
save_user_language: function(lang) {
localStorage.lang = lang;
this.user.prefs_language = lang;
this.save_user(function() {
window._spacedeck_location_change = true;
location.href="/spaces";
}.bind(this));
if (this.user.preferences) {
this.user.preferences.language = lang;
this.save_user(function() {
window._spacedeck_location_change = true;
location.href="/spaces";
}.bind(this));
}
},
save_user: function(on_success) {

View File

@@ -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.toString());
medium.value(a.description);
}
}
},
@@ -61,16 +61,16 @@ var SpacedeckBoardArtifacts = {
},
artifact_link: function(a) {
if (a.link_uri) {
return a.link_uri;
if (a.meta && a.meta.link_uri) {
return a.meta.link_uri;
} else {
return "";
}
},
artifact_link_caption: function(a) {
if (a.link_uri) {
var parts = a.link_uri.split("/");
if (a.meta && a.meta.link_uri) {
var parts = a.meta.link_uri.split("/");
// scheme://domain.foo/...
// 0 1 2
if (parts.length>2) {
@@ -88,11 +88,10 @@ var SpacedeckBoardArtifacts = {
},
artifact_is_text_blank: function(a) {
if (a.description) {
desc = a.description.toString();
var filtered = desc.replace(/<[^>]+>/g,"").replace(/\s/g,"");
if(a.description){
var filtered = a.description.replace(/<[^>]+>/g,"").replace(/\s/g,"");
return (filtered.length<1);
} else {
}else{
return false;
}
},
@@ -103,9 +102,11 @@ var SpacedeckBoardArtifacts = {
if (this.artifact_is_selected(a) && this.editing_artifact_id!=a._id) clzs.push("selected");
if (!a._id) clzs.push("creating");
if (a.align) clzs.push("align-"+a.align);
if (a.valign) clzs.push("align-"+a.valign);
if (a.style) {
clzs.push("align-"+a.style.align);
clzs.push("align-"+a.style.valign);
}
clzs.push("state-"+a.state);
if (this.artifact_is_text_blank(a)) {
@@ -122,56 +123,56 @@ var SpacedeckBoardArtifacts = {
artifact_inner_style: function(a) {
var styles = [];
//if (a.style) {
if (a.style) {
var svg_style = ((a.mime.match("vector") || a.mime.match("shape")) && a.shape!="square");
var svg_style = ((a.mime.match("vector") || a.mime.match("shape")) && a.style.shape!="square");
if (!svg_style) {
if (a.stroke) {
styles.push("border-width:"+a.stroke+"px");
styles.push("border-style:"+(a.stroke_style||"solid"));
if (a.style.stroke) {
styles.push("border-width:"+a.style.stroke+"px");
styles.push("border-style:"+(a.style.stroke_style||"solid"));
}
if (a.stroke_color) {
styles.push("border-color:"+a.stroke_color);
if (a.style.stroke_color) {
styles.push("border-color:"+a.style.stroke_color);
}
if (a.border_radius) {
styles.push("border-radius:"+a.border_radius+"px");
if (a.style.border_radius) {
styles.push("border-radius:"+a.style.border_radius+"px");
}
}
if (a.fill_color && !svg_style) {
styles.push("background-color:"+a.fill_color);
if (a.style.fill_color && !svg_style) {
styles.push("background-color:"+a.style.fill_color);
}
if (a.text_color) {
styles.push("color:"+a.text_color);
if (a.style.text_color) {
styles.push("color:"+a.style.text_color);
}
var filters = [];
if (!isNaN(a.brightness) && a.brightness != 100) {
filters.push("brightness("+a.brightness+"%)");
if (!isNaN(a.style.brightness) && a.style.brightness != 100) {
filters.push("brightness("+a.style.brightness+"%)");
}
if (!isNaN(a.contrast) && a.contrast != 100) {
filters.push("contrast("+a.contrast+"%)");
if (!isNaN(a.style.contrast) && a.style.contrast != 100) {
filters.push("contrast("+a.style.contrast+"%)");
}
if (!isNaN(a.opacity) && a.opacity != 100) {
filters.push("opacity("+a.opacity+"%)");
if (!isNaN(a.style.opacity) && a.style.opacity != 100) {
filters.push("opacity("+a.style.opacity+"%)");
}
if (!isNaN(a.hue) && a.hue) {
filters.push("hue-rotate("+a.hue+"deg)");
if (!isNaN(a.style.hue) && a.style.hue) {
filters.push("hue-rotate("+a.style.hue+"deg)");
}
if (!isNaN(a.saturation) && a.saturation != 100) {
filters.push("saturate("+a.saturation+"%)");
if (!isNaN(a.style.saturation) && a.style.saturation != 100) {
filters.push("saturate("+a.style.saturation+"%)");
}
if (!isNaN(a.blur) && a.blur) {
filters.push("blur("+a.blur+"px)");
if (!isNaN(a.style.blur) && a.style.blur) {
filters.push("blur("+a.style.blur+"px)");
}
if (filters.length) {
styles.push("-webkit-filter:"+filters.join(" "));
styles.push("filter:"+filters.join(" "));
}
//}
}
return styles.join(";");
},
@@ -179,10 +180,12 @@ var SpacedeckBoardArtifacts = {
artifact_text_cell_style: function(a, for_text_editor) {
var styles = [];
if (a.padding_left) styles.push("padding-left:"+a.padding_left+"px");
if (a.padding_right) styles.push("padding-right:"+a.padding_right+"px");
if (a.padding_top) styles.push("padding-top:"+a.padding_top+"px");
if (a.padding_bottom) styles.push("padding-bottom:"+a.padding_bottom+"px");
if (a.style) {
if (a.style.padding_left) styles.push("padding-left:"+a.style.padding_left+"px");
if (a.style.padding_right) styles.push("padding-right:"+a.style.padding_right+"px");
if (a.style.padding_top) styles.push("padding-top:"+a.style.padding_top+"px");
if (a.style.padding_bottom) styles.push("padding-bottom:"+a.style.padding_bottom+"px");
}
return styles.join(";");
},
@@ -191,22 +194,26 @@ var SpacedeckBoardArtifacts = {
var styles = [];
var z = 0;
z = a.z;
if (z<0) z=0; // fix negative z-index
styles = [
"left:" +a.x+"px",
"top:" +a.y+"px",
"width:" +a.w+"px",
"height:"+a.h+"px",
"z-index:"+z
];
if (a.board) {
z = a.board.z;
if (z<0) z=0; // fix negative z-index
styles = [
"left:" +a.board.x+"px",
"top:" +a.board.y+"px",
"width:" +a.board.w+"px",
"height:"+a.board.h+"px",
"z-index:"+z
];
}
if (a.style) {
if (a.style.margin_left) styles.push("margin-left:"+a.style.margin_left+"px");
if (a.style.margin_right) styles.push("margin-right:"+a.style.margin_right+"px");
if (a.style.margin_top) styles.push("margin-top:"+a.style.margin_top+"px");
if (a.style.margin_bottom) styles.push("margin-bottom:"+a.style.margin_bottom+"px");
}
if (a.margin_left) styles.push("margin-left:"+a.margin_left+"px");
if (a.margin_right) styles.push("margin-right:"+a.margin_right+"px");
if (a.margin_top) styles.push("margin-top:"+a.margin_top+"px");
if (a.margin_bottom) styles.push("margin-bottom:"+a.margin_bottom+"px");
// FIXME: via class logic?
if (a.mime.match("vector")) {
styles.push("overflow:visible");
@@ -234,7 +241,7 @@ var SpacedeckBoardArtifacts = {
artifact_thumbnail_uri: function(a) {
if (a.payload_thumbnail_big_uri && a.board) {
if (a.w>800) {
if (a.board.w>800) {
return a.payload_thumbnail_big_uri;
}
}
@@ -248,35 +255,35 @@ var SpacedeckBoardArtifacts = {
var type = parts[0];
var provider = parts[1];
if (!a.link_uri) {
if (!a.meta || !a.meta.link_uri) {
console.log("missing meta / link_uri: ",a);
console.log("type/provider: ",type,provider);
return ("missing metadata: "+a._id);
}
if (provider=="youtube") {
var vid = a.link_uri.match(/(v=|\/)([a-zA-Z0-9\-_]{11})/);
var vid = a.meta.link_uri.match(/(v=|\/)([a-zA-Z0-9\-_]{11})/);
if (vid && vid.length>2) {
var uri = "https://youtube.com/embed/"+vid[2];
return "<iframe frameborder=0 allowfullscreen src=\""+uri+"?showinfo=0&rel=0&controls=0\"></iframe>";
} else return "Can't resolve: "+a.payload_uri;
} else if (provider=="dailymotion") {
var match = a.link_uri.match(/dailymotion.com\/video\/([^<]*)/);
var match = a.meta.link_uri.match(/dailymotion.com\/video\/([^<]*)/);
if (match && match.length>1) {
var uri = "https://www.dailymotion.com/embed/video/"+match[1];
return "<iframe frameborder=0 allowfullscreen src=\""+uri+"\"></iframe>";
} else return "Can't resolve: "+a.payload_uri;
} else if (provider=="vimeo") {
var match = a.link_uri.match(/https?:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/);
var match = a.meta.link_uri.match(/https?:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/);
if (match) {
var uri = "https://player.vimeo.com/video/"+match[2];
return "<iframe frameborder=0 allowfullscreen src=\""+uri+"\"></iframe>";
} else return "Can't resolve: "+a.payload_uri;
} else if (provider=="soundcloud") {
return '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url='+a.link_uri.replace(":", "%3A")+'"></iframe>';
return '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url='+a.meta.link_uri.replace(":", "%3A")+'"></iframe>';
} else if (provider=="spacedeck") {
@@ -292,8 +299,8 @@ var SpacedeckBoardArtifacts = {
if (mtype != "vector" && mtype != "shape") return "";
var shape = a.shape || "";
var padding = 32 + a.stroke*2;
var shape = a.style.shape || "";
var padding = 32 + a.style.stroke*2;
var path_svg;
var fill = "";
@@ -303,13 +310,13 @@ var SpacedeckBoardArtifacts = {
fill = "fill:none";
} else {
path_svg = render_vector_shape(a, padding);
fill = "fill:"+a.fill_color+";";
fill = "fill:"+a.style.fill_color+";";
padding = 0;
}
var margin = padding;
var svg = "<svg xmlns='http://www.w3.org/2000/svg' width='"+(a.w+2*padding)+"' height='"+(a.h+2*padding)+"' ";
svg += "style='margin-left:"+(-margin)+"px;margin-top:"+(-margin)+"px;stroke-width:"+a.stroke+";stroke:"+a.stroke_color+";"+fill+"'>";
var svg = "<svg xmlns='http://www.w3.org/2000/svg' width='"+(a.board.w+2*padding)+"' height='"+(a.board.h+2*padding)+"' ";
svg += "style='margin-left:"+(-margin)+"px;margin-top:"+(-margin)+"px;stroke-width:"+a.style.stroke+";stroke:"+a.style.stroke_color+";"+fill+"'>";
svg += path_svg;
svg += "</svg>";
@@ -322,10 +329,10 @@ var SpacedeckBoardArtifacts = {
if (arts.length==0) return null;
r = {
x1: parseInt(_.min(arts.map(function(a){return a.x}))),
y1: parseInt(_.min(arts.map(function(a){return a.y}))),
x2: parseInt(_.max(arts.map(function(a){return a.x+a.w}))),
y2: parseInt(_.max(arts.map(function(a){return a.y+a.h})))
x1: parseInt(_.min(arts.map(function(a){return a.board.x}))),
y1: parseInt(_.min(arts.map(function(a){return a.board.y}))),
x2: parseInt(_.max(arts.map(function(a){return a.board.x+a.board.w}))),
y2: parseInt(_.max(arts.map(function(a){return a.board.y+a.board.h})))
};
r.x=r.x1;
r.y=r.y1;
@@ -349,7 +356,7 @@ var SpacedeckBoardArtifacts = {
artifacts_in_rect: function(rect) {
return _.filter(this.active_space_artifacts, function(a) {
return this.rects_intersecting(a, rect);
return this.rects_intersecting(a.board, rect);
}.bind(this));
},
@@ -359,15 +366,15 @@ var SpacedeckBoardArtifacts = {
var rect = this.artifact_selection_rect();
var overlapping = _.filter(this.artifacts_in_rect(rect), function(a){return !this.is_selected(a)}.bind(this));
var max_z = _.max(overlapping,function(a){ return a.z; });
var max_z = _.max(overlapping,function(a){ return a.board.z; });
if (max_z.board) {
max_z = max_z.z + 1;
max_z = max_z.board.z + 1;
} else {
max_z = 1;
}
this.update_selected_artifacts(function(a) {
return { z: max_z };
return { board: _.extend(a.board, { z: max_z }) };
});
},
@@ -377,15 +384,15 @@ var SpacedeckBoardArtifacts = {
var rect = this.artifact_selection_rect();
var overlapping = _.filter(this.artifacts_in_rect(rect), function(a){return !this.is_selected(a);}.bind(this));
var min_z = _.min(overlapping,function(a){ return a.z; });
var min_z = _.min(overlapping,function(a){ return (a.board?a.board.z:0); });
if (min_z.board) {
min_z = min_z.z - 1;
min_z = min_z.board.z - 1;
} else {
min_z = 0;
}
var my_z = _.max(this.selected_artifacts(),function(a){ return a.z; });
var my_z = _.max(this.selected_artifacts(),function(a){ (a.board?a.board.z:0); });
if (my_z.board) {
my_z = my_z.z - 1;
my_z = my_z.board.z - 1;
} else {
my_z = 0;
}
@@ -393,14 +400,14 @@ var SpacedeckBoardArtifacts = {
// TODO: move all other items up in this case?
if (min_z < 0) {
this.update_artifacts(overlapping, function(a) {
return { z: (my_z + a.z + 1) };
return { board: _.extend(a.board, { z: (my_z + (a.board?a.board.z:0) + 1) }) };
});
return;
}
this.update_selected_artifacts(function(a) {
return { z: min_z };
return { board: _.extend(a.board, { z: min_z }) };
});
},
@@ -409,7 +416,7 @@ var SpacedeckBoardArtifacts = {
var rect = this.artifact_selection_rect();
this.update_selected_artifacts(function(a) {
return { x: rect.x1 };
return { board: _.extend(a.board, { x: rect.x1 }) };
});
},
@@ -418,7 +425,7 @@ var SpacedeckBoardArtifacts = {
var rect = this.artifact_selection_rect();
this.update_selected_artifacts(function(a) {
return { y: rect.y1 };
return { board: _.extend(a.board, { y: rect.y1 }) };
});
},
@@ -427,7 +434,7 @@ var SpacedeckBoardArtifacts = {
var rect = this.artifact_selection_rect();
this.update_selected_artifacts(function(a) {
return { x: rect.x2 - a.w };
return { board: _.extend(a.board, { x: rect.x2 - a.board.w }) };
});
},
@@ -436,7 +443,7 @@ var SpacedeckBoardArtifacts = {
var rect = this.artifact_selection_rect();
this.update_selected_artifacts(function(a) {
return { y: rect.y2 - a.h };
return { board: _.extend(a.board, { y: rect.y2 - a.board.h }) };
});
},
@@ -446,7 +453,7 @@ var SpacedeckBoardArtifacts = {
var rect = this.artifact_selection_rect();
var cx = rect.x1 + (rect.x2-rect.x1)/2;
this.update_selected_artifacts(function(a) {
return { x: cx - a.w/2 };
return { board: _.extend(a.board, { x: cx - a.board.w/2 }) };
});
},
@@ -456,7 +463,7 @@ var SpacedeckBoardArtifacts = {
var rect = this.artifact_selection_rect();
var cy = rect.y1 + (rect.y2-rect.y1)/2;
this.update_selected_artifacts(function(a) {
return { y: cy - a.h/2 };
return { board: _.extend(a.board, { y: cy - a.board.h/2 }) };
});
},
@@ -466,11 +473,11 @@ var SpacedeckBoardArtifacts = {
var arts = this.selected_artifacts();
if (arts.length<2) return;
var totalw = _.reduce(arts, function(sum, a) { return sum + a.w }, 0);
var totalw = _.reduce(arts, function(sum, a) { return sum + a.board.w }, 0);
var avgw = totalw / arts.length;
this.update_selected_artifacts(function(a) {
return { w: avgw };
return { board: _.extend(a.board, { w: avgw }) };
});
},
@@ -480,11 +487,11 @@ var SpacedeckBoardArtifacts = {
var arts = this.selected_artifacts();
if (arts.length<2) return;
var totalh = _.reduce(arts, function(sum, a) { return sum + a.h }, 0);
var totalh = _.reduce(arts, function(sum, a) { return sum + a.board.h }, 0);
var avgh = totalh / arts.length;
this.update_selected_artifacts(function(a) {
return { h: avgh };
return { board: _.extend(a.board, { h: avgh }) };
});
},
@@ -499,16 +506,16 @@ var SpacedeckBoardArtifacts = {
var selected = this.selected_artifacts();
if (selected.length<3) return;
var sorted = _.sortBy(selected, function(a) { return a.x });
var startx = sorted[0].x + sorted[0].w/2;
var stopx = _.last(sorted).x + _.last(sorted).w/2;
var sorted = _.sortBy(selected, function(a) { return a.board.x });
var startx = sorted[0].board.x + sorted[0].board.w/2;
var stopx = _.last(sorted).board.x + _.last(sorted).board.w/2;
var step = (stopx-startx)/(sorted.length-1);
for (var i=1; i<sorted.length-1; i++) {
var a = sorted[i];
var x = startx + step*i - a.w/2;
var x = startx + step*i - a.board.w/2;
this.update_artifacts([a],function(a) {
return { x: x }
return { board: _.extend(a.board, {x: x}) }
});
}
},
@@ -519,16 +526,16 @@ var SpacedeckBoardArtifacts = {
var selected = this.selected_artifacts();
if (selected.length<3) return;
var sorted = _.sortBy(selected, function(a) { return a.y });
var starty = sorted[0].y + sorted[0].h/2;
var stopy = _.last(sorted).y + _.last(sorted).h/2;
var sorted = _.sortBy(selected, function(a) { return a.board.y });
var starty = sorted[0].board.y + sorted[0].board.h/2;
var stopy = _.last(sorted).board.y + _.last(sorted).board.h/2;
var step = (stopy-starty)/(sorted.length-1);
for (var i=1; i<sorted.length-1; i++) {
var a = sorted[i];
var y = starty + step*i - a.h/2;
var y = starty + step*i - a.board.h/2;
this.update_artifacts([a],function(a) {
return { y: y }
return { board: _.extend(a.board, {y: y}) }
});
}
},
@@ -539,21 +546,21 @@ var SpacedeckBoardArtifacts = {
var selected = this.selected_artifacts();
if (selected.length<3) return;
var sorted = _.sortBy(selected, function(a) { return a.x });
var startx = sorted[0].x;
var stopx = _.last(sorted).x + _.last(sorted).w;
var sorted = _.sortBy(selected, function(a) { return a.board.x });
var startx = sorted[0].board.x;
var stopx = _.last(sorted).board.x + _.last(sorted).board.w;
var range = stopx - startx;
var totalw = _.reduce(sorted, function(sum, a) { return sum + a.w }, 0);
var totalw = _.reduce(sorted, function(sum, a) { return sum + a.board.w }, 0);
var avgs = (range - totalw) / (sorted.length-1);
var prevend = startx + sorted[0].w;
var prevend = startx + sorted[0].board.w;
for (var i=1; i<sorted.length-1; i++) {
var a = sorted[i];
var x = prevend + avgs;
this.update_artifacts([a],function(a) {
return { x: x }
return { board: _.extend(a.board, {x: x}) }
});
prevend = x+a.w;
prevend = x+a.board.w;
}
},
@@ -563,21 +570,21 @@ var SpacedeckBoardArtifacts = {
var selected = this.selected_artifacts();
if (selected.length<3) return;
var sorted = _.sortBy(selected, function(a) { return a.y });
var starty = sorted[0].y;
var stopy = _.last(sorted).y + _.last(sorted).h;
var sorted = _.sortBy(selected, function(a) { return a.board.y });
var starty = sorted[0].board.y;
var stopy = _.last(sorted).board.y + _.last(sorted).board.h;
var range = stopy - starty;
var totalh = _.reduce(sorted, function(sum, a) { return sum + a.h }, 0);
var totalh = _.reduce(sorted, function(sum, a) { return sum + a.board.h }, 0);
var avgs = (range - totalh) / (sorted.length-1);
var prevend = starty + sorted[0].h;
var prevend = starty + sorted[0].board.h;
for (var i=1; i<sorted.length-1; i++) {
var a = sorted[i];
var y = prevend + avgs;
this.update_artifacts([a],function(a) {
return { y: y }
return { board: _.extend(a.board, {y: y}) }
});
prevend = y+a.h;
prevend = y+a.board.h;
}
},
@@ -587,22 +594,20 @@ var SpacedeckBoardArtifacts = {
var selected = this.selected_artifacts();
if (selected.length<2) return;
var sorted = _.sortBy(selected, function(a) { return a.x+a.y*this.active_space.width }.bind(this));
var sorted = _.sortBy(selected, function(a) { return a.board.x+a.board.y*this.active_space.advanced.width }.bind(this));
var minx = sorted[0].x;
var miny = sorted[0].y;
var minx = sorted[0].board.x;
var miny = sorted[0].board.y;
var sorted = _.sortBy(selected, function(a) { return -Math.max(a.w,a.h) }.bind(this));
var sorted = _.sortBy(selected, function(a) { return -Math.max(a.board.w,a.board.h) }.bind(this));
var blocks = [];
var padding = 10;
for (var i=0; i<sorted.length; i++) {
var a = sorted[i];
blocks.push({
w: a.w+padding,
h: a.h+padding,
w: a.board.w,
h: a.board.h,
a: a
});
}
@@ -615,10 +620,10 @@ var SpacedeckBoardArtifacts = {
if (block.fit) {
var a = block.a;
this.update_artifacts([a],function(a) {
return {
return { board: _.extend(a.board, {
x: minx+block.fit.x,
y: miny+block.fit.y
}
}) }
});
}
}

View File

@@ -170,6 +170,7 @@ var SpacedeckRoutes = {
location.href = "/";
} else {
this.active_view = "account";
this.load_subscription();
}
}.bind(this)
}
@@ -252,6 +253,8 @@ var SpacedeckRoutes = {
// #hash
if (event.currentTarget.hash && event.currentTarget.hash.length>1) return;
console.log("clicked", event.currentTarget.pathname);
// external link?
if (event.currentTarget.host != location.host) return;
@@ -267,6 +270,35 @@ var SpacedeckRoutes = {
event.preventDefault();
}.bind(this));
if (location.host!=ENV.webHost) {
if (!subdomainTeam) {
location.href = ENV.webEndpoint;
return;
} else {
if(subdomainTeam.subdomain) {
var realHost = (subdomainTeam.subdomain + "." + ENV.webHost);
if (location.host != realHost) {
location.href = realHost;
return;
}
} else {
location.href = ENV.webEndpoint;
return;
}
}
}
if (this.logged_in) {
if (this.user.team) {
if (this.user.team.subdomain && this.user.team.subdomain.length > 0) {
var realHost = (this.user.team.subdomain + "." + ENV.webHost);
if (location.host != realHost) {
location.href = location.protocol + "//" + realHost + location.pathname;
return;
}
}
}
}
this.internal_route(location.pathname);
},

View File

@@ -369,8 +369,8 @@ var SpacedeckSections = {
// canvas
this.$watch('active_style.background_color', function (value, mutation) {
if (this.active_style.background_color != this.active_space.background_color) {
this.$set("active_space.background_color",this.active_style.background_color);
if (this.active_style.background_color != this.active_space.advanced.background_color) {
this.$set("active_space.advanced.background_color",this.active_style.background_color);
this.throttled_save_active_space();
}
@@ -448,7 +448,7 @@ var SpacedeckSections = {
for (var i=0; i<props.length; i++) {
var prop = props[i];
this.active_style[prop]=a[prop];
this.active_style[prop]=a.style[prop];
}
// defaults
@@ -457,10 +457,10 @@ var SpacedeckSections = {
this.active_style.line_height = this.default_style.line_height;
this.active_style.letter_spacing = this.default_style.letter_spacing;
this.active_style.padding_top = a.padding_top || 0;
this.active_style.padding_bottom = a.padding_bottom || 0;
this.active_style.padding_left = a.padding_left || 0;
this.active_style.padding_right = a.padding_right || 0;
this.active_style.padding_top = a.style.padding_top || 0;
this.active_style.padding_bottom = a.style.padding_bottom || 0;
this.active_style.padding_left = a.style.padding_left || 0;
this.active_style.padding_right = a.style.padding_right || 0;
if (this.active_style.padding_top == this.active_style.padding_bottom) {
this.active_style.padding_vert = this.active_style.padding_top;
@@ -476,10 +476,10 @@ var SpacedeckSections = {
this.active_style.padding = this.active_style.padding_top;
}
this.active_style.margin_top = a.margin_top || 0;
this.active_style.margin_bottom = a.margin_bottom || 0;
this.active_style.margin_left = a.margin_left || 0;
this.active_style.margin_right = a.margin_right || 0;
this.active_style.margin_top = a.style.margin_top || 0;
this.active_style.margin_bottom = a.style.margin_bottom || 0;
this.active_style.margin_left = a.style.margin_left || 0;
this.active_style.margin_right = a.style.margin_right || 0;
if (this.active_style.margin_top == this.active_style.margin_bottom) {
this.active_style.margin_vert = this.active_style.margin_top;
@@ -758,8 +758,8 @@ var SpacedeckSections = {
},
resize_minimap: function() {
if (!this.active_space) return;
this.minimap_scale = this.active_space.width/100.0;
if (!this.active_space || !this.active_space.advanced) return;
this.minimap_scale = this.active_space.advanced.width/100.0;
},
handle_minimap_mouseup: function(evt) {
@@ -921,7 +921,7 @@ var SpacedeckSections = {
discover_zones: function() {
this.zones = _.sortBy(_.filter(this.active_space_artifacts, function(a) { return (a.mime=="x-spacedeck/zone") }),
function(z){return z.order});
function(z){return z.style.order});
},
artifact_plaintext: function(a) {
@@ -1015,10 +1015,10 @@ var SpacedeckSections = {
arts = _.filter(arts); // remove any nulls
return {
x1: parseInt(_.min(arts.map(function(a){return ((!a || !a.x)?0:a.x)}))),
y1: parseInt(_.min(arts.map(function(a){return ((!a || !a.y)?0:a.y)}))),
x2: parseInt(_.max(arts.map(function(a){return (!a?0:a.x+a.w)}))),
y2: parseInt(_.max(arts.map(function(a){return (!a?0:a.y+a.h)})))
x1: parseInt(_.min(arts.map(function(a){return ((!a.board || !a.board.x)?0:a.board.x)}))),
y1: parseInt(_.min(arts.map(function(a){return ((!a.board || !a.board.y)?0:a.board.y)}))),
x2: parseInt(_.max(arts.map(function(a){return (!a.board?0:a.board.x+a.board.w)}))),
y2: parseInt(_.max(arts.map(function(a){return (!a.board?0:a.board.y+a.board.h)})))
};
},
@@ -1076,7 +1076,7 @@ var SpacedeckSections = {
this.selection_metrics.count=arts.length;
this.selection_metrics.scribble_selection = false;
if (arts.length == 1 && arts[0].mime == "x-spacedeck/vector") {
if (arts[0].shape == "scribble") {
if (arts[0].style.shape == "scribble") {
this.selection_metrics.scribble_selection = true;
}
this.selection_metrics.vector_points = arts[0].control_points;
@@ -1112,8 +1112,8 @@ var SpacedeckSections = {
fixup_space_size: function() {
if (!this.active_space) return;
this.active_space.width =Math.max(this.active_space.width, window.innerWidth);
this.active_space.height=Math.max(this.active_space.height, window.innerHeight);
this.active_space.advanced.width =Math.max(this.active_space.advanced.width, window.innerWidth);
this.active_space.advanced.height=Math.max(this.active_space.advanced.height, window.innerHeight);
},
end_transaction: function() {
@@ -1125,13 +1125,13 @@ var SpacedeckSections = {
var er = this.enclosing_rect(this.active_space_artifacts);
if (!er) return;
this.active_space.width =Math.max(er.x2+100, window.innerWidth);
this.active_space.height=Math.max(er.y2+100, window.innerHeight);
this.active_space.advanced.width =Math.max(er.x2+100, window.innerWidth);
this.active_space.advanced.height=Math.max(er.y2+100, window.innerHeight);
if (this._last_bounds_width != this.active_space.width ||
this._last_bounds_height != this.active_space.height) {
this._last_bounds_width = this.active_space.width;
this._last_bounds_height = this.active_space.height;
if (this._last_bounds_width != this.active_space.advanced.width ||
this._last_bounds_height != this.active_space.advanced.height) {
this._last_bounds_width = this.active_space.advanced.width;
this._last_bounds_height = this.active_space.advanced.height;
save_space(this.active_space);
}
@@ -1214,7 +1214,7 @@ var SpacedeckSections = {
// this is a bit hacky, but might be the smartest place to do it
if (a.view && a.view.vector_svg) {
a.shape_svg = a.view.vector_svg;
a.style.shape_svg = a.view.vector_svg;
}
window.artifact_save_queue[a._id] = a;
@@ -1329,7 +1329,7 @@ var SpacedeckSections = {
this.update_selected_artifacts(function(a) {
var c = {};
if (a[prop] != val) {
if (c[prop] != val) {
//console.log("set_artifact_prop: ",c,val);
c[prop]=val;
return c;
@@ -1343,11 +1343,11 @@ var SpacedeckSections = {
this.begin_transaction();
this.update_selected_artifacts(function(a) {
var c = {};
if (a[prop] != val) {
var c = {style: a.style||{}};
if (c.style[prop] != val) {
//console.log("set_artifact_style_prop: ",c,val);
c[prop]=val;
c.style[prop]=val;
return c;
}
@@ -1419,7 +1419,7 @@ var SpacedeckSections = {
if (this.selected_artifacts().length!=1 && this.opened_dialog!="background") return;
if (this.opened_dialog=="background") {
this.active_style[this.color_picker_target] = this.active_space.background_color;
this.active_style[this.color_picker_target] = this.active_space.advanced.background_color;
} else {
if (!this.active_style[this.color_picker_target]) {
this.active_style[this.color_picker_target] = this.default_style[this.color_picker_target];
@@ -1478,8 +1478,10 @@ var SpacedeckSections = {
this.update_selected_artifacts(function(a) {
return {
x: a.x+dx,
y: a.y+dy
board: _.extend(a.board, {
x: a.board.x+dx,
y: a.board.y+dy
})
};
});
},
@@ -1487,7 +1489,7 @@ var SpacedeckSections = {
/* -------------------------------------------------------------------- */
highest_z: function() {
var z = _.max(this.active_space_artifacts.map(function(a){return a.z||0}));
var z = _.max(this.active_space_artifacts.map(function(a){return a.board.z||0}));
if (z<0) z=0;
if (z>999) z=999;
return z;
@@ -1572,18 +1574,20 @@ var SpacedeckSections = {
payload_thumbnail_web_uri: url || null,
space_id: space._id,
order: this.active_space_artifacts.length+1,
valign: "middle",
align: "center"
//fill_color: "#f8f8f8"
style: {
order: this.active_space_artifacts.length+1,
valign: "middle",
align: "center"
//fill_color: "#f8f8f8"
}
};
if (mimes[item_type] == "text/html") {
new_item.padding_left = 10;
new_item.padding_top = 10;
new_item.padding_right = 10;
new_item.padding_bottom = 10;
new_item.fill_color = "rgba(255,255,255,1)";
new_item.style.padding_left = 10;
new_item.style.padding_top = 10;
new_item.style.padding_right = 10;
new_item.style.padding_bottom = 10;
new_item.style.fill_color = "rgba(255,255,255,1)";
new_item.description = "<p>Text</p>";
}
@@ -1596,11 +1600,13 @@ var SpacedeckSections = {
z = point.z;
}
new_item.x = parseInt(point.x);
new_item.y = parseInt(point.y);
new_item.z = z;
new_item.w = w;
new_item.h = h;
new_item.board = {
x: parseInt(point.x),
y: parseInt(point.y),
w: w,
h: h,
z: z
};
if (this.guest_nickname) {
new_item.editor_name = this.guest_nickname;
@@ -1659,7 +1665,7 @@ var SpacedeckSections = {
for (var i=0; i<new_zones.length; i++) {
if (new_zones[i]) {
if (!new_zones[i].style) new_zones[i].style = {};
new_zones[i].order = i;
new_zones[i].style.order = i;
save_artifact(new_zones[i]);
}
}
@@ -1673,7 +1679,7 @@ var SpacedeckSections = {
for (var i=0; i<new_zones.length; i++) {
if (new_zones[i]) {
if (!new_zones[i].style) new_zones[i].style = {};
new_zones[i].order = i;
new_zones[i].style.order = i;
save_artifact(new_zones[i]);
}
}
@@ -1689,13 +1695,17 @@ var SpacedeckSections = {
space_id: this.active_space._id,
mime: "x-spacedeck/zone",
description: "Zone "+(this.zones.length+1),
x: point.x,
y: point.y,
w: w,
h: h,
z: 0,
valign: "middle",
align: "center"
board: {
x: point.x,
y: point.y,
w: w,
h: h,
z: 0
},
style: {
valign: "middle",
align: "center"
}
};
if (this.guest_nickname) {
@@ -1725,18 +1735,22 @@ var SpacedeckSections = {
space_id: this.active_space._id,
mime: "x-spacedeck/shape",
description: "Text",
x: point.x,
y: point.y,
z: point.z,
w: w,
h: h,
stroke_color: "#ffffff",
text_color: "#ffffff",
stroke: 0,
fill_color: "#000000",
shape: shape_type,
valign: "middle",
align: "center"
board: {
x: point.x,
y: point.y,
z: point.z,
w: w,
h: h
},
style: {
stroke_color: "#ffffff",
text_color: "#ffffff",
stroke: 0,
fill_color: "#000000",
shape: shape_type,
valign: "middle",
align: "center"
}
};
if (this.guest_nickname) {
@@ -1815,13 +1829,17 @@ var SpacedeckSections = {
state: "uploading",
payload_thumbnail_medium_uri: null,
payload_thumbnail_web_uri: null,
x: point.x,
y: point.y,
w: w,
h: h,
z: point.z,
order: this.active_space_artifacts.length+1,
fill_color: fill
board: {
x: point.x,
y: point.y,
w: w,
h: h,
z: point.z
},
style: {
order: this.active_space_artifacts.length+1,
fill_color: fill
}
}
this.update_board_artifact_viewmodel(a);
@@ -1846,11 +1864,7 @@ var SpacedeckSections = {
a.payload_thumbnail_big_uri = updated_a.payload_thumbnail_big_uri;
a.payload_alternatives = updated_a.payload_alternatives;
a.mime = updated_a.mime;
a.x = updated_a.x;
a.y = updated_a.y;
a.w = updated_a.w;
a.h = updated_a.h;
a.z = updated_a.z;
a.board = updated_a.board;
a.state = updated_a.state;
this.update_board_artifact_viewmodel(a);
@@ -1988,26 +2002,26 @@ var SpacedeckSections = {
clear_formatting_walk: function(el,cmd,arg1,arg2) {
if (el && el.style) {
if (cmd == "preciseFontSize") {
el.fontSize = null;
el.style.fontSize = null;
} else if (cmd == "letterSpacing") {
el.letterSpacing = null;
el.style.letterSpacing = null;
} else if (cmd == "lineHeight") {
el.lineHeight = null;
el.style.lineHeight = null;
} else if (cmd == "fontName") {
el.fontFamily = null;
el.style.fontFamily = null;
} else if (cmd == "fontWeight") {
el.fontWeight = null;
el.fontStyle = null;
el.style.fontWeight = null;
el.style.fontStyle = null;
} else if (cmd == "bold") {
el.fontWeight = null;
el.style.fontWeight = null;
} else if (cmd == "italic") {
el.fontStyle = null;
el.style.fontStyle = null;
} else if (cmd == "underline") {
el.textDecoration = null;
el.style.textDecoration = null;
} else if (cmd == "strikeThrough") {
el.textDecoration = null;
el.style.textDecoration = null;
} else if (cmd == "forecolor") {
el.color = null;
el.style.color = null;
}
}
@@ -2094,9 +2108,6 @@ var SpacedeckSections = {
if (a.description!=dom.innerHTML) {
a.description = dom.innerHTML;
console.log("new DOM:",dom.innerHTML);
this.update_board_artifact_viewmodel(a);
this.queue_artifact_for_save(a);
@@ -2130,7 +2141,10 @@ var SpacedeckSections = {
remove_link_from_selected_artifacts: function() {
this.update_selected_artifacts(function(a) {
return {link_uri: ""};
var meta = a.meta || {};
delete meta.link_uri;
return {meta: meta};
});
},
@@ -2146,7 +2160,9 @@ var SpacedeckSections = {
var insert_link_url = prompt("URL:",def);
this.update_selected_artifacts(function(a) {
var update = {link_uri: insert_link_url};
var meta = a.meta || {};
meta.link_uri = insert_link_url;
var update = {meta: meta};
if (a.payload_uri && a.payload_uri.match("webgrabber")) {
var enc_uri = encodeURIComponent(btoa(insert_link_url));
@@ -2169,10 +2185,11 @@ var SpacedeckSections = {
delete copy["$index"];
delete copy["_id"];
if (dx) copy.x += dx;
if (dy) copy.y += dy;
if (dx) copy.board.x += dx;
if (dy) copy.board.y += dy;
copy.order = this.active_space_artifacts.length+1;
if (!copy.style) copy.style = {};
copy.style.order = this.active_space_artifacts.length+1;
if (this.guest_nickname) {
copy.editor_name = this.guest_nickname;
@@ -2317,16 +2334,16 @@ var SpacedeckSections = {
if (parsed[i].mime) {
var z = this.highest_z()+1;
if (parsed.length==1) {
var w = parsed[i].w;
var h = parsed[i].h;
var w = parsed[i].board.w;
var h = parsed[i].board.h;
var point = this.find_place_for_item(w,h);
parsed[i].x = point.x;
parsed[i].y = point.y;
parsed[i].z = point.z;
parsed[i].board.x = point.x;
parsed[i].board.y = point.y;
parsed[i].board.z = point.z;
} else {
parsed[i].x = parsed[i].x+50;
parsed[i].y = parsed[i].y+50;
parsed[i].y = parsed[i].z+z;
parsed[i].board.x = parsed[i].board.x+50;
parsed[i].board.y = parsed[i].board.y+50;
parsed[i].board.y = parsed[i].board.z+z;
}
this.clone_artifact(parsed[i], 0,0, function(a) {
this.multi_select([a]);
@@ -2356,11 +2373,13 @@ var SpacedeckSections = {
var h = 300;
var point = this.find_place_for_item(w,h);
new_item.x = point.x;
new_item.y = point.y;
new_item.w = w;
new_item.h = h;
new_item.z = point.z;
new_item.board = {
x: point.x,
y: point.y,
w: w,
h: h,
z: point.z
};
if (this.guest_nickname) {
new_item.editor_name = this.guest_nickname;
@@ -2383,12 +2402,16 @@ var SpacedeckSections = {
mime: "image/png",
description: url,
state: "uploading",
x: point.x,
y: point.y,
w: 200,
h: 200,
z: z,
order: this.active_space_artifacts.length
board: {
x: point.x,
y: point.y,
w: 200,
h: 200,
z: z
},
style: {
order: this.active_space_artifacts.length
}
}
var metadata = parse_link(url)
@@ -2450,12 +2473,16 @@ var SpacedeckSections = {
payload_thumbnail_medium_uri: metadata.thumbnail_url,
payload_thumbnail_web_uri: metadata.thumbnail_url,
state: "idle",
title: metadata.title,
link_uri: metadata.url || url,
x: point.x - w/2,
y: point.y - h/2,
w: w,
h: h
meta: {
title: metadata.title,
link_uri: metadata.url || url
},
board: {
x: point.x - w/2,
y: point.y - h/2,
w: w,
h: h
}
});
if (this.guest_nickname) {
@@ -2564,7 +2591,7 @@ var SpacedeckSections = {
},
remove_section_background: function() {
this.active_space.background_uri = null;
this.active_space.advanced.background_uri = null;
save_space(this.active_space);
},
@@ -2625,8 +2652,8 @@ var SpacedeckSections = {
this.bounds_zoom = this.viewport_zoom;
var eff_w = this.active_space.width*this.viewport_zoom;
var eff_h = this.active_space.height*this.viewport_zoom;
var eff_w = this.active_space.advanced.width*this.viewport_zoom;
var eff_h = this.active_space.advanced.height*this.viewport_zoom;
if (window.innerWidth>eff_w) {
// horizontal centering
@@ -2819,8 +2846,8 @@ var SpacedeckSections = {
var el = $("#space")[0];
var eff_w = this.active_space.width*this.viewport_zoom;
var eff_h = this.active_space.height*this.viewport_zoom;
var eff_w = this.active_space.advanced.width*this.viewport_zoom;
var eff_h = this.active_space.advanced.height*this.viewport_zoom;
var sx = el.scrollLeft;
var sy = el.scrollTop;
@@ -2953,9 +2980,9 @@ var SpacedeckSections = {
var w = 300;
var h = 200;
if (parsed.board && parsed.w && parsed.h) {
w = parsed.w;
h = parsed.h;
if (parsed.board && parsed.board.w && parsed.board.h) {
w = parsed.board.w;
h = parsed.board.h;
}
var point = this.cursor_point_to_space(evt);

View File

@@ -71,7 +71,9 @@ var SpacedeckSpaces = {
methods: {
search_spaces: function() {
var query = this.folder_spaces_search;
console.log("search query: ",query);
load_spaces_search(query, function(spaces) {
console.log("results: ",spaces);
this.active_profile_spaces = spaces;
}.bind(this));
},
@@ -83,7 +85,14 @@ var SpacedeckSpaces = {
location.reload();
},
ask_guestname: function(dft, cb) {
smoke.prompt(__('what_is_your_name', "Spacedeck") , function(content) {
console.log("ask_guestname");
var team_name = "Spacedeck";
if(subdomainTeam) {
team_name = subdomainTeam.name;
}
smoke.prompt(__('what_is_your_name', team_name) , function(content) {
if (!content || (content.length === 0)) {
this.ask_guestname(dft, cb);
} else {
@@ -92,7 +101,7 @@ var SpacedeckSpaces = {
if ("localStorage" in window && localStorage) {
try {
localStorage['guest_nickname'] = this.guest_nickname;
} catch(e) {
}catch(e) {
console.error(e);
}
}
@@ -163,6 +172,7 @@ var SpacedeckSpaces = {
this.space_embed_html = "<iframe width=\"1024\" height=\"768\" seamless src=\""+ENV.webEndpoint+"/spaces/"+space._id+"?embedded=1\"></iframe>";
if (!is_home) {
//console.log(space);
load_members(space, function(members) {
this.active_space_memberships = members;
}.bind(this));
@@ -273,9 +283,9 @@ var SpacedeckSpaces = {
this.discover_zones();
//window.setTimeout(function() {
// this.zoom_to_fit();
//}.bind(this),10);
window.setTimeout(function() {
this.zoom_to_fit();
}.bind(this),10);
if (on_success) {
on_success();
@@ -626,14 +636,17 @@ var SpacedeckSpaces = {
download_space: function() {
smoke.quiz(__("download_space"), function(e, test) {
if (e == "PDF") {
if (e == "PDF"){
this.download_space_as_pdf(this.active_space);
} else if (e == "ZIP") {
}else if (e == "ZIP"){
this.download_space_as_zip(this.active_space);
}else if (e == "TXT"){
this.download_space_as_list(this.active_space);
}
}.bind(this), {
button_1: "PDF",
button_2: "ZIP",
button_3: "TXT",
button_cancel:__("cancel")
});

View File

@@ -15,8 +15,7 @@ SpacedeckUsers = {
account_remove_error: null,
loading_user: false,
password_reset_confirm_error: "",
password_reset_error: "",
password_reset_error: ""
},
methods:{
load_user: function(on_success, on_error) {
@@ -30,12 +29,6 @@ SpacedeckUsers = {
if (on_success) {
on_success(user);
}
// see spacedeck_account.js
load_importables(this.user, function(files) {
this.importables = files;
}.bind(this));
}.bind(this), function() {
// error
this.loading_user = false;
@@ -47,7 +40,23 @@ SpacedeckUsers = {
}.bind(this));
},
login_google: function(evt) {
this.loading_user = true;
create_oauthtoken(function(data){
this.loading_user = false;
location.href = data.url;
}, function(xhr){
this.loading_user = false;
alert("could not get oauth token");
});
},
finalize_login: function(session_token, on_success) {
if(!window.socket_auth || window.socket_auth == '' || window.socket_auth == 'null') {
window.socket_auth = session_token;
}
this.load_user(function(user) {
if (this.invitation_token) {
accept_invitation(this.invitation_token, function(memberships){
@@ -160,6 +169,7 @@ SpacedeckUsers = {
},
password_reset_submit: function(evt, email) {
if (evt) {
evt.preventDefault();
evt.stopPropagation();
@@ -193,6 +203,7 @@ SpacedeckUsers = {
},
password_reset_confirm: function(evt, password, password_confirmation) {
if (evt) {
evt.preventDefault();
evt.stopPropagation();

View File

@@ -158,7 +158,7 @@ function boot_spacedeck() {
});
}
document.addEventListener("DOMContentLoaded",function() {
$(document).ready(function(){
window.smoke = smoke;
window.alert = smoke.alert;

View File

@@ -59,13 +59,13 @@ SpacedeckWebsockets = {
else if (msg.action == "delete" && msg.object) {
if (this.active_space) {
var o = msg.object;
if (o._id){
if(o._id){
var existing_artifact = this.find_artifact_by_id(o._id);
if (existing_artifact) {
var idx = this.active_space_artifacts.indexOf(existing_artifact);
this.active_space_artifacts.splice(idx, 1);
} else console.log("existing artifact to delete not found");
} else console.error("object without _id");
}else console.error("object without _id");
}
}
}
@@ -101,13 +101,11 @@ SpacedeckWebsockets = {
}
if (this.websocket && this.websocket.readyState==1) {
var token = "";
if (this.user) token = this.user.token;
var auth_params = {
action: "auth",
editor_auth: space_auth,
editor_name: this.guest_nickname,
auth_token: token,
auth_token: window.socket_auth,
space_id: space._id
};
console.log("[websocket] auth space");

View File

@@ -331,7 +331,7 @@ function setup_whiteboard_directives() {
var $scope = this.vm.$root;
return _.filter($scope.active_space_artifacts, function(a) {
return this.rects_intersecting(a, rect);
return this.rects_intersecting(a.board, rect);
}.bind(this));
},
@@ -439,15 +439,15 @@ function setup_whiteboard_directives() {
dists = $scope.unselected_artifacts().map(function(a){
var r = this.rect_to_points(a);
var r = this.rect_to_points(a.board);
var xd1 = Math.abs(r[0].x-x);
var xd2 = Math.abs(r[1].x-x);
var xd3 = Math.abs(r[0].x+a.w/2 - x);
var xd3 = Math.abs(r[0].x+a.board.w/2 - x);
var yd1 = Math.abs(r[0].y-y);
var yd2 = Math.abs(r[2].y-y);
var yd3 = Math.abs(r[0].y+a.h/2 - y);
var yd3 = Math.abs(r[0].y+a.board.h/2 - y);
if (!snap_middle) {
if (xd2<xd1) {
@@ -469,10 +469,10 @@ function setup_whiteboard_directives() {
if (snap_middle) {
var xd = xd3;
var sx = r[0].x+a.w/2;
var sx = r[0].x+a.board.w/2;
var yd = yd3;
var sy = r[0].y+a.h/2;
var sy = r[0].y+a.board.h/2;
}
return [[xd,sx],[yd,sy]];
@@ -531,14 +531,18 @@ function setup_whiteboard_directives() {
mime: "x-spacedeck/vector",
description: "",
control_points: [{dx:0,dy:0}],
x: point.x,
y: point.y,
z: z,
w: 64,
h: 64,
stroke_color: "#000000",
stroke: 2,
shape: "scribble"
board: {
x: point.x,
y: point.y,
z: z,
w: 64,
h: 64
},
style: {
stroke_color: "#000000",
stroke: 2,
shape: "scribble"
}
};
$scope.save_artifact(a, function(saved_a) {
@@ -568,14 +572,18 @@ function setup_whiteboard_directives() {
mime: "x-spacedeck/vector",
description: "",
control_points: [{dx:0,dy:0},{dx:0,dy:0},{dx:0,dy:0}],
x: point.x,
y: point.y,
z: z,
w: 64,
h: 64,
stroke_color: "#000000",
stroke: 2,
shape: "arrow"
board: {
x: point.x,
y: point.y,
z: z,
w: 64,
h: 64
},
style: {
stroke_color: "#000000",
stroke: 2,
shape: "arrow"
}
};
$scope.save_artifact(a, function(saved_a) {
@@ -604,14 +612,18 @@ function setup_whiteboard_directives() {
mime: "x-spacedeck/vector",
description: "",
control_points: [{dx:0,dy:0},{dx:0,dy:0}],
x: point.x,
y: point.y,
z: z,
w: 64,
h: 64,
stroke_color: "#000000",
stroke: 2,
shape: "line"
board: {
x: point.x,
y: point.y,
z: z,
w: 64,
h: 64
},
style: {
stroke_color: "#000000",
stroke: 2,
shape: "line"
}
};
$scope.save_artifact(a, function(saved_a) {
@@ -663,11 +675,11 @@ function setup_whiteboard_directives() {
if (_.include(["text","placeholder"],$scope.artifact_major_type(ars[i]))) {
// some types of artifact need a minimum size
if (ars[i].w<10) {
ars[i].w = 10;
if (ars[i].board.w<10) {
ars[i].board.w = 10;
}
if (ars[i].h<10) {
ars[i].h = 10;
if (ars[i].board.h<10) {
ars[i].board.h = 10;
}
}
@@ -815,8 +827,10 @@ function setup_whiteboard_directives() {
if (old_a) {
return {
x: old_a.x + dx - snap_dx,
y: old_a.y + dy - snap_dy
board: _.extend(a.board, {
x: old_a.board.x + dx - snap_dx,
y: old_a.board.y + dy - snap_dy
})
};
} else {
// deleted?
@@ -851,24 +865,26 @@ function setup_whiteboard_directives() {
var scale_x = lead_x ? (moved_x)/lead_x : 1;
var scale_y = lead_y ? (moved_y)/lead_y : 1;
if (!$scope.transform_lock) scale_y = scale_x;
if ($scope.transform_lock) scale_y = scale_x;
$scope.update_selected_artifacts(function(a) {
var old_a = $scope.find_artifact_before_transaction(a);
var x1 = origin_x + ((old_a.x - origin_x) * scale_x);
var y1 = origin_y + ((old_a.y - origin_y) * scale_y);
var x2 = origin_x + (((old_a.x + old_a.w) - origin_x) * scale_x);
var y2 = origin_y + (((old_a.y + old_a.h) - origin_y) * scale_y);
var x1 = origin_x + ((old_a.board.x - origin_x) * scale_x);
var y1 = origin_y + ((old_a.board.y - origin_y) * scale_y);
var x2 = origin_x + (((old_a.board.x + old_a.board.w) - origin_x) * scale_x);
var y2 = origin_y + (((old_a.board.y + old_a.board.h) - origin_y) * scale_y);
if (x1>x2) { var t = x1; x1 = x2; x2 = t; }
if (y1>y2) { var t = y1; y1 = y2; y2 = t; }
return {
x: x1,
y: y1,
w: x2 - x1,
h: y2 - y1
board: _.extend(a.board, {
x: x1,
y: y1,
w: x2 - x1,
h: y2 - y1
})
};
}.bind(this));
@@ -886,17 +902,18 @@ function setup_whiteboard_directives() {
var old_a = $scope.find_artifact_before_transaction(a);
var control_points = _.cloneDeep(old_a.control_points);
var board = _.clone(old_a.board);
var cp = control_points[$scope.selected_control_point_idx];
var snapped = _this.snap_point(old_a.x+cp.dx+dx, old_a.y+cp.dy+dy);
dx = snapped.snapx[1]-(old_a.x+cp.dx);
dy = snapped.snapy[1]-(old_a.y+cp.dy);
var snapped = _this.snap_point(board.x+cp.dx+dx, board.y+cp.dy+dy);
dx = snapped.snapx[1]-(board.x+cp.dx);
dy = snapped.snapy[1]-(board.y+cp.dy);
cp.dx += dx;
cp.dy += dy;
// special case for arrow's 3rd point
if (a.shape == "arrow" && $scope.selected_control_point_idx!=2) {
if (a.style.shape == "arrow" && $scope.selected_control_point_idx!=2) {
/*control_points[2].dx += dx/2;
control_points[2].dy += dy/2; */
@@ -904,7 +921,7 @@ function setup_whiteboard_directives() {
control_points[2].dy = (control_points[0].dy+control_points[1].dy)/2;
}
return _this.normalize_control_points(control_points, old_a);
return _this.normalize_control_points(control_points, board);
});
} else if (this.mouse_state == "scribble") {
@@ -913,14 +930,16 @@ function setup_whiteboard_directives() {
var old_a = a;
var control_points = _.cloneDeep(old_a.control_points);
var board = _.clone(old_a.board);
var offset = this.offset_point_in_wrapper({x:cursor.x,y:cursor.y});
control_points.push({
dx: offset.x-old_a.x,
dy: offset.y-old_a.y
dx: offset.x-board.x,
dy: offset.y-board.y
});
return this.normalize_control_points(simplify_scribble_points(control_points), old_a);
return this.normalize_control_points(simplify_scribble_points(control_points), board);
}.bind(this));
var arts = $scope.selected_artifacts();
@@ -940,7 +959,7 @@ function setup_whiteboard_directives() {
}
},
normalize_control_points: function(control_points, artifact) {
normalize_control_points: function(control_points, board) {
var x1 = _.min(control_points,"dx").dx;
var y1 = _.min(control_points,"dy").dy;
var x2 = _.max(control_points,"dx").dx;
@@ -962,15 +981,19 @@ function setup_whiteboard_directives() {
var bshiftx = 0;
var bshifty = 0;
if (artifact.w < 0) bshiftx = -artifact.w;
if (artifact.h < 0) bshifty = -artifact.h;
if (board.w < 0) bshiftx = -board.w;
if (board.h < 0) bshifty = -board.h;
return {
x: artifact.x + bshiftx - shiftx,
y: artifact.y + bshifty - shifty,
var shifted_board = {
x: board.x + bshiftx - shiftx,
y: board.y + bshifty - shifty,
w: w,
h: h,
z: artifact.z,
z: board.z
};
return {
board: shifted_board,
control_points: shifted_cps
};
}

View File

@@ -21,7 +21,7 @@ function vec2_angle(v) {
}
function render_vector_drawing(a, padding) {
var shape = a.shape || "";
var shape = a.style.shape || "";
var path = [];
var p = a.control_points[0];
@@ -48,8 +48,8 @@ function render_vector_drawing(a, padding) {
var d = "M" + (cps.dx + padding) + "," + (cps.dy + padding) + " Q" + (scaledMiddlePoint.dx + padding) + "," + (scaledMiddlePoint.dy + padding) + " " + (cpe.dx + padding) + "," + (cpe.dy + padding);
var tip = "<defs><marker id='ae" + markerId + "' refX=\"0.1\" refY=\"3\" markerWidth=\"3\" markerHeight=\"6\" orient=\"auto\">";
tip += "<path d=\"M-3,0 V6 L3,3 Z\" fill=\""+a.stroke_color+"\" stroke-width=\"0\"/></marker></defs>";
var svg = tip + "<path d='" + d + "' style='stroke-width:" + a.stroke + ";' marker-end='url(#ae" + markerId + ")'/>";
tip += "<path d=\"M-3,0 V6 L3,3 Z\" fill=\""+a.style.stroke_color+"\" stroke-width=\"0\"/></marker></defs>";
var svg = tip + "<path d='" + d + "' style='stroke-width:" + a.style.stroke + ";' marker-end='url(#ae" + markerId + ")'/>";
return svg;
}
@@ -237,11 +237,11 @@ function render_vector_rect(xradius,yradius,offset) {
}
function render_vector_shape(a) {
var stroke = parseInt(a.stroke) + 4;
var stroke = parseInt(a.style.stroke) + 4;
var offset = stroke / 2;
var xr = (a.w-stroke) / 2;
var yr = (a.h-stroke) / 2;
var xr = (a.board.w-stroke) / 2;
var yr = (a.board.h-stroke) / 2;
var shape_renderers = {
ellipse: function() { return render_vector_ellipse(xr, yr, offset); },
@@ -258,7 +258,7 @@ function render_vector_shape(a) {
cloud: function() { return render_vector_cloud(xr, yr, offset); },
}
var render_func = shape_renderers[a.shape];
var render_func = shape_renderers[a.style.shape];
if (!render_func) return "";

File diff suppressed because it is too large Load Diff

View File

@@ -1,40 +1,56 @@
"use strict";
var config = require('config');
require('../../models/schema');
var fs = require('fs');
var _ = require("underscore");
var mongoose = require("mongoose");
var async = require('async');
var archiver = require('archiver');
var request = require('request');
var url = require("url");
var path = require("path");
var crypto = require('crypto');
var qr = require('qr-image');
var glob = require('glob');
var gm = require('gm');
var express = require('express');
var router = express.Router();
const db = require('../../models/db');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
const uuidv4 = require('uuid/v4');
var userMapping = { '_id': 1, 'nickname': 1, 'email': 1};
var spaceMapping = { '_id': 1, name: 1};
router.get('/:membership_id/accept', function(req, res, next) {
if (req.user) {
db.Membership.findOne({where:{
Membership.findOne({
_id: req.params.membership_id,
code: req.query.code
}, include: ['space']}).then((mem) => {
if (mem) {
if (!mem.user) {
mem.state = "active";
mem.user_id = req.user._id;
mem.save().then(function() {
res.status(200).json(mem);
});
state: "pending",
code: req.query.code,
user: { "$exists": false }
}).populate('space').exec((err,mem) => {
if (err) res.sendStatus(400);
else {
if (mem) {
if(!mem.user) {
mem.code = null;
mem.state = "active";
mem.user = req.user;
mem.save(function(err){
if (err) res.status(400).json(err);
else {
console.log(mem);
res.status(200).json(mem);
}
});
} else {
res.status(400).json({"error": "already_used"});
}
} else {
res.status(200).json(mem);
res.status(404).json({"error": "not found"});
}
} else {
res.status(404).json({"error": "not found"});
}
});
} else {

View File

@@ -1,72 +1,79 @@
"use strict";
var config = require('config');
const db = require('../../models/db');
require('../../models/schema');
var bcrypt = require('bcryptjs');
var crypto = require('crypto');
var URL = require('url').URL;
var bcrypt = require('bcrypt');
var crypo = require('crypto');
var express = require('express');
var router = express.Router();
router.post('/', function(req, res) {
var data = req.body;
if (!data.email || !data.password) {
res.status(400).json({});
return;
}
var email = req.body.email.toLowerCase();
var password = req.body["password"];
if (data.email && data.password) {
var email = req.body.email.toLowerCase();
var password = req.body["password"];
db.User.findOne({where: {email: email}})
.error(err => {
res.sendStatus(404);
})
.then(user => {
if (!user) {
res.sendStatus(404);
}
else if (bcrypt.compareSync(password, user.password_hash)) {
crypto.randomBytes(48, function(ex, buf) {
var token = buf.toString('hex');
var session = {
user_id: user._id,
token: token,
ip: req.ip,
device: "web",
created_at: new Date()
};
db.Session.create(session)
.error(err => {
console.error("Error creating Session:",err);
res.sendStatus(500);
})
.then(() => {
var domain = (process.env.NODE_ENV == "production") ? new URL(config.get('endpoint')).hostname : req.headers.hostname;
res.cookie('sdsession', token, { domain: domain, httpOnly: true });
res.status(201).json(session);
});
});
User.find({email: email, account_type: "email"}, (function (err, users) {
if (err) {
res.status(400).json({"error":"session.users"});
} else {
res.sendStatus(403);
if (users.length == 1) {
var user = users[0];
if (bcrypt.compareSync(password, user.password_hash)) {
crypo.randomBytes(48, function(ex, buf) {
var token = buf.toString('hex');
var session = {
token: token,
ip: req.ip,
device: "web",
created_at: new Date()
};
if (!user.sessions)
user.sessions = [];
user.sessions.push(session);
user.save(function(err, result) {
// FIXME
var secure = process.env.NODE_ENV == "production" || process.env.NODE_ENV == "staging";
var domain = (process.env.NODE_ENV == "production") ? ".example.org" : "localhost";
res.cookie('sdsession', token, { domain: domain, httpOnly: true, secure: secure});
res.status(201).json(session);
});
});
}else{
res.sendStatus(403);
}
} else {
res.sendStatus(404);
}
}
});
}));
} else {
res.status(400).json({});
}
});
router.delete('/current', function(req, res, next) {
if (req.user) {
var token = req.cookies['sdsession'];
db.Session.findOne({where: {token: token}})
.then(session => {
session.destroy();
});
var domain = (process.env.NODE_ENV == "production") ? new URL(config.get('endpoint')).hostname : req.headers.hostname;
res.clearCookie('sdsession', { domain: domain });
res.sendStatus(204);
var user = req.user;
var newSessions = user.sessions.filter( function(session){
return session.token != req.token;
});
user.sessions = newSessions;
user.save(function(err, result) {
// FIXME
var domain = (process.env.NODE_ENV == "production") ? ".example.org" : "localhost";
res.clearCookie('sdsession', { domain: domain });
res.sendStatus(204);
});
} else {
res.sendStatus(404);
}

View File

@@ -1,12 +1,7 @@
"use strict";
var config = require('config');
const os = require('os');
const db = require('../../models/db');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
const uuidv4 = require('uuid/v4');
require('../../models/schema');
var payloadConverter = require('../../helpers/artifact_converter');
var redis = require('../../helpers/redis');
@@ -14,11 +9,13 @@ var redis = require('../../helpers/redis');
var async = require('async');
var fs = require('fs');
var _ = require("underscore");
var mongoose = require("mongoose");
var archiver = require('archiver');
var request = require('request');
var url = require("url");
var path = require("path");
var crypto = require('crypto');
var qr = require('qr-image');
var glob = require('glob');
var gm = require('gm');
@@ -49,27 +46,22 @@ var roleMapping = {
// ARTIFACTS
router.get('/', (req, res) => {
db.Artifact.findAll({where: {
Artifact.find({
space_id: req.space._id
}}).then(artifacts => {
}).exec((err, artifacts) => {
async.map(artifacts, (a, cb) => {
db.unpackArtifact(a);
a = a.toObject();
if (a.user_id) {
// FIXME JOIN
/*User.findOne({where: {
User.findOne({
"_id": a.user_id
}}).select({
}).select({
"_id": 1,
"nickname": 1,
"email": 1
}).exec((err, user) => {
if (user) {
a['user'] = user.toObject();
}
a['user'] = user.toObject();
cb(err, a);
});*/
cb(null, a);
});
} else {
cb(null, a);
}
@@ -87,8 +79,9 @@ router.post('/', function(req, res, next) {
attrs['space_id'] = req.space._id;
var artifact = attrs;
artifact._id = uuidv4();
var artifact = new Artifact(attrs);
artifact.created_from_ip = req['real_ip'];
if (req.user) {
artifact.user_id = req.user._id;
@@ -97,18 +90,23 @@ router.post('/', function(req, res, next) {
artifact.last_update_editor_name = req.editor_name;
}
db.packArtifact(artifact);
if (req.spaceRole == "editor" || req.spaceRole == "admin") {
db.Artifact.create(artifact).then(() => {
//if (err) res.status(400).json(err);
db.unpackArtifact(artifact);
db.Space.update({ updated_at: new Date() }, {where: {_id: req.space._id}});
res.distributeCreate("Artifact", artifact);
if (req.spaceRole == "editor"  ||  req.spaceRole == "admin") {
artifact.save(function(err) {
if (err) res.status(400).json(err);
else {
Space.update({
_id: req.space._id
}, {
"$set": {
updated_at: new Date()
}
});
res.distributeCreate("Artifact", artifact);
}
});
} else {
res.status(401).json({
"error": "Access denied"
"error": "no access"
});
}
});
@@ -118,26 +116,30 @@ router.post('/:artifact_id/payload', function(req, res, next) {
var a = req.artifact;
var fileName = (req.query.filename || "upload.bin").replace(/[^a-zA-Z0-9_\-\.]/g, '');
var localFilePath = os.tmpdir() + "/" + fileName;
var localFilePath = "/tmp/" + fileName;
var writeStream = fs.createWriteStream(localFilePath);
var stream = req.pipe(writeStream);
var progressCallback = function(progressMsg) {
a.description = progressMsg.toString();
db.packArtifact(a);
var progress_callback = function(progress_msg) {
a.description = progress_msg;
a.save();
redis.sendMessage("update", "Artifact", a, req.channelId);
redis.sendMessage("update", a, a.toJSON(), req.channelId);
};
stream.on('finish', function() {
payloadConverter.convert(a, fileName, localFilePath, function(error, artifact) {
if (error) res.status(400).json(error);
else {
db.Space.update({ updated_at: new Date() }, {where: {_id: req.space._id}});
Space.update({
_id: req.space._id
}, {
"$set": {
updated_at: new Date()
}
});
res.distributeUpdate("Artifact", artifact);
}
}, progressCallback);
}, progress_callback);
});
} else {
res.status(401).json({
@@ -157,24 +159,42 @@ router.put('/:artifact_id', function(req, res, next) {
} else {
newAttr.last_update_editor_name = req.editor_name;
}
db.packArtifact(newAttr);
db.Artifact.update(newAttr, { where: {
Artifact.findOneAndUpdate({
"_id": a._id
}}).then(rows => {
db.unpackArtifact(newAttr);
db.Space.update({ updated_at: new Date() }, {where: {_id: req.space._id} });
newAttr._id = a._id;
res.distributeUpdate("Artifact", newAttr);
}, {
"$set": newAttr
}, {
"new": true
}, function(err, artifact) {
if (err) res.status(400).json(err);
else {
Space.update({
_id: req.space._id
}, {
"$set": {
updated_at: new Date()
}
});
res.distributeUpdate("Artifact", artifact);
}
});
});
router.delete('/:artifact_id', function(req, res, next) {
var artifact = req.artifact;
db.Artifact.destroy({where: { "_id": artifact._id}}).then(() => {
db.Space.update({ updated_at: new Date() }, {where: {_id: req.space._id} });
res.distributeDelete("Artifact", artifact);
artifact.remove(function(err) {
if (err) res.status(400).json(err);
else {
Space.update({
_id: req.space._id
}, {
"$set": {
updated_at: new Date()
}
});
res.distributeDelete("Artifact", artifact);
}
});
});

View File

@@ -1,15 +1,17 @@
"use strict";
var config = require('config');
require('../../models/db');
require('../../models/schema');
var async = require('async');
var fs = require('fs');
var _ = require("underscore");
var mongoose = require("mongoose");
var request = require('request');
var url = require("url");
var path = require("path");
var crypto = require('crypto');
var qr = require('qr-image');
var glob = require('glob');
var gm = require('gm');
@@ -38,12 +40,6 @@ var roleMapping = {
};
router.get('/', function(req, res, next) {
res.status(200).json([]);
return;
// FIXME TODO
var showActionForSpaces = function(err, spaceIds) {
var userMapping = {
'_id': 1,

View File

@@ -1,7 +1,8 @@
"use strict";
var config = require('config');
const db = require('../../models/db');
require('../../models/schema');
var redis = require('../../helpers/redis');
var mailer = require('../../helpers/mailer');
var uploader = require('../../helpers/uploader');
var space_render = require('../../helpers/space-render');
@@ -11,11 +12,13 @@ var async = require('async');
var moment = require('moment');
var fs = require('fs');
var _ = require("underscore");
var mongoose = require("mongoose");
var archiver = require('archiver');
var request = require('request');
var url = require("url");
var path = require("path");
var crypto = require('crypto');
var qr = require('qr-image');
var glob = require('glob');
var gm = require('gm');
var sanitizeHtml = require('sanitize-html');
@@ -46,18 +49,26 @@ var roleMapping = {
router.get('/png', function(req, res, next) {
var triggered = new Date();
var s3_filename = "s" + req.space._id + "/" + "thumb_" + triggered.getTime() + ".jpg";
if (!req.space.thumbnail_updated_at || req.space.thumbnail_updated_at < req.space.updated_at || !req.space.thumbnail_url) {
db.Space.update({ thumbnail_updated_at: triggered }, {where : {"_id": req.space._id }});
Space.update({
"_id": req.space._id
}, {
"$set": {
thumbnail_updated_at: triggered
}
}, function(a, b, c) {});
phantom.takeScreenshot(req.space, "png",
function(local_path) {
var localResizedFilePath = local_path + ".thumb.jpg";
gm(local_path).resize(640, 480).quality(70.0).autoOrient().write(localResizedFilePath, function(err) {
if (err) {
console.error("[space screenshot] resize error: ", err);
console.error("screenshot resize error: ", err);
res.status(500).send("Error taking screenshot.");
return;
}
@@ -65,15 +76,22 @@ router.get('/png', function(req, res, next) {
uploader.uploadFile(s3_filename, "image/jpeg", localResizedFilePath, function(err, thumbnailUrl) {
if (err) {
console.error("[space screenshot] upload error. filename: " + s3_filename + " details: ", err);
console.error("screenshot s3 upload error. filename: " + s3_filename + " details: ", err);
res.status(500).send("Error uploading screenshot.");
return;
}
var oldUrl = req.space.thumbnail_url;
db.Space.update({ thumbnail_url: thumbnailUrl }, {where : {"_id": req.space._id }}).then(() => {
Space.update({
"_id": req.space._id
}, {
"$set": {
thumbnail_url: thumbnailUrl
}
}, function(a, b, c) {
res.redirect(thumbnailUrl);
try {
if (oldUrl) {
var oldPath = url.parse(oldUrl).pathname;
@@ -107,6 +125,77 @@ function make_export_filename(space, extension) {
return space.name.replace(/[^\w]/g, '') + "-" + space._id + "-" + moment().format("YYYYMMDD-HH-mm-ss") + "." + extension;
}
router.get('/list', function(req, res, next) {
if (req.user) {
if (req.spaceRole == "admin" ||  req.spaceRole == "editor") {
if (req.space.space_type == "space") {
Artifact.find({
space_id: req.space._id
}).exec(function(err, artifacts) {
async.map(artifacts, function(a, cb) {
if (a.user_id) {
User.findOne({
"_id": a.user_id
}).exec(function(err, user) {
a.user = user;
if (a.last_update_user_id) {
User.findOne({
"_id": a.last_update_user_id
}).exec(function(err, updateUser) {
a.update_user = updateUser;
cb(null, a);
});
} else {
cb(null, a);
}
});
} else {
cb(null, a);
}
}, function(err, mappedArtifacts) {
req.space.artifacts = mappedArtifacts.map(function(a) {
a.description = sanitizeHtml(a.description, {
allowedTags: [],
allowedAttributes: []
});
if (a.payload_uri) {
var parsed = url.parse(a.payload_uri);
var fileName = path.basename(parsed.pathname) || "file.bin";
a.filename = fileName;
}
return a;
});
res.render('artifact_list', {
space: req.space
});
});
});
} else {
Space.getRecursiveSubspacesForSpace(req.space, (err, subspaces) => {
res.render('space_list', {
subspaces: subspaces.map((s) => {
s.ae_link = config.endpoint + '/s/' + s.edit_hash + (s.edit_slug ? ('-'+s.edit_slug) : '')
return s;
}),
space: req.space
});
});
}
} else {
res.sendStatus(403);
}
} else {
res.sendStatus(403);
}
});
router.get('/pdf', function(req, res, next) {
var s3_filename = make_export_filename(req.space, "pdf");
@@ -240,13 +329,36 @@ router.get('/zip', function(req, res, next) {
});
router.get('/html', function(req, res) {
db.Artifact.findAll({where: {
Artifact.find({
space_id: req.space._id
}}).then(function(artifacts) {
}, function(err, artifacts) {
var space = req.space;
res.send(space_render.render_space_as_html(space, artifacts));
});
});
module.exports = router;
router.get('/path', (req, res) => {
// build up a breadcrumb trail (path)
var path = [];
var buildPath = (space) => {
if (space.parent_space_id) {
Space.findOne({
"_id": space.parent_space_id
}, (err, parentSpace) => {
if (space._id == parentSpace._id) {
console.log("error: circular parent reference for space " + space._id);
res.send("error: circular reference");
} else {
path.push(parentSpace);
buildPath(parentSpace);
}
});
} else {
// reached the top
res.json(path.reverse());
}
}
buildPath(req.space);
});
module.exports = router;

View File

@@ -1,31 +1,57 @@
"use strict";
var config = require('config');
const db = require('../../models/db');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
const uuidv4 = require('uuid/v4');
require('../../models/schema');
var redis = require('../../helpers/redis');
var mailer = require('../../helpers/mailer');
var uploader = require('../../helpers/uploader');
var space_render = require('../../helpers/space-render');
var phantom = require('../../helpers/phantom');
var async = require('async');
var fs = require('fs');
var _ = require("underscore");
var mongoose = require("mongoose");
var archiver = require('archiver');
var request = require('request');
var url = require("url");
var path = require("path");
var glob = require('glob');
var crypto = require('crypto');
var qr = require('qr-image');
var glob = require('glob');
var gm = require('gm');
var express = require('express');
var router = express.Router({mergeParams: true});
// JSON MAPPINGS
var userMapping = {
_id: 1,
nickname: 1,
email: 1,
avatar_thumb_uri: 1
};
var spaceMapping = {
_id: 1,
name: 1,
thumbnail_url: 1
};
var roleMapping = {
"none": 0,
"viewer": 1,
"editor": 2,
"admin": 3
}
router.get('/', function(req, res, next) {
db.Membership
.findAll({where: {
space_id: req.space._id
}, include: ['user']})
.then(memberships => {
Membership
.find({
space: req.space._id
})
.populate("user")
.exec(function(err, memberships) {
res.status(200).json(memberships);
});
});
@@ -33,51 +59,52 @@ router.get('/', function(req, res, next) {
router.post('/', function(req, res, next) {
if (req.spaceRole == "admin") {
var attrs = req.body;
attrs.space_id = req.space._id;
attrs.state = "pending";
attrs._id = uuidv4();
var membership = attrs;
attrs['space'] = req.space._id;
attrs['state'] = "pending";
var membership = new Membership(attrs);
var msg = attrs.personal_message;
if (membership.email_invited != req.user.email) {
db.User.findOne({where:{
User.findOne({
"email": membership.email_invited
}}).then(function(user) {
}, function(err, user) {
if (user) {
membership.user_id = user._id;
membership.user = user;
membership.state = "active";
} else {
membership.code = crypto.randomBytes(64).toString('hex').substring(0, 12);
}
db.Membership.create(membership).then(function() {
var accept_link = config.endpoint + "/accept/" + membership._id + "?code=" + membership.code;
membership.save(function(err) {
if (err) res.sendStatus(400);
else {
var accept_link = config.endpoint + "/accept/" + membership._id + "?code=" + membership.code;
if (user) {
accept_link = config.endpoint + "/" + req.space.space_type + "s/" + req.space._id;
if (user) {
accept_link = config.endpoint + "/" + req.space.space_type + "s/" + req.space._id;
}
var openText = req.i18n.__("space_invite_membership_action");
if (user) {
req.i18n.__("open");
}
const name = req.user.nickname || req.user.email
const subject = (req.space.space_type == "space") ? req.i18n.__("space_invite_membership_subject", name, req.space.name) : req.i18n.__("folder_invite_membership_subject", req.user.nickname, req.space.name)
const body = (req.space.space_type == "space") ? req.i18n.__("space_invite_membership_body", name, req.space.name) : req.i18n.__("folder_invite_membership_body", req.user.nickname, req.space.name)
mailer.sendMail(
membership.email_invited, subject, body, {
messsage: msg,
action: {
link: accept_link,
name: openText
}
});
res.status(201).json(membership);
}
var openText = req.i18n.__("space_invite_membership_action");
if (user) {
req.i18n.__("open");
}
const name = req.user.nickname || req.user.email
const subject = (req.space.space_type == "space") ? req.i18n.__("space_invite_membership_subject", name, req.space.name) : req.i18n.__("folder_invite_membership_subject", req.user.nickname, req.space.name)
const body = (req.space.space_type == "space") ? req.i18n.__("space_invite_membership_body", name, req.space.name) : req.i18n.__("folder_invite_membership_body", req.user.nickname, req.space.name)
mailer.sendMail(
membership.email_invited, subject, body, {
messsage: msg,
action: {
link: accept_link,
name: openText
}
});
res.status(201).json(membership);
});
});
@@ -98,15 +125,21 @@ router.post('/', function(req, res, next) {
router.put('/:membership_id', function(req, res, next) {
if (req.user) {
if (req.spaceRole == "admin") {
db.Membership.findOne({ where: {
Membership.findOne({
_id: req.params.membership_id
}}).then(function(mem) {
if (mem) {
var attrs = req.body;
mem.role = attrs.role;
mem.save(function() {
res.status(201).json(mem);
});
}, function(err, mem) {
if (err) res.sendStatus(400);
else {
if (mem) {
var attrs = req.body;
mem.role = attrs.role;
mem.save(function(err) {
if (err) res.sendStatus(400);
else {
res.status(201).json(mem);
}
});
}
}
});
} else {
@@ -119,12 +152,20 @@ router.put('/:membership_id', function(req, res, next) {
router.delete('/:membership_id', function(req, res, next) {
if (req.user) {
db.Membership.findOne({ where: {
Membership.findOne({
_id: req.params.membership_id
}}).then(function(mem) {
mem.destroy().then(function() {
res.sendStatus(204);
});
}, function(err, mem) {
if (err) res.sendStatus(400);
else {
mem.remove(function(err) {
if (err) {
res.status(400).json(err);
} else {
// FIXME might need to delete the user?
res.sendStatus(204);
}
});
}
});
} else {
res.sendStatus(403);

View File

@@ -1,9 +1,6 @@
"use strict";
var config = require('config');
const db = require('../../models/db');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
const uuidv4 = require('uuid/v4');
require('../../models/schema');
var redis = require('../../helpers/redis');
var mailer = require('../../helpers/mailer');
@@ -14,12 +11,15 @@ var phantom = require('../../helpers/phantom');
var async = require('async');
var fs = require('fs');
var _ = require("underscore");
var mongoose = require("mongoose");
var archiver = require('archiver');
var request = require('request');
var url = require("url");
var path = require("path");
var crypto = require('crypto');
var qr = require('qr-image');
var glob = require('glob');
var gm = require('gm');
var express = require('express');
var router = express.Router({mergeParams: true});
@@ -49,44 +49,90 @@ var roleMapping = {
// MESSAGES
router.get('/', function(req, res, next) {
db.Message.findAll({where:{
space_id: req.space._id
}, include: ['user']})
.then(function(messages) {
res.status(200).json(messages);
});
Message.find({
space: req.space._id
}).populate('user', userMapping).exec(function(err, messages) {
res.status(200).json(messages);
});
});
router.post('/', function(req, res, next) {
var attrs = req.body;
attrs.space_id = req.space._id;
attrs.space = req.space;
if (req.user) {
attrs.user = req.user;
attrs.user_id = req.user._id;
} else {
attrs.user = null;
}
var msg = attrs;
msg._id = uuidv4();
var msg = new Message(attrs);
msg.save(function(err) {
if (err) res.status(400).json(erra);
else {
if (msg.message.length <= 1) return;
db.Message.create(msg).then(function() {
if (msg.message.length <= 1) return;
// TODO reimplement notifications
res.distributeCreate("Message", msg);
Membership
.find({
space: req.space,
user: {
"$exists": true
}
})
.populate('user')
.exec(function(err, memberships) {
var users = memberships.map(function(m) {
return m.user;
});
users.forEach((user) => {
if (user.preferences.email_notifications) {
redis.isOnlineInSpace(user, req.space, function(err, online) {
if (!online) {
var nickname = msg.editor_name;
if (req.user) {
nickname = req.user.nickname;
}
mailer.sendMail(
user.email,
req.i18n.__("space_message_subject", req.space.name),
req.i18n.__("space_message_body", nickname, req.space.name), {
message: msg.message,
action: {
link: config.endpoint + "/spaces/" + req.space._id.toString(),
name: req.i18n.__("open")
}
});
} else {
console.log("not sending message to user: is online.");
}
});
} else {
console.log("not sending message to user: is disabled notifications.");
}
});
});
res.distributeCreate("Message", msg);
}
});
});
router.delete('/:message_id', function(req, res, next) {
db.Message.findOne({where:{
Message.findOne({
"_id": req.params.message_id
}}).then(function(msg) {
}, function(err, msg) {
if (!msg) {
res.sendStatus(404);
} else {
msg.destroy().then(function() {
res.distributeDelete("Message", msg);
msg.remove(function(err) {
if (err) res.status(400).json(err);
else {
if (msg) {
res.distributeDelete("Message", msg);
} else {
res.sendStatus(404);
}
}
});
}
});

View File

@@ -1,10 +1,6 @@
"use strict";
var config = require('config');
const os = require('os');
const db = require('../../models/db');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
const uuidv4 = require('uuid/v4');
require('../../models/schema');
var redis = require('../../helpers/redis');
var mailer = require('../../helpers/mailer');
@@ -18,10 +14,13 @@ var slug = require('slug');
var fs = require('fs');
var async = require('async');
var _ = require("underscore");
var mongoose = require("mongoose");
var archiver = require('archiver');
var request = require('request');
var url = require("url");
var path = require("path");
var crypto = require('crypto');
var qr = require('qr-image');
var glob = require('glob');
var gm = require('gm');
const exec = require('child_process');
@@ -49,14 +48,15 @@ router.get('/', function(req, res, next) {
});
} else {
if (req.query.writablefolders) {
db.Membership.find({where: {
user_id: req.user._id
}}, (memberships) => {
Membership.find({
user: req.user._id
}, (err, memberships) => {
var validMemberships = memberships.filter((m) => {
if (!m.space_id || (m.space_id == "undefined"))
if (!m.space || (m.space == "undefined"))
return false;
return true;
else
return mongoose.Types.ObjectId.isValid(m.space.toString());
});
var editorMemberships = validMemberships.filter((m) => {
@@ -64,10 +64,9 @@ router.get('/', function(req, res, next) {
});
var spaceIds = editorMemberships.map(function(m) {
return m.space_id;
return new mongoose.Types.ObjectId(m.space);
});
// TODO port
var q = {
"space_type": "folder",
"$or": [{
@@ -82,11 +81,13 @@ router.get('/', function(req, res, next) {
}]
};
db.Space
.findAll({where: q})
.then(function(spaces) {
Space
.find(q)
.populate('creator', userMapping)
.exec(function(err, spaces) {
if (err) console.error(err);
var updatedSpaces = spaces.map(function(s) {
var spaceObj = s; //.toObject();
var spaceObj = s.toObject();
return spaceObj;
});
@@ -103,67 +104,75 @@ router.get('/', function(req, res, next) {
return s.space_type == "folder";
})
var uniqueFolders = _.unique(onlyFolders, (s) => {
return s._id;
return s._id.toString();
})
res.status(200).json(uniqueFolders);
});
});
});
} else if (req.query.search) {
db.Membership.findAll({where:{
user_id: req.user._id
}}).then(memberships => {
Membership.find({
user: req.user._id
}, function(err, memberships) {
var validMemberships = memberships.filter(function(m) {
if (!m.space_id || (m.space_id == "undefined"))
if (!m.space || (m.space == "undefined"))
return false;
else
return true;
return mongoose.Types.ObjectId.isValid(m.space.toString());
});
var spaceIds = validMemberships.map(function(m) {
return m.space_id;
return new mongoose.Types.ObjectId(m.space);
});
// TODO FIXME port
var q = { where: {
[Op.or]: [{"creator_id": req.user._id},
{"_id": {[Op.in]: spaceIds}},
{"parent_space_id": {[Op.in]: spaceIds}}],
name: {[Op.like]: "%"+req.query.search+"%"}
}, include: ['creator']};
var q = {
"$or": [{"creator": req.user._id},
{"_id": {"$in": spaceIds}},
{"parent_space_id": {"$in": spaceIds}}],
name: new RegExp(req.query.search, "i")
};
db.Space
.findAll(q)
.then(function(spaces) {
Space
.find(q)
.populate('creator', userMapping)
.exec(function(err, spaces) {
if (err) console.error(err);
var updatedSpaces = spaces.map(function(s) {
var spaceObj = s.toObject();
return spaceObj;
});
res.status(200).json(spaces);
});
});
} else if (req.query.parent_space_id && req.query.parent_space_id != req.user.home_folder_id) {
db.Space
.findOne({where: {
Space
.findOne({
_id: req.query.parent_space_id
}})
//.populate('creator', userMapping)
.then(function(space) {
})
.populate('creator', userMapping)
.exec(function(err, space) {
if (space) {
db.getUserRoleInSpace(space, req.user, function(role) {
Space.roleInSpace(space, req.user, function(err, role) {
if (role == "none") {
if (space.access_mode == "public") {
if(space.access_mode == "public") {
role = "viewer";
}
}
if (role != "none") {
db.Space
.findAll({where:{
Space
.find({
parent_space_id: req.query.parent_space_id
}, include:['creator']})
.then(function(spaces) {
})
.populate('creator', userMapping)
.exec(function(err, spaces) {
res.status(200).json(spaces);
});
} else {
@@ -176,39 +185,41 @@ router.get('/', function(req, res, next) {
});
} else {
db.Membership.findAll({ where: {
user_id: req.user._id
}}).then(memberships => {
if (!memberships) memberships = [];
Membership.find({
user: req.user._id
}, function(err, memberships) {
var validMemberships = memberships.filter(function(m) {
if (!m.space_id || (m.space_id == "undefined"))
if (!m.space || (m.space == "undefined"))
return false;
else
return mongoose.Types.ObjectId.isValid(m.space.toString());
});
var spaceIds = validMemberships.map(function(m) {
return m.space_id;
return new mongoose.Types.ObjectId(m.space);
});
var q = {
[Op.or]: [{
"creator_id": req.user._id,
"$or": [{
"creator": req.user._id,
"parent_space_id": req.user.home_folder_id
}, {
"_id": {
[Op.in]: spaceIds
"$in": spaceIds
},
"creator_id": {
[Op.ne]: req.user._id
"creator": {
"$ne": req.user._id
}
}]
};
db.Space
.findAll({where: q, include: ['creator']})
.then(function(spaces) {
Space
.find(q)
.populate('creator', userMapping)
.exec(function(err, spaces) {
if (err) console.error(err);
var updatedSpaces = spaces.map(function(s) {
var spaceObj = db.spaceToObject(s);
var spaceObj = s.toObject();
return spaceObj;
});
res.status(200).json(spaces);
@@ -218,43 +229,47 @@ router.get('/', function(req, res, next) {
}
});
// create a space
router.post('/', function(req, res, next) {
if (req.user) {
var attrs = req.body;
var createSpace = () => {
attrs._id = uuidv4();
attrs.creator_id = req.user._id;
attrs.creator = req.user;
attrs.edit_hash = crypto.randomBytes(64).toString('hex').substring(0, 7);
attrs.edit_slug = slug(attrs.name);
db.Space.create(attrs).then(createdSpace => {
//if (err) res.sendStatus(400);
var membership = {
_id: uuidv4(),
user_id: req.user._id,
space_id: attrs._id,
role: "admin"
};
db.Membership.create(membership).then(() => {
res.status(201).json(createdSpace);
});
var space = new Space(attrs);
space.save(function(err, createdSpace) {
if (err) res.sendStatus(400);
else {
var membership = new Membership({
user: req.user,
space: createdSpace,
role: "admin"
});
membership.save(function(err, createdTeam) {
if (err) {
res.status(400).json(err);
} else {
res.status(201).json(createdSpace);
}
});
}
});
}
if (attrs.parent_space_id) {
db.Space.findOne({ where: {
Space.findOne({
"_id": attrs.parent_space_id
}}).then(parentSpace => {
}).populate('creator', userMapping).exec((err, parentSpace) => {
if (parentSpace) {
db.getUserRoleInSpace(parentSpace, req.user, (role) => {
Space.roleInSpace(parentSpace, req.user, (err, role) => {
if ((role == "editor") || (role == "admin")) {
createSpace();
} else {
res.status(403).json({
"error": "not editor in parent Space. role: "+role
"error": "not editor in parent Space"
});
}
});
@@ -277,30 +292,6 @@ router.get('/:id', function(req, res, next) {
res.status(200).json(req.space);
});
router.get('/:id/path', (req, res) => {
// build up a breadcrumb trail (path)
var path = [];
var buildPath = (space) => {
if (space.parent_space_id) {
db.Space.findOne({ where: {
"_id": space.parent_space_id
}}).then(parentSpace => {
if (space._id == parentSpace._id) {
console.error("error: circular parent reference for space " + space._id);
res.send("error: circular reference");
} else {
path.push(parentSpace);
buildPath(parentSpace);
}
});
} else {
// reached the top
res.json(path.reverse());
}
}
buildPath(req.space);
});
router.put('/:id', function(req, res) {
var space = req.space;
var newAttr = req.body;
@@ -317,17 +308,24 @@ router.put('/:id', function(req, res) {
delete newAttr['editor_name'];
delete newAttr['creator'];
db.Space.update(newAttr, {where: {
Space.findOneAndUpdate({
"_id": space._id
}}).then(space => {
res.distributeUpdate("Space", space);
}, {
"$set": newAttr
}, {
"new": true
}, function(err, space) {
if (err) res.status(400).json(err);
else {
res.distributeUpdate("Space", space);
}
});
});
router.post('/:id/background', function(req, res, next) {
var space = req.space;
var newDate = new Date();
var fileName = (req.query.filename || "upload.jpg").replace(/[^a-zA-Z0-9\.]/g, '');
var fileName = (req.query.filename || "upload.bin").replace(/[^a-zA-Z0-9\.]/g, '');
var localFilePath = "/tmp/" + fileName;
var writeStream = fs.createWriteStream(localFilePath);
var stream = req.pipe(writeStream);
@@ -336,26 +334,38 @@ router.post('/:id/background', function(req, res, next) {
uploader.uploadFile("s" + req.space._id + "/bg_" + newDate.getTime() + "_" + fileName, "image/jpeg", localFilePath, function(err, backgroundUrl) {
if (err) res.status(400).json(err);
else {
if (space.background_uri) {
var oldPath = url.parse(req.space.background_uri).pathname;
var adv = space.advanced;
if (adv.background_uri) {
var oldPath = url.parse(req.space.thumbnail_url).pathname;
uploader.removeFile(oldPath, function(err) {
console.error("removed old bg error:", err);
console.log("removed old bg error:", err);
});
}
db.Space.update({
background_uri: backgroundUrl
adv.background_uri = backgroundUrl;
Space.findOneAndUpdate({
"_id": space._id
}, {
where: { "_id": space._id }
}, function(rows) {
fs.unlink(localFilePath, function(err) {
if (err) {
console.error(err);
res.status(400).json(err);
} else {
res.status(200).json(space);
}
});
"$set": {
advanced: adv
}
}, {
"new": true
}, function(err, space) {
if (err) {
res.sendStatus(400);
} else {
fs.unlink(localFilePath, function(err) {
if (err) {
console.error(err);
res.status(400).json(err);
} else {
res.status(200).json(space);
}
});
}
});
}
});
@@ -380,10 +390,10 @@ router.post('/:id/duplicate', (req, res, next) => {
}).populate('creator', userMapping).exec((err, parentSpace) => {
if (!parentSpace) {
res.status(404).json({
"error": "parent space not found for duplicate"
"error": "parent space not found for dupicate"
});
} else {
db.getUserRoleInSpace(parentSpace, req.user, (role) => {
Space.roleInSpace(parentSpace, req.user, (err, role) => {
if (role == "admin" ||  role == "editor") {
handleDuplicateSpaceRequest(req, res, parentSpace);
} else {
@@ -405,12 +415,15 @@ router.delete('/:id', function(req, res, next) {
if (req.spaceRole == "admin") {
const attrs = req.body;
space.destroy().then(function() {
res.distributeDelete("Space", space);
Space.recursiveDelete(space, function(err) {
if (err) res.status(400).json(err);
else {
res.distributeDelete("Space", space);
}
});
} else {
res.status(403).json({
"error": "requires admin role"
"error": "requires admin status"
});
}
} else {
@@ -423,19 +436,19 @@ router.post('/:id/artifacts-pdf', function(req, res, next) {
var withZones = (req.query.zones) ? req.query.zones == "true" : false;
var fileName = (req.query.filename || "upload.bin").replace(/[^a-zA-Z0-9\.]/g, '');
var localFilePath = os.tmpdir() + "/" + fileName;
var localFilePath = "/tmp/" + fileName;
var writeStream = fs.createWriteStream(localFilePath);
var stream = req.pipe(writeStream);
req.on('end', function() {
var rawName = fileName.slice(0, fileName.length - 4);
var outputFolder = os.tmpdir() + "/" + rawName;
fs.mkdir(outputFolder, function(err) {
var outputFolder = "/tmp/" + rawName;
var rights = 777;
fs.mkdir(outputFolder, function(db) {
var images = outputFolder + "/" + rawName + "-page-%03d.jpeg";
// FIXME not portable
exec.execFile("gs", ["-sDEVICE=jpeg", "-dDownScaleFactor=4", "-dDOINTERPOLATE", "-dNOPAUSE", "-dJPEGQ=80", "-dBATCH", "-sOutputFile=" + images, "-r250", "-f", localFilePath], {}, function(error, stdout, stderr) {
if (error === null) {
@@ -455,7 +468,7 @@ router.post('/:id/artifacts-pdf', function(req, res, next) {
var number = parseInt(baseName.slice(baseName.length - 3, baseName.length), 10);
gm(localFilePath).size((err, size) => {
gm(localFilePath).size(function(err, size) {
var w = 350;
var h = w;
@@ -463,58 +476,62 @@ router.post('/:id/artifacts-pdf', function(req, res, next) {
var y = startY + ((parseInt(((number - 1) / limitPerRow), 10) + 1) * w);
var userId;
if (req.user) userId = req.user._id;
if (req.user)
userId = req.user._id;
var a = db.Artifact.create({
_id: uuidv4(),
var a = new Artifact({
mime: "image/jpg",
space_id: req.space._id,
user_id: userId,
editor_name: req.guest_name,
w: w,
h: h,
x: x,
y: y,
z: (number + (count + 100))
}).then(a => {
payloadConverter.convert(a, fileName, localfilePath, (error, artifact) => {
if (error) res.status(400).json(error);
else {
if (withZones) {
var zone = {
_id: uuidv4(),
mime: "x-spacedeck/zone",
description: "Zone " + (number),
space_id: req.space._id,
user_id: userId,
editor_name: req.guest_name,
w: artifact.w + 20,
h: artifact.h + 40,
board: {
w: w,
h: h,
x: x,
y: y,
z: (number + (count + 100))
}
});
payloadConverter.convert(a, fileName, localfilePath, (error, artifact) => {
if (error) res.status(400).json(error);
else {
if (withZones) {
var zone = new Artifact({
mime: "x-spacedeck/zone",
description: "Zone " + (number),
space_id: req.space._id,
user_id: userId,
editor_name: req.guest_name,
board: {
w: artifact.board.w + 20,
h: artifact.board.h + 40,
x: x - 10,
y: y - 30,
z: number,
z: number
},
style: {
order: number,
valign: "middle",
align: "center"
};
}
});
db.Artifact.create(zone).then((z) => {
redis.sendMessage("create", "Artifact", z.toJSON(), req.channelId);
cb(null, [artifact, zone]);
});
zone.save((err) => {
redis.sendMessage("create", "Artifact", zone.toJSON(), req.channelId);
cb(null, [artifact, zone]);
});
} else {
cb(null, [artifact]);
}
} else {
cb(null, [artifact]);
}
});
}
});
});
}, function(err, artifacts) {
// FIXME not portable
exec.execFile("rm", ["-r", outputFolder], function(err) {
res.status(201).json(_.flatten(artifacts));
@@ -522,10 +539,10 @@ router.post('/:id/artifacts-pdf', function(req, res, next) {
if (artifact_or_artifacts instanceof Array) {
_.each(artifact_or_artifacts, (a) => {
redis.sendMessage("create", "Artifact", JSON.stringify(a), req.channelId);
redis.sendMessage("create", "Artifact", a.toJSON(), req.channelId);
});
} else  {
redis.sendMessage("create", "Artifact", JSON.stringify(artifact_or_artifacts), req.channelId);
redis.sendMessage("create", "Artifact", artifact_or_artifacts.toJSON(), req.channelId);
}
cb(null);
});
@@ -534,7 +551,6 @@ router.post('/:id/artifacts-pdf', function(req, res, next) {
});
} else {
console.error("error:", error);
// FIXME not portable
exec.execFile("rm", ["-r", outputFolder], function(err) {
fs.unlink(localFilePath);
res.status(400).json({});

265
routes/api/teams.js Normal file
View File

@@ -0,0 +1,265 @@
"use strict";
var config = require('config');
require('../../models/schema');
var redis = require('../../helpers/redis');
var mailer = require('../../helpers/mailer');
var fs = require('fs');
var _ = require('underscore');
var crypto = require('crypto');
var bcrypt = require('bcrypt');
var express = require('express');
var router = express.Router();
var userMapping = { '_id': 1, 'nickname': 1, 'email': 1};
router.get('/:id', (req, res) => {
res.status(200).json(req.user.team);
});
router.put('/:id', (req, res) => {
var team = req.user.team;
if (!team) {
res.status(400).json({"error": "user in no team"});
} else {
var newAttr = req.body;
newAttr.updated_at = new Date();
delete newAttr['_id'];
if(newAttr['subdomain']) {
newAttr['subdomain'] = newAttr['subdomain'].toLowerCase();
}
const new_subdomain = newAttr['subdomain'];
var forbidden_subdomains = [];
function updateTeam() {
Team.findOneAndUpdate({"_id": team._id}, {"$set": newAttr}, {"new": true}, (err, team) => {
if (err) res.status(400).json(err);
else {
res.status(200).json(team);
}
});
}
var isForbidden = forbidden_subdomains.indexOf(new_subdomain) > -1;
if (isForbidden) {
res.bad_request("subdomain not valid");
} else {
if (new_subdomain) {
Team.findOne({"domain": new_subdomain}).exec((err, team) => {
if(team) {
res.bad_request("subdomain already used");
} else {
updateTeam()
}
});
} else {
updateTeam()
}
}
}
});
router.get('/:id/memberships', (req, res) => {
User
.find({team: req.user.team})
.populate("team")
.exec(function(err, users){
if (err) res.status(400).json(err);
else {
res.status(200).json(users);
}
});
});
router.post('/:id/memberships', (req, res, next) => {
if (req.body.email) {
const email = req.body.email.toLowerCase();
const team = req.user.team;
User.findOne({"email": email}).populate('team').exec((err, user) => {
if (user) {
const code = crypto.randomBytes(64).toString('hex').substring(0,7);
team.invitation_codes.push(code);
team.save((err) => {
if (err){ res.status(400).json(err); }
else {
mailer.sendMail(email, req.i18n.__("team_invite_membership_subject", team.name), req.i18n.__("team_invite_membership_body", team.name), { action: {
link: config.endpoint + "/teams/" + req.user.team._id + "/join?code=" + code,
name: req.i18n.__("team_invite_membership_action"),
teamname: team.name
}});
res.status(201).json(user);
}
});
} else {
// complete new user
const password = crypto.randomBytes(64).toString('hex').substring(0,7);
const confirmation_token = crypto.randomBytes(64).toString('hex').substring(0,7);
bcrypt.genSalt(10, (err, salt) => {
bcrypt.hash(password, salt, (err, hash) => {
crypto.randomBytes(16, (ex, buf) => {
const token = buf.toString('hex');
var u = new User({
email: email,
account_type: "email",
nickname: email,
team: team._id,
password_hash: hash,
payment_plan_key: team.payment_plan_key,
confirmation_token: confirmation_token,
preferences: {
language: req.i18n.locale
}
});
u.save((err) => {
if(err) res.sendStatus(400);
else {
var homeSpace = new Space({
name: req.i18n.__("home"),
space_type: "folder",
creator: u
});
homeSpace.save((err, homeSpace) => {
if (err) res.sendStatus(400);
else {
u.home_folder_id = homeSpace._id;
u.save((err) => {
User.find({"_id": {"$in": team.admins }}).exec((err, admins) => {
admins.forEach((admin) => {
var i18n = req.i18n;
if(admin.preferences && admin.preferences.language){
i18n.setLocale(admin.preferences.language || "en");
}
mailer.sendMail(admin.email, i18n.__("team_invite_membership_subject", team.name), i18n.__("team_invite_admin_body", email, team.name, password), { teamname: team.name });
});
});
mailer.sendMail(email, req.i18n.__("team_invite_membership_subject", team.name), req.i18n.__("team_invite_user_body", team.name, password), { action: {
link: config.endpoint + "/users/byteam/" + req.user.team._id + "/join?confirmation_token=" + confirmation_token,
name: req.i18n.__("team_invite_membership_action")
}, teamname: team.name });
if (err) res.status(400).json(err);
else{
res.status(201).json(u)
}
});
}
});
}
});
});
});
});
}
});
} else {
res.status(400).json({"error": "email missing"});
}
});
router.put('/:id/memberships/:user_id', (req, res) => {
User.findOne({_id: req.params.user_id}, (err,mem) => {
if (err) res.sendStatus(400);
else {
if(user.team._id == req.user.team._id){
user['team'] = req.user.team._id;
user.save((err) => {
res.sendStatus(204);
});
} else {
res.sendStatus(403);
}
}
});
});
router.get('/:id/memberships/:user_id/promote', (req, res) => {
User.findOne({_id: req.params.user_id}, (err,user) => {
if (err) res.sendStatus(400);
else {
if (user.team.toString() == req.user.team._id.toString()) {
var team = req.user.team;
var adminIndex = team.admins.indexOf(user._id);
if (adminIndex == -1) {
team.admins.push(user._id);
team.save((err, team) => {
res.status(204).json(team);
});
} else {
res.status(400).json({"error": "already admin"});
}
} else {
res.status(403).json({"error": "team id not correct"});
}
}
});
});
router.get('/:id/memberships/:user_id/demote', (req, res, next) => {
User.findOne({_id: req.params.user_id}, (err,user) => {
if (err) res.sendStatus(400);
else {
if (user.team.toString() == req.user.team._id.toString()) {
const team = req.user.team;
const adminIndex = team.admins.indexOf(user._id);
if(adminIndex > -1) {
team.admins.splice(adminIndex,1);
team.save((err, team) => {
res.status(204).json(team);
});
} else {
res.sendStatus(404);
}
} else {
res.sendStatus(403);
}
}
});
});
router.delete('/:id/memberships/:user_id', (req, res) => {
User.findOne({_id: req.params.user_id}).populate('team').exec((err,user) => {
if (err) res.sendStatus(400);
else {
const currentUserId = req.user._id.toString();
const team = req.user.team;
const isAdmin = (req.user.team.admins.filter( mem => {
return mem == currentUserId;
}).length == 1)
if (isAdmin) {
user.team = null;
user.payment_plan_key = "free";
user.save( err => {
const adminIndex = team.admins.indexOf(user._id);
if(adminIndex > -1) {
team.admins.splice(adminIndex,1);
team.save((err, team) => {
console.log("admin removed");
});
}
res.sendStatus(204);
});
} else {
res.status(403).json({"error": "not admin"});
}
}
});
});
module.exports = router;

View File

@@ -1,16 +1,13 @@
"use strict";
var config = require('config');
const db = require('../../models/db');
const uuidv4 = require('uuid/v4');
const os = require('os');
require('../../models/schema');
var mailer = require('../../helpers/mailer');
var uploader = require('../../helpers/uploader');
var importer = require('../../helpers/importer');
var bcrypt = require('bcryptjs');
var crypto = require('crypto');
var bcrypt = require('bcrypt');
var crypo = require('crypto');
var swig = require('swig');
var async = require('async');
var _ = require('underscore');
@@ -18,117 +15,245 @@ var fs = require('fs');
var request = require('request');
var gm = require('gm');
var validator = require('validator');
var URL = require('url').URL;
var express = require('express');
var router = express.Router();
var glob = require('glob');
router.get('/current', function(req, res, next) {
if (req.user) {
var u = _.clone(req.user.dataValues);
delete u.password_hash;
delete u.password_reset_token;
delete u.confirmation_token;
u.token = req.cookies['sdsession'];
console.log(u);
res.status(200).json(u);
console.log(req.user.team);
res.status(200).json(req.user);
} else {
res.status(401).json({"error":"user_not_found"});
}
});
// create user
router.post('/', function(req, res) {
if (!req.body["email"] || !req.body["password"]) {
res.status(400).json({"error":"email or password missing"});
return;
}
var email = req.body["email"].toLowerCase();
var nickname = req.body["nickname"];
var password = req.body["password"];
var password_confirmation = req.body["password_confirmation"];
if (req.body["email"] && req.body["password"]) {
if (password_confirmation != password) {
res.status(400).json({"error":"password_confirmation"});
return;
}
if (!validator.isEmail(email)) {
res.status(400).json({"error":"email_invalid"});
return;
}
var createUser = function() {
bcrypt.genSalt(10, function(err, salt) {
bcrypt.hash(password, salt, function(err, hash) {
crypto.randomBytes(16, function(ex, buf) {
var token = buf.toString('hex');
var email = req.body["email"].toLowerCase();
var nickname = req.body["nickname"];
var password = req.body["password"];
var password_confirmation = req.body["password_confirmation"];
var u = {
_id: uuidv4(),
email: email,
account_type: "email",
nickname: nickname,
password_hash: hash,
prefs_language: req.i18n.locale,
confirmation_token: token
};
if (password_confirmation == password) {
if (validator.isEmail(email)) {
db.User.create(u)
.error(err => {
res.sendStatus(400);
})
.then(u => {
var homeSpace = {
_id: uuidv4(),
name: req.i18n.__("home"),
space_type: "folder",
creator_id: u._id
};
db.Space.create(homeSpace)
.error(err => {
res.sendStatus(400);
})
.then(homeSpace => {
u.home_folder_id = homeSpace._id;
u.save()
.then(() => {
res.status(201).json({});
mailer.sendMail(u.email, req.i18n.__("confirm_subject"), req.i18n.__("confirm_body"), {
action: {
link: config.endpoint + "/confirm/" + u.confirmation_token,
name: req.i18n.__("confirm_action")
}
});
})
.error(err => {
res.status(400).json(err);
var createUser = function() {
bcrypt.genSalt(10, function(err, salt) {
bcrypt.hash(password, salt, function(err, hash) {
crypo.randomBytes(16, function(ex, buf) {
var token = buf.toString('hex');
var u = new User({
email: email,
account_type: "email",
nickname: nickname,
password_hash: hash,
preferences: {
language: req.i18n.locale
},
confirmation_token: token
});
u.save(function (err) {
if (err) res.sendStatus(400);
else {
var homeSpace = new Space({
name: req.i18n.__("home"),
space_type: "folder",
creator: u
});
})
homeSpace.save((err, homeSpace) => {
if (err) res.sendStatus(400);
else {
u.home_folder_id = homeSpace._id;
u.save((err) => {
mailer.sendMail(u.email, req.i18n.__("confirm_subject"), req.i18n.__("confirm_body"), {
action: {
link: config.endpoint + "/confirm/" + u.confirmation_token,
name: req.i18n.__("confirm_action")
}
});
if (err) res.status(400).json(err);
else {
res.status(201).json({});
}
});
}
});
}
});
});
});
});
});
};
User.find({email: email}, (function (err, users) {
if (err) {
res.status(400).json({"error":"password_confirmation"});
} else {
if (users.length === 0) {
var domain = email.slice(email.lastIndexOf('@')+1);
Domain.findOne({domain: domain}, function(err, domain) {
if(domain){
if(domain.edu) {
createUser();
} else {
res.status(400).json({"error":"domain_blocked"});
}
} else {
createUser();
}
});
} else {
res.status(400).json({"error":"user_email_already_used"});
}
}
}));
} else {
res.status(400).json({"error":"email_invalid"});
}
} else {
res.status(400).json({"error":"password_confirmation"});
}
} else {
res.status(400).json({"error":"email or password missing"});
}
});
router.get('/oauth2callback/url', function(req, res) {
var google = require('googleapis');
var OAuth2 = google.auth.OAuth2;
var oauth2Client = new OAuth2(
config.google_access,
config.google_secret,
config.endpoint + "/login"
);
var url = oauth2Client.generateAuthUrl({
access_type: 'online',
scope: "email"
});
res.status(200).json({"url":url});
});
router.get('/loginorsignupviagoogle', function(req, res) {
var google = require('googleapis');
var OAuth2 = google.auth.OAuth2;
var plus = google.plus('v1');
var oauth2Client = new OAuth2(
config.google_access,
config.google_secret,
config.endpoint + "/login"
);
var loginUser = function(user, cb) {
crypo.randomBytes(48, function(ex, buf) {
var token = buf.toString('hex');
var session = {
token: token,
created_at: new Date()
};
if(!user.sessions)
user.sessions = [];
user.sessions.push(session);
user.save(function(err, user) {
cb(session);
});
});
};
db.User.findAll({where: {email: email}})
.then(users => {
if (users.length == 0) {
//var domain = email.slice(email.lastIndexOf('@')+1);
createUser();
} else {
res.status(400).json({"error":"user_email_already_used"});
}
})
var code = req.query.code;
oauth2Client.getToken(code, function(err, tokens) {
if (err) res.status(400).json(err);
else {
var apiUrl = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=" + tokens.access_token;
var finalizeLogin = function(session){
var secure = process.env.NODE_ENV == "production" || process.env.NODE_ENV == "staging";
res.cookie('sdsession', session.token, { httpOnly: true, secure: secure});
res.status(201).json(session);
};
request.get(apiUrl, function(error, response, body) {
if (error) res.status(400).json(error);
else {
const data = JSON.parse(body);
const email = data.email;
const name = data.name;
User.findOne({email: email}, function (err, user) {
if (user) {
// login new google user
if (user.account_type == "google") {
// just login
loginUser(user, (session) => {
finalizeLogin(session);
});
} else {
res.status(400).json({"error":"user_email_already_used"});
}
} else {
const u = new User({
email: email,
account_type: "google",
nickname: name,
avatar_thumb_uri: body.picture,
preferences: {
language: req.i18n.locale
},
confirmed_at: new Date()
});
u.save(function (err) {
if (err) res.status(400).json(err);
else {
var homeSpace = new Space({
name: req.i18n.__("home"),
space_type: "folder",
creator: u
});
homeSpace.save(function(err, homeSpace) {
if (err) res.status(400).json(err);
else {
u.home_folder_id = homeSpace._id;
u.save(function(err){
if (err) res.sendStatus(400);
else {
mailer.sendMail(u.email, req.i18n.__("welcome_subject"), req.i18n.__("welcome_body"), {});
loginUser(u, function(session) {
finalizeLogin(session);
});
}
});
}
});
}
});
}
});
}
});
}
});
});
router.get('/current', function(req, res, next) {
router.get('/ ', function(req, res, next) {
if (req.user) {
console.log(req.user.team);
res.status(200).json(req.user);
} else {
res.status(401).json({"error":"user_not_found"});
@@ -136,15 +261,19 @@ router.get('/current', function(req, res, next) {
});
router.put('/:id', function(req, res, next) {
// TODO explicit whitelisting
var user = req.user;
console.log(req.params.id, user._id);
if (user._id == req.params.id) {
var newAttr = req.body;
newAttr.updated_at = new Date();
delete newAttr['_id'];
db.User.update(newAttr, {where: {"_id": user._id}}).then(function(updatedUser) {
res.status(200).json(newAttr);
User.findOneAndUpdate({"_id": user._id}, {"$set": newAttr}, function(err, updatedUser) {
if (err) {
res.sendStatus(400);
} else {
res.status(200).json(updatedUser);
}
});
} else {
res.sendStatus(403);
@@ -162,8 +291,12 @@ router.post('/:id/password', function(req, res, next) {
bcrypt.genSalt(10, function(err, salt) {
bcrypt.hash(pass, salt, function(err, hash) {
user.password_hash = hash;
user.save().then(function() {
res.sendStatus(204);
user.save(function(err){
if(err){
res.status(400).json(err);
}else{
res.sendStatus(204);
}
});
});
});
@@ -192,7 +325,7 @@ router.delete('/:id', (req, res, next) => {
}
} else {
user.remove((err) => {
if (err) res.status(400).json(err);
if(err)res.status(400).json(err);
else res.sendStatus(204);
});
}
@@ -223,8 +356,8 @@ router.post('/:user_id/avatar', (req, res, next) => {
const user = req.user;
const filename = "u"+req.user._id+"_"+(new Date().getTime())+".jpeg"
const localFilePath = os.tmpdir()+"/"+filename;
const localResizedFilePath = os.tmpdir()+"/resized_"+filename;
const localFilePath = "/tmp/"+filename;
const localResizedFilePath = "/tmp/resized_"+filename;
const writeStream = fs.createWriteStream(localFilePath);
const stream = req.pipe(writeStream);
@@ -236,15 +369,19 @@ router.post('/:user_id/avatar', (req, res, next) => {
if (err) res.status(400).json(err);
else {
user.avatar_thumb_uri = url;
user.save().then(() => {
fs.unlink(localResizedFilePath, (err) => {
if (err) {
console.error(err);
res.status(400).json(err);
} else {
res.status(200).json(user);
}
});
user.save((err, updatedUser) => {
if (err) {
res.sendStatus(400);
} else {
fs.unlink(localResizedFilePath, (err) => {
if (err) {
console.error(err);
res.status(400).json(err);
} else {
res.status(200).json(updatedUser);
}
});
}
});
}
});
@@ -262,20 +399,31 @@ router.post('/feedback', function(req, res, next) {
router.post('/password_reset_requests', (req, res, next) => {
const email = req.query.email;
db.User.findOne({where: {"email": email}}).then((user) => {
if (user) {
crypto.randomBytes(16, (ex, buf) => {
user.password_reset_token = buf.toString('hex');
user.save().then(updatedUser => {
mailer.sendMail(email, req.i18n.__("password_reset_subject"), req.i18n.__("password_reset_body"), {action: {
link: config.endpoint + "/password-confirm/" + user.password_reset_token,
name: req.i18n.__("password_reset_action")
}});
res.status(201).json({});
});
});
User.findOne({"email": email}).exec((err, user) => {
if (err) {
res.status(400).json(err);
} else {
res.status(404).json({"error": "error_unknown_email"});
if (user) {
if(user.account_type == "email") {
crypo.randomBytes(16, (ex, buf) => {
user.password_reset_token = buf.toString('hex');
user.save((err, updatedUser) => {
if (err) res.status(400).json(err);
else {
mailer.sendMail(email, req.i18n.__("password_reset_subject"), req.i18n.__("password_reset_body"), {action: {
link: config.endpoint + "/password-confirm/" + user.password_reset_token,
name: req.i18n.__("password_reset_action")
}});
res.status(201).json({});
}
});
});
} else {
res.status(404).json({"error": "error_unknown_email"});
}
} else {
res.status(404).json({"error": "error_unknown_email"});
}
}
});
});
@@ -284,25 +432,29 @@ router.post('/password_reset_requests/:confirm_token/confirm', function(req, res
var password = req.body.password;
User
.findOne({where: {"password_reset_token": req.params.confirm_token}})
.then((user) => {
if (user) {
bcrypt.genSalt(10, (err, salt) => {
bcrypt.hash(password, salt, function(err, hash) {
.findOne({"password_reset_token": req.params.confirm_token})
.exec((err, user) => {
if (err) {
res.sendStatus(400);
} else {
if(user) {
bcrypt.genSalt(10, (err, salt) => {
bcrypt.hash(password, salt, function(err, hash) {
user.password_hash = hash;
user.password_token = null;
user.save(function(err, updatedUser){
if (err) {
res.sendStatus(400);
} else {
res.sendStatus(201);
}
user.password_hash = hash;
user.password_token = null;
user.save(function(err, updatedUser){
if (err) {
res.sendStatus(400);
} else {
res.sendStatus(201);
}
});
});
});
});
} else {
res.sendStatus(404);
} else {
res.sendStatus(404);
}
}
});
});
@@ -315,19 +467,4 @@ router.post('/:user_id/confirm', function(req, res, next) {
res.sendStatus(201);
});
router.get('/:user_id/importables', function(req, res, next) {
glob('*.zip', function(err, files) {
res.status(200).json(files);
});
});
router.get('/:user_id/import', function(req, res, next) {
if (req.query.zip) {
res.send("importing");
importer.importZIP(req.user, req.query.zip);
} else {
res.sendStatus(400);
}
});
module.exports = router;

View File

@@ -1,7 +1,7 @@
"use strict";
var config = require('config');
require('../../models/db');
require('../../models/schema');
var fs = require('fs');
var phantom = require('node-phantom-simple');

View File

@@ -1,6 +1,7 @@
"use strict";
const config = require('config');
require('../models/schema');
const redis = require('../helpers/redis');
const express = require('express');
@@ -8,11 +9,7 @@ const crypto = require('crypto');
const router = express.Router();
const mailer = require('../helpers/mailer');
const _ = require('underscore');
const db = require('../models/db');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;
const uuidv4 = require('uuid/v4');
const qr = require('qr-image');
router.get('/', (req, res) => {
res.render('index', { title: 'Spaces' });
@@ -98,6 +95,10 @@ router.get('/logout', (req, res) => {
res.render('spacedeck');
});
router.get('/users/oauth2callback', (req, res) => {
res.render('spacedeck');
});
router.get('/contact', (req, res) => {
res.render('public/contact');
});
@@ -124,30 +125,180 @@ router.get('/t/:id', (req, res) => {
});
router.get('/s/:token', (req, res) => {
var token = req.params.token;
if (token.split("-").length > 0) {
token = token.split("-")[0];
}
redis.rateLimit(req.real_ip, "token", function(ok) {
if (ok) {
var token = req.params.token;
if (token.split("-").length > 0) {
token = token.split("-")[0];
}
db.Space.findOne({where: {"edit_hash": token}}).then(function (space) {
if (space) {
if (req.accepts('text/html')){
res.redirect("/spaces/"+space._id + "?spaceAuth=" + token);
} else {
res.status(200).json(space);
}
Space.findOne({"edit_hash": token}).exec(function (err, space) {
if (err) {
res.status(404).render('not_found', { title: 'Page Not Found.' });
} else {
if (space) {
if(req.accepts('text/html')){
res.redirect("/spaces/"+space._id + "?spaceAuth=" + token);
}else{
res.status(200).json(space);
}
} else {
if(req.accepts('text/html')){
res.status(404).render('not_found', { title: 'Page Not Found.' });
} else {
res.status(404).json({});
}
}
}
});
} else {
if (req.accepts('text/html')) {
res.status(404).render('not_found', { title: 'Page Not Found.' });
} else {
res.status(404).json({});
}
res.status(429).json({"error": "Too Many Requests"});
}
});
});
router.get('/spaces/:id', (req, res) => {
res.render('spacedeck', { title: 'Space' });
if (req.headers['user-agent']) {
if (req.headers['user-agent'].match(/facebook/)) {
Space.findOne({"_id": req.params.id }).exec(function (err, space) {
if (err) {
res.status(400).json(err);
} else {
if (space) {
if (space.access_mode == "public") {
Artifact.find({"space_id": req.params.id }).populate("creator").exec(function(err, artifacts) {
space.artifacts = artifacts;
res.render('facebook', { space: space });
});
} else {
res.redirect("/?error=space_not_accessible");
}
} else {
res.render('not_found', { title: 'Spaces' });
}
}
});
} else {
// not facebook, render javascript
res.render('spacedeck', { title: 'Space' });
}
} else res.render('spacedeck', { title: 'Space' });
});
router.get('/users/byteam/:team_id/join', (req, res) => {
if (!req.user) {
const q = {confirmation_token: req.query.confirmation_token, account_type: "email", team: req.params.team_id};
User.findOne(q, (err, user) => {
if (err) {
res.status(400).json({"error":"session.users"});
} else {
if (user) {
crypto.randomBytes(48, function(ex, buf) {
const token = buf.toString('hex');
var session = {
token: token,
ip: req.ip,
device: "web",
created_at: new Date()
};
if (!user.sessions)
user.sessions = [];
user.sessions.push(session);
user.confirmed_at = new Date();
user.confirmation_token = null;
user.save(function(err, result) {
// FIXME
const secure = process.env.NODE_ENV == "production" || process.env.NODE_ENV == "staging";
const domain = (process.env.NODE_ENV == "production") ? ".spacedeck.com" : ".spacedecklocal.de";
res.cookie('sdsession', token, { domain: domain, httpOnly: true, secure: secure});
res.redirect("/spaces");
});
});
} else {
res.status(404).json({"error": "not found"});
}
}
});
} else {
res.redirect("/spaces");
}
});
router.get('/teams/:id/join', function(req, res, next) {
if (req.user) {
if (!req.user.team) {
Team.findOne({"_id": req.params.id}, function(err, team) {
if (team) {
const idx = team.invitation_codes.indexOf(req.query.code);
if (idx >= 0) {
const u = req.user;
u.team = team;
if(!u.confirmed_at) {
u.confirmed_at = new Date();
}
u.payment_plan_key = team.payment_plan_key;
u.save(function(err) {
if (err) res.status(400).json(err);
else {
team.invitation_condes = team.invitation_codes.slice(idx);
team.save(function(err) {
team.invitation_codes = null;
var finish = function(team, users) {
User.find({"_id": {"$in": team.admins}}).exec((err, admins) => {
if(admins) {
admins.forEach((admin) => {
mailer.sendMail(
admin.email,
req.i18n.__("team_new_member_subject", team.name),
req.i18n.__("team_new_member_body", u.email, team.name)
);
});
}
});
}
User.find({team: team}, function(err, users) {
finish(team, users);
res.redirect("/spaces");
});
});
}
});
} else {
res.redirect("/spaces?error=team_code_notfound");
}
} else {
res.redirect("/spaces?error=team_notfound");
}
});
} else {
res.redirect("/spaces?error=team_already");
}
} else res.redirect("/login");
});
router.get('/qrcode/:id', function(req, res) {
Space.findOne({"_id": req.params.id}).exec(function(err, space) {
if (space) {
const url = config.get("endpoint") + "/s/"+space.edit_hash;
const code = qr.image(url, { type: 'svg' });
res.type('svg');
code.pipe(res);
} else {
res.status(404).json({
"error": "not_found"
});
}
});
});
module.exports = router;

View File

@@ -1,169 +0,0 @@
"use strict";
const db = require('./models/db.js');
require("log-timestamp");
const config = require('config');
const redis = require('./helpers/redis');
const websockets = require('./helpers/websockets');
const http = require('http');
const path = require('path');
const _ = require('underscore');
const favicon = require('serve-favicon');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const swig = require('swig');
const i18n = require('i18n-2');
const helmet = require('helmet');
const express = require('express');
const app = express();
const serveStatic = require('serve-static');
const isProduction = app.get('env') === 'production';
console.log("Booting Spacedeck Open… (environment: " + app.get('env') + ")");
app.use(logger(isProduction ? 'combined' : 'dev'));
i18n.expressBind(app, {
locales: ["en", "de", "fr"],
defaultLocale: "en",
cookieName: "spacedeck_locale",
devMode: (app.get('env') == 'development')
});
swig.setDefaults({
varControls: ["[[", "]]"] // otherwise it's not compatible with vue.js
});
swig.setFilter('cdn', function(input, idx) {
return input;
});
app.engine('html', swig.renderFile);
app.set('view engine', 'html');
if (isProduction) {
app.set('views', path.join(__dirname, 'build', 'views'));
app.use(favicon(path.join(__dirname, 'build', 'assets', 'images', 'favicon.png')));
app.use(express.static(path.join(__dirname, 'build', 'assets')));
} else {
app.set('views', path.join(__dirname, 'views'));
app.use(favicon(path.join(__dirname, 'public', 'images', 'favicon.png')));
app.use(express.static(path.join(__dirname, 'public')));
}
app.use(bodyParser.json({
limit: '50mb'
}));
app.use(bodyParser.urlencoded({
extended: false,
limit: '50mb'
}));
app.use(cookieParser());
app.use(helmet.frameguard())
app.use(helmet.xssFilter())
app.use(helmet.hsts({
maxAge: 7776000000,
includeSubdomains: true
}))
app.disable('x-powered-by');
app.use(helmet.noSniff())
//app.use(require("./middlewares/error_helpers"));
app.use(require("./middlewares/session"));
//app.use(require("./middlewares/cors"));
app.use(require("./middlewares/i18n"));
app.use("/api", require("./middlewares/api_helpers"));
app.use('/api/spaces/:id', require("./middlewares/space_helpers"));
app.use('/api/spaces/:id/artifacts/:artifact_id', require("./middlewares/artifact_helpers"));
app.use('/api/users', require('./routes/api/users'));
app.use('/api/memberships', require('./routes/api/memberships'));
const spaceRouter = require('./routes/api/spaces');
app.use('/api/spaces', spaceRouter);
spaceRouter.use('/:id/artifacts', require('./routes/api/space_artifacts'));
spaceRouter.use('/:id/memberships', require('./routes/api/space_memberships'));
spaceRouter.use('/:id/messages', require('./routes/api/space_messages'));
spaceRouter.use('/:id/digest', require('./routes/api/space_digest'));
spaceRouter.use('/:id', require('./routes/api/space_exports'));
app.use('/api/sessions', require('./routes/api/sessions'));
//app.use('/api/webgrabber', require('./routes/api/webgrabber'));
app.use('/', require('./routes/root'));
if (config.get('storage_local_path')) {
app.use('/storage', serveStatic(config.get('storage_local_path')+"/"+config.get('storage_bucket'), {
maxAge: 24*3600
}));
}
// catch 404 and forward to error handler
//app.use(require('./middlewares/404'));
if (app.get('env') == 'development') {
app.set('view cache', false);
swig.setDefaults({cache: false});
} else {
app.use(require('./middlewares/500'));
}
module.exports = app;
// CONNECT TO DATABASE
db.init();
// START WEBSERVER
const port = 9666;
const server = http.Server(app).listen(port, () => {
if ("send" in process) {
process.send('online');
}
}).on('listening', () => {
const host = server.address().address;
const port = server.address().port;
console.log('Spacedeck Open listening at http://%s:%s', host, port);
}).on('error', (error) => {
if (error.syscall !== 'listen') {
throw error;
}
const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port;
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
});
websockets.startWebsockets(server);
redis.connectRedis();
/*process.on('message', (message) => {
console.log("Process message:", message);
if (message === 'shutdown') {
console.log("Exiting Spacedeck.");
process.exit(0);
}
});*/

View File

@@ -53,7 +53,7 @@
<p>
<div class="col-xs-6">
<a href="/contact">[[ __("contact") ]]</a>
<span style="color:#888">&copy; 2011–2018 The Spacedeck Open Developers <a href="https://github.com/spacedeck/spacedeck-open">https://github.com/spacedeck/spacedeck-open</a></span>
<span style="color:#888">&copy; 2011–2017 The Spacedeck Open Developers</span>
</div>
</p>
</div>

View File

@@ -1,6 +1,6 @@
<div id="team" class="dialog in" style="padding:100px;z-index:20000;position:absolute;width:100%;min-height:100%;background-color:#eee" v-if="active_view == 'account' && user" v-cloak>
<a href="/spaces" class="btn btn-round btn-icon btn-dark btn-md pull-right" style="position:absolute;top:30px;right:30px"><span class="icon icon-cross-0"></span></a>
<a href="/spaces" class="btn btn-round btn-icon btn-stroke-darken btn-md pull-right" style="position:absolute;top:30px;right:30px"><span class="icon icon-cross-0"></span></a>
<div class="dialog-tabs" style="margin:auto">
<div class="dialog-tab" v-bind:class="{open:account=='profile'}" v-on:click="account='profile'"><span>[[__("profile_caption")]]</span></div>
@@ -80,29 +80,21 @@
<span class="icon icon-check"></span> <span>[[__("confirmation_sent_another")]]</span>
</p>
</div>
<div class="form-group">
<label class="label">Spacedeck.com Data Import</label>
<p v-if="!importables">No .ZIP files found in Spacedeck application folder.</p>
<ul>
<li v-for="f in importables">{{f}} <button v-on:click="start_zip_import(f)">Start Import</button></li>
</ul>
</div>
</div>
</div>
<div class="collapse" v-bind:class="{in:account=='language'}">
<div class="modal-section">
<label class="radio" v-bind:class="{checked
: user.prefs_language=='en'}" v-on:click="save_user_language('en')">
: user.preferences.language=='en'}" v-on:click="save_user_language('en')">
<input type="radio" id="user-preferences_language" name="language" value="en"><span>English</span>
</label>
<hr/>
<label class="radio" v-bind:class="{checked: user.prefs_language=='de'}" v-on:click="save_user_language('de')">
<label class="radio" v-bind:class="{checked: user.preferences.language=='de'}" v-on:click="save_user_language('de')">
<input type="radio" id="user-preferences_language" name="language" value="de"><span>Deutsch</span>
</label>
<hr/>
<label class="radio" v-bind:class="{checked: user.prefs_language=='fr'}" v-on:click="save_user_language('fr')">
<label class="radio" v-bind:class="{checked: user.preferences.language=='fr'}" v-on:click="save_user_language('fr')">
<input type="radio" id="user-preferences_language" name="language" value="fr"><span>Français</span>
</label>
</div>
@@ -112,8 +104,8 @@
<div class="modal-section labels-inline">
<div class="form-group">
<label class="checkbox"
v-bind:class="{checked: user.prefs_email_notifications}"
v-on:click="account_save_user_notifications(!user.prefs_email_notifications);">
v-bind:class="{checked: user.preferences.email_notifications}"
v-on:click="account_save_user_notifications(!user.preferences.email_notifications);">
<span>[[__('notifications_option_chat')]]</span>
</label>
</div>

View File

@@ -1,9 +1,9 @@
<div id="space" class="section board active mouse-{{mouse_state}} tool-{{active_tool}}">
<div class="space-bounds" style="width:{{active_space.width*bounds_zoom}}px;height:{{active_space.height*bounds_zoom}}px;"></div>
<div class="space-bounds" style="width:{{active_space.advanced.width*bounds_zoom}}px;height:{{active_space.advanced.height*bounds_zoom}}px;"></div>
<div class="wrapper"
style="transform:scale({{viewport_zoom}});transform-origin:0 0;width:{{active_space.width}}px;height:{{active_space.height}}px;background-image:url('{{active_space.background_uri}}');background-color:{{active_space.background_color}};margin-left:{{bounds_margin_horiz}}px;margin-top:{{bounds_margin_vert}}px" >
style="transform:scale({{viewport_zoom}});transform-origin:0 0;width:{{active_space.advanced.width}}px;height:{{active_space.advanced.height}}px;background-image:url('{{active_space.advanced.background_uri}}');background-color:{{active_space.advanced.background_color}};margin-left:{{bounds_margin_horiz}}px;margin-top:{{bounds_margin_vert}}px" >
<div v-repeat="a : active_space_artifacts"
v-class="text-editing:(editing_artifact_id==a._id && (a.view.major_type=='text' || a.view.major_type=='shape'))"
@@ -81,7 +81,7 @@
</div>
<div class="tl-controls">
<div class="btn btn-md btn-toggle btn-round" v-class="alt:a.player_view.state=='playing'" v-show="a.w>=200 || a.player_view.state!='playing'">
<div class="btn btn-md btn-toggle btn-round" v-class="alt:a.player_view.state=='playing'" v-show="a.board.w>=200 || a.player_view.state!='playing'">
<span class="btn-option play">
<span class="icon icon-controls-play"></span>
</span>
@@ -95,8 +95,8 @@
<span class="icon icon-controls-stop"></span>
</span>
<span class="tl-title" v-show="a.w>=250 && a.h>=150">{{a.view.filename}}</span>
<span class="tl-times" class="btn-group" v-show="a.w>=400 && a.h>=150">
<span class="tl-title" v-show="a.board.w>=250 && a.board.h>=150">{{a.view.filename}}</span>
<span class="tl-times" class="btn-group" v-show="a.board.w>=400 && a.board.h>=150">
<span class="btn btn-md btn-transparent no-p set-inpoint">{{a.player_view.current_time_string}} /</span>
<span class="btn btn-md btn-transparent no-p set-outpoint">{{a.player_view.total_time_string}}</span>
</span>

View File

@@ -198,7 +198,7 @@
<div id="space" v-cloak
v-if="active_view == 'space' && active_space_loaded"
class="section board active mouse-{{mouse_state}} tool-{{active_tool}}"
v-bind:style="{'background-color': active_space.background_color}"
v-bind:style="{'background-color': active_space.advanced.background_color}"
v-sd-droppable="handle_data_drop;active_space"
v-sd-whiteboard
v-on:scroll="handle_scroll"
@@ -206,16 +206,16 @@
<div id="space-clipboard" style="position:fixed;top:0;left:0;z-index:0;opacity:0;background-color:white"><textarea v-model="selected_artifacts_json" cols="2" rows="2" id="clipboard-ta" class="mousetrap"></textarea></div>
<div class="space-bounds" v-bind:style="{width: active_space.width*bounds_zoom + 'px', height: active_space.height*bounds_zoom + 'px', 'background-color': active_space.background_color}"></div>
<div class="space-bounds" v-bind:style="{width: active_space.advanced.width*bounds_zoom + 'px', height: active_space.advanced.height*bounds_zoom + 'px', 'background-color': active_space.advanced.background_color}"></div>
<div class="wrapper"
v-bind:style="{
transform: 'scale('+viewport_zoom+')',
'transform-origin': '0 0',
width: active_space.width + 'px',
height: active_space.height + 'px',
'background-image': (active_space.background_uri)?'url(' + active_space.background_uri + ')':'',
'background-color': ''+active_space.background_color,
width: active_space.advanced.width + 'px',
height: active_space.advanced.height + 'px',
'background-image': (active_space.advanced.background_uri)?'url(' + active_space.advanced.background_uri + ')':'',
'background-color': ''+active_space.advanced.background_color,
'margin-left': bounds_margin_horiz + 'px',
'margin-top': bounds_margin_vert + 'px'}" >
@@ -331,7 +331,7 @@
<source v-bind:src="a.payload_uri" v-bind:type="a.mime" v-if="a.payload_uri"/>
</audio>
<div class="timeline" v-show="a.h>=64 && a.w>=170" v-bind:style="{'background-image': 'url(' + a.payload_thumbnail_web_uri +')'}">
<div class="timeline" v-show="a.board.h>=64 && a.board.w>=170" v-bind:style="{'background-image': 'url(' + a.payload_thumbnail_web_uri +')'}">
<div class="tl-current-time" v-bind:style="{width: a.player_view.current_time_float*100 + '%'}"></div>
<div class="tl-inpoint" v-bind:style="{left: a.player_view.inpoint_float*100 + '%'}" v-if="a.player_view.inpoint_float>0.0"></div>
<div class="tl-outpoint" v-bind:style="{left: a.player_view.outpoint_float*100 + '%'}"></div>
@@ -352,13 +352,13 @@
<span class="icon icon-controls-stop"></span>
</span>
<span class="tl-title" v-show="a.w>=400">{{a.view.filename}}</span>
<span class="tl-title" v-show="a.board.w>=400">{{a.view.filename}}</span>
<span class="tl-times" class="btn-group">
<span class="btn btn-md btn-transparent no-p">{{a.player_view.current_time_string}}</span>
<span class="btn btn-md btn-transparent no-p" v-show="a.w>=170"> / {{a.player_view.total_time_string}}</span>
<span class="btn btn-md btn-transparent no-p" v-show="a.board.w>=170"> / {{a.player_view.total_time_string}}</span>
</span>
<span v-show="logged_in && a.w>=310">
<span v-show="logged_in && a.board.w>=310">
<a class="btn btn-xs btn-round btn-icon set-inpoint" title="Set Inpoint at Playhead">
<span class="icon icon-edge-left"></span>
</a>
@@ -464,7 +464,7 @@
<div v-if="active_space_loaded" v-cloak>
<div id="minimap"
v-bind:style="{width: ''+(active_space.width/minimap_scale)+'px', height: ''+(active_space.height/minimap_scale)+'px', bottom: '66px', right: '20px'}"
v-bind:style="{width: ''+(active_space.advanced.width/minimap_scale)+'px', height: ''+(active_space.advanced.height/minimap_scale)+'px', bottom: '66px', right: '20px'}"
v-if="active_space"
v-on:mousedown="handle_minimap_mousedown($event)"
v-on:touchstart="handle_minimap_mousedown($event)"
@@ -473,7 +473,7 @@
v-on:mouseleave="handle_minimap_mouseup($event)"
v-on:touchend="handle_minimap_mouseup($event)"
v-on:mouseup="handle_minimap_mouseup($event)">
<div v-for="a in active_space_artifacts" v-bind:style="{left: ''+(a.x/minimap_scale)+ 'px', top: ''+(a.y/minimap_scale) + 'px', width: ''+(a.w/minimap_scale)+ 'px', height: ''+(a.h/minimap_scale) + 'px'}"></div>
<div v-for="a in active_space_artifacts" v-bind:style="{left: ''+(a.board.x/minimap_scale)+ 'px', top: ''+(a.board.y/minimap_scale) + 'px', width: ''+(a.board.w/minimap_scale)+ 'px', height: ''+(a.board.h/minimap_scale) + 'px'}"></div>
<div class="window" v-bind:style="{left: ''+(scroll_left/minimap_scale) + 'px', top: ''+(scroll_top/minimap_scale)+ 'px', width: ''+(window_width/minimap_scale)+ 'px', height: ''+(window_height/minimap_scale) + 'px'}"></div>
</div>

View File

@@ -79,14 +79,14 @@
</div-->
<div class="" v-show="background_mode=='image'" v-if="active_space">
<div class="background-image" v-bind:style="{height: '233px', 'background-image':'url('+active_space.background_uri+')', 'margin': '6px', 'border-radius': '3px'}" v-if="active_space.background_uri && !space_background_uploading">
<div class="background-image" v-bind:style="{height: '233px', 'background-image':'url('+active_space.advanced.background_uri+')', 'margin': '6px', 'border-radius': '3px'}" v-if="active_space.advanced.background_uri && !space_background_uploading">
</div>
<div class="progress state-processing" v-if="space_background_uploading">
<div class="spinner"></div>
</div>
<div class="dialog-section no-b adapt" v-if="!active_space.background_uri && !space_background_uploading" v-on:touchstart="handle_touch_select_background_image()">
<div class="dialog-section no-b adapt" v-if="!active_space.advanced.background_uri && !space_background_uploading" v-on:touchstart="handle_touch_select_background_image()">
<label class="btn btn-xxl btn-transparent btn-icon">
<span class="icon icon-picture-upload"></span>
<input id="background-uploader" type="file" accept="image/*" v-on:change="handle_section_background_upload($event)">
@@ -94,9 +94,9 @@
<p>[[__("upload_background_caption")]]</p>
</div>
<div class="dialog-section no-p no-flex" v-if="active_space.background_uri">
<div class="dialog-section no-p no-flex" v-if="active_space.advanced.background_uri">
<div class="btn-cluster">
<label class="btn btn-transparent btn-block text-center" v-if="active_space.background_uri" v-on:touchstart="handle_touch_select_background_image()">
<label class="btn btn-transparent btn-block text-center" v-if="active_space.advanced.background_uri" v-on:touchstart="handle_touch_select_background_image()">
<input id="background-uploader" type="file" accept="image/*" v-on:chang="handle_section_background_upload($event)">
<span class="icon icon-picture-upload"></span>
<!-- Upload -->

View File

@@ -1,7 +1,7 @@
<div id="pick-mobile" v-if="active_space" class="dialog-section" v-show="opened_dialog=='mobile'">
<h4 class="dialog-title">Mobile Upload</h4>
<!--img v-if="active_space.edit_hash" v-bind:src="'/api/helper/qrcode/'+ active_space._id"-->
<img v-if="active_space.edit_hash" v-bind:src="'/api/helper/qrcode/'+ active_space._id" />
<p class="text-center">
Install the Spacedeck App on your phone and scan this QR code to upload photos, sound, video or text.

View File

@@ -76,7 +76,20 @@
{% include "./zones.html" %}
</div>
</div>
<div id="mobile-dialog" class="dropdown bottom light center static" v-bind:class="{open:opened_dialog=='mobile'}">
<div class="btn-collapse in">
<button class="btn btn-transparent btn-icon-labeled" v-bind:class="{open:opened_dialog=='mobile'}" v-on:click="open_dialog('mobile')" >
<span class="icon icon-device-mobile"></span>
<span class="icon-label">[[__("mobile")]]</span>
</button>
</div>
<div class="dialog mobile-search">
{% include "./pick-mobile.html" %}
</div>
</div>
<button class="btn btn-divider" v-show="logged_in"></button>
<div class="dropdown bottom light center" v-show="logged_in" v-bind:class="{open:opened_dialog=='background'}">

View File

@@ -9,7 +9,7 @@
<button v-on:click="add_zone()" class="btn btn-sm btn-primary">[[__("add_zone")]]</button>
</div>
<div class="dialog-section no-p" v-for="z in zones | orderBy 'order'" style="white-space: nowrap;text-align:left;cursor:pointer" v-on:click="zoom_to_zone(z)">
<div class="dialog-section no-p" v-for="z in zones | orderBy 'style.order'" style="white-space: nowrap;text-align:left;cursor:pointer" v-on:click="zoom_to_zone(z)">
<button class="btn btn-sm btn-transparent">{{{z.description}}}</button>
<button v-if="$index==current_zone_idx" v-on:click="sort_zone_up(z)" class="btn btn-sm btn-round btn-transparent btn-icon"><span class="icon icon-triangle-up"></span></button>
<button v-if="$index==current_zone_idx" v-on:click="sort_zone_down(z)" class="btn btn-sm btn-round btn-transparent btn-icon"><span class="icon icon-triangle-down"></span></button>

View File

@@ -13,8 +13,6 @@
<link type="text/css" rel="stylesheet" href="https://fast.fonts.net/cssapi/ee1a3484-4d98-4f9f-9f55-020a7b37f3c5.css"/>
<link rel="stylesheet" href="[[ '/stylesheets/style.css' | cdn ]]">
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twemoji/1.3.2/twemoji.min.js"></script>
<script>
@@ -22,13 +20,21 @@
window.browser_lang = '[[locale]]';
window.csrf_token = '[[csrf_token]]';
var ENV = {
name: 'development',
webHost: location.host,
webEndpoint: location.origin,
apiEndpoint: location.origin,
websocketsEndpoint: location.origin.replace("https:","wss:").replace("http:","ws:")
};
{% if process.env.NODE_ENV != "production" %}
var ENV = {
name: 'development',
webHost: "localhost:9000",
webEndpoint:"http://localhost:9000",
apiEndpoint: "http://localhost:9000",
websocketsEndpoint: "ws://localhost:9000"
};
{% endif %}
{% if subdomain_team %}
var subdomainTeam = [[ subdomain_team | json | safe ]];
{% else %}
var subdomainTeam = null;
{% endif %}
</script>
{% if process.env.NODE_ENV == "production" %}
@@ -69,8 +75,6 @@
<script minify src="/javascripts/spacedeck_directives.js"></script>
<script minify src="/javascripts/spacedeck_vue.js"></script>
{% endif %}
<script>if (window.module) module = window.module;</script>
</head>
<body id="main" v-bind:class="{'present-mode':present_mode,'modal-open':active_modal}" v-on:click="handle_body_click($event)">