Skip to content

Commit

Permalink
Nitro Sync 1.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
stayradiated committed Jun 23, 2012
1 parent f97716d commit d11d3cc
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 39 deletions.
Binary file added app/cog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 28 additions & 2 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
Get Nitro from stayradiated/nitro (github) &amp; rename app.html to index.html (replacing this file)<br>
Set app in ui.js to web
<html>
<head>
<title>Nitro Web App</title>
<link rel="stylesheet" type="text/css" href="success/css/style.css">
<style>
.paper-stack {
height: 335px;
}
.paper-stack p {
color: #555;
}
.paper-stack a {
color: #AE89E6;
text-decoration: none;
}
.paper-stack a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="paper-stack">
<h2>Under Maintanance.</h2>
<img src="cog.png">
<p>Hi. The Nitro Web App is currently under maintenance. We recommend that you use the <a href="https://chrome.google.com/webstore/detail/pjlaneabgdaemdklmeonicfiifmegija">Chrome extension</a>.</p>
</div>
</body>
</html>
Binary file modified app/success/bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/success/tick.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 10 additions & 20 deletions merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ emptyServer = {
order:0
}
},
scheduled:{
order:[],
time:{
order:0
}
},
length: 0
},
time: 0
Expand All @@ -39,10 +33,12 @@ emptyServer = {

mergeDB = function(server, client, callback) {

try {

msg(server.version)

// Check for version number
if(client.stats.version != "1.4") {
if(client.stats.version != '1.4' && client.stats.version != '1.4.2') {
// Add a task telling them to update...
var id = client.tasks.length
client.tasks[id] = {
Expand Down Expand Up @@ -71,15 +67,14 @@ mergeDB = function(server, client, callback) {
callback(client)
return
}
if(server.version !== "1.4") {
if(server.version !== "1.4" && server.version !== "1.4.2") {
upgradeDB(server)
}

msg(JSON.stringify(client, null, 2))
msg("CLIENT")
cleanDB(client)
msg("SERVER")
cleanDB(server)
msg("=============================")
msg(JSON.stringify(client, null, 2))

// ----------------------------
// CORE FUNCTIONS
Expand Down Expand Up @@ -190,13 +185,11 @@ mergeDB = function(server, client, callback) {
}

//Remove from List order
var index = server.lists.order.indexOf(id);
var index = server.lists.order.indexOf(Number(id));
if(index > -1) {
server.lists.order.splice(index, 1);
}

msg(JSON.stringify(server.lists.order))

//Deletes List
//server.lists.items[id] = {deleted: core.timestamp()};
server.lists.items[id] = {deleted: time};
Expand Down Expand Up @@ -424,7 +417,6 @@ mergeDB = function(server, client, callback) {
}

msg("Task '" + task + "' is being added to the server.");

core.task().add("New Task", _this.list)
server.tasks[task] = clone(_this)

Expand Down Expand Up @@ -618,10 +610,6 @@ mergeDB = function(server, client, callback) {

var mergedListOrder = mergeOrder(c, s);

msg(list)
msg(JSON.stringify(c));
msg(JSON.stringify(s));

server.lists.items[list].order = mergedListOrder[0];
server.lists.items[list].time.order = mergedListOrder[1];

Expand All @@ -633,6 +621,8 @@ mergeDB = function(server, client, callback) {

callback(server);

} catch(e) {}

}

// Fix the length of an object
Expand Down
18 changes: 6 additions & 12 deletions sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

console.info('Nitro Sync 1.4\nCopyright (C) 2012 Caffeinated Code\nBy George Czabania & Jono Cooper');
console.info('Nitro Sync 1.4.2\nCopyright (C) 2012 Caffeinated Code\nBy George Czabania & Jono Cooper');

settings = {
version: "1.4",
version: "1.4.2",
filename: 'nitro_data.json',
url: 'http://localhost:3000',
timeout: 180 // How long the server will wait for the user to authenticate Nitro.
url: 'http://localhost:3000'
}

// Node Packages
Expand Down Expand Up @@ -132,8 +131,6 @@ function authenticate(req, res) {
var user_token = req.param('token')
if(typeof user_token === 'string') user_token = JSON.parse(user_token)

console.log(JSON.stringify(user_token))

switch (req.param('service')) {

//
Expand All @@ -143,12 +140,9 @@ function authenticate(req, res) {
case "dropbox":
// Check user exists
if(users.dropbox.hasOwnProperty(user_token.oauth_token)) {
msg("Found user")
var user = users.dropbox[user_token.oauth_token]
if(user.token_secret === user_token.oauth_token_secret) {
msg("Token secret matches")
if(user.hasOwnProperty('uid')) {
msg("Verifed")
// Check token
dbox.access_token(user_token, function (status, access_token) {
// Token is good :D
Expand Down Expand Up @@ -221,9 +215,9 @@ function sync(req, res) {
getServer(service, user, function(server) {

if(server != 'error') {

var recievedData = decompress(JSON.parse(req.param('data')));

// Merge data
mergeDB(server, recievedData, function (server) {

Expand All @@ -240,7 +234,7 @@ function sync(req, res) {

require('http').get(options, function() {});
});

} else {

res.json("error");
Expand Down
131 changes: 126 additions & 5 deletions upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ cleanDB = function(d) {
order: 0
},
synced: false
},
smartlist: {
order: [],
time: {
order: 0
}
}
}

Expand All @@ -50,7 +56,7 @@ cleanDB = function(d) {
else tasks = clone(emptyServer.tasks)

// Find length
var length = 0
var length = -1
for(var k in tasks) {
if(typeof tasks[k] === 'object') {
if(Number(k) > length) length = Number(k)
Expand All @@ -59,19 +65,19 @@ cleanDB = function(d) {
length++
o.tasks.length = length
for(var i = 0; i < length; i++) {

o.tasks[i] = clone(defaults.task)
if(tasks.hasOwnProperty(i)) {
var _this = tasks[i]
} else {
o.tasks[i] = { deleted: 0 }
break
}

// Deleted
if(_this.hasOwnProperty('deleted')) {
if(isNumber(_this.deleted)) {
if(isNumber(_this.deleted) || isNumber(Number(_this.deleted))) {
o.tasks[i] = {
deleted: _this.deleted
deleted: Number(_this.deleted)
}
} else {
o.tasks[i] = {
Expand Down Expand Up @@ -199,8 +205,124 @@ cleanDB = function(d) {
}
}
}

// Lists
var lists
if(d.hasOwnProperty('lists')) lists = d.lists
else lists = clone(emptyServer.lists)

// Find length
length = -1
for(var k in lists.items) {
if(typeof lists.items[k] === 'object') {
if(Number(k) > length) length = Number(k)
}
}
length++
o.lists.items.length = length

var tempArray = ['today','next','logbook']
for(var i = 0; i < length; i++) {
tempArray.push(i)
}

for(var n = 0; n < tempArray.length; n++) {
i = tempArray[n]

// Create blank list
if (i == 'today' || i == 'next' || i == 'logbook') {
o.lists.items[i] = clone(defaults.smartlist)
if(lists.items.hasOwnProperty(i)) {
var _this = lists.items[i]
}
} else {
o.lists.items[i] = clone(defaults.list)
if(lists.items.hasOwnProperty(i)) {
var _this = lists.items[i]
} else {
o.tasks[i] = { deleted: 0 }
}
}

// Deleted
if(_this.hasOwnProperty('deleted')) {
if(isNumber(_this.deleted) || isNumber(Number(_this.deleted))) {
o.lists.items[i] = {
deleted: Number(_this.deleted)
}
} else {
o.lists.items[i] = {
deleted: 0
}
}
}

// Name
if(_this.hasOwnProperty('name')) {
if(typeof _this.name === 'string') {
o.lists.items[i].name = _this.name
} else if(isNumber(_this.name)) {
o.lists.items[i].name = _this.name.toString()
}
}


// Order
if(_this.hasOwnProperty('order')) {
if(isArray(_this.order)) {
for(var j = 0; j < _this.order.length; j++) {
if(o.tasks.hasOwnProperty(_this.order[j])) {
if(!o.tasks[_this.order[j]].hasOwnProperty('deleted')) {
o.lists.items[i].order.push(_this.order[j])
}
}
}
}
}

// Timestamps
if(_this.hasOwnProperty('time')) {
if(isObject(_this.time)) {
for(var j in o.lists.items[i].time) {
if(isNumber(_this.time[j])) {
o.lists.items[i].time[j] = _this.time[j]
} else {
var Dt = new Date(_this.time[j]).getTime()
if(isNumber(Dt)) {
o.lists.items[i].time[j] = Dt
}
}
}
}
}

// Synced
if(_this.hasOwnProperty('synced')) {
if(_this.synced === 'true') _this.synced = true
if(typeof _this.synced === 'boolean') {
o.lists.items[i].synced = _this.synced
}
}
}


// List order
for(var i = 0; i < lists.order.length; i++) {
var _this = lists.order[i]
if(o.lists.items.hasOwnProperty(_this)) {
if(!o.lists.items[_this].hasOwnProperty('deleted')) {
o.lists.order.push(_this)
}
}
}

// List Time
if(lists.hasOwnProperty('time')) {
o.lists.time = Number(lists.time)
}

d.tasks = o.tasks
d.lists = o.lists

}

Expand Down Expand Up @@ -260,7 +382,6 @@ upgradeDB = function(server) {
if(key !== 'length') {
var _this = lists.scheduled[key],
id = tasks.length
console.log(_this, id)
tasks[id] = $.extend(true, {}, _this)
_this = tasks[id]
_this.list = scheduledID
Expand Down

0 comments on commit d11d3cc

Please sign in to comment.