mirror of
https://github.com/spacedeck/spacedeck-open.git
synced 2025-12-16 01:47:30 +01:00
Port Backend to SQLite/Sequelize (removes MongoDB), Support Electron (#14)
* The MongoDB/Mongoose data storage is removed in favor of Sequelize. This abstracts over SQLite or RDBMs like PostgreSQL and MSSQL. The default is SQLite, which significantly simplifies deployments in end-user environments. * As Spacedeck now has no more mandatory server dependencies, we can wrap it in Electron and ship it as a desktop application. * Removes docker-compose.yml * First version of import UI
This commit is contained in:
@@ -5,7 +5,12 @@ const config = require('config')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
require('../models/schema')
|
||||
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) {
|
||||
@@ -54,8 +59,8 @@ module.exports = {
|
||||
let artifacts = JSON.parse(fs.readFileSync(importDir+'/'+space._id+'_artifacts.json'))
|
||||
console.log('[import] space',space._id,'artifacts:',artifacts.length)
|
||||
|
||||
let q = {_id: space._id}
|
||||
space.creator = user._id
|
||||
//let q = {where: {_id: space._id}}
|
||||
space.creator_id = user._id
|
||||
delete space.__v
|
||||
|
||||
// transplant homefolder
|
||||
@@ -64,17 +69,35 @@ module.exports = {
|
||||
space.parent_space_id = user.home_folder_id
|
||||
}
|
||||
|
||||
Space.findOneAndUpdate(q, space, {upsert: true}, function(err,res) {
|
||||
if (err) console.log("[import] space upsert err:",err)
|
||||
})
|
||||
// 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.creator = user._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
|
||||
@@ -92,8 +115,10 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
Artifact.findOneAndUpdate(q, a, {upsert: true}, function(err,res) {
|
||||
if (err) console.log("[import] artifact upsert err:",err)
|
||||
db.packArtifact(a)
|
||||
|
||||
db.Artifact.create(a).error(function(err) {
|
||||
console.error("[import] artifact upsert err:",err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user