Skip to content

Commit

Permalink
merged origin/experimental branch
Browse files Browse the repository at this point in the history
  • Loading branch information
remyla committed Nov 30, 2016
2 parents de61f31 + 0657430 commit 52f87cb
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 37 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,26 @@ A PHP server to run in a Apache environment. Generic key-value data model, simpl

## py and js
The Python and Javascript libraries to access the server remotely, to interface its methods and process the JSON results using the native language objects.
* Setup a scripting environment using this [guide](https://github.com/remyla/damas-core/wiki/Scripting)
* The documentation of the methods is available in the [API Reference](https://github.com/remyla/damas-core/wiki/API)

# Usage
Choose a server to run (either the Php or the NodeJS server). Refer to the README.md files in the servers folders for the installation instructions. Then use the Python or Javascript libraries to access it, of which instructions can be found in the wiki.
Choose a server to run (either the Php or the NodeJS server). Refer to the README.md files in the servers folders for the installation instructions. Then use the Python or Javascript libraries to access it, of which instructions can be found in the [Wiki](https://github.com/remyla/damas-core/wiki) or install one of the interfaces available (see below). Your feedback is highly welcome.

# Related Links

http://damas-software.org is a website which presents the projects related to damas-core

http://dabox.io is collaborative platform for architecture using damas-core as backend

https://github.com/PRIMCODE/damas-flow is a flow graph interface based on the NodeJS server implementation which is being created since April 2015.
https://github.com/PRIMCODE/damas-flow is a web flow graph interface based on the NodeJS server implementation which is being created since April 2015.

http://primcode.com PRIMCODE is the company behind the development, the distribution and the maintenance of damas-core
https://github.com/PRIMCODE/damas-dashboard is a web control center based on the NodeJS server implementation being developped since summer 2016, usable but not well packaged and documented yet. Get in touch if interested.

http://primcode.com PRIMCODE is the company behind the development, the distribution and the maintenance of damas-core

# License
GPL License(GPLV3)

Copyright(c) 2015 Remy Lalanne remy@primcode.com
Copyright(c) 2016 Remy Lalanne remy@primcode.com

damas-core is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
26 changes: 26 additions & 0 deletions cli/damas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ damas_update() {
fi
}

damas_stats() {
local bytes=`stat -c%s $1`
local mtime=`stat -c%Y $1`000
RES=$(curl -ks -X PUT -H "$AUTH" -H "$JSON" \
-d '{"_id":"/'$1'","file_size":'$bytes',"file_mtime":'$mtime'}' \
$URL'update/')
}

damas_remove() {
get_ids $@
RES=$(curl -ks -X DELETE -H "$AUTH" -H "$JSON" -d "$IDS" $URL'delete/')
Expand Down Expand Up @@ -258,6 +266,11 @@ case $ACTION in
;;
--help)
echo "COMMANDS"
echo ""
echo " create"
echo " <json>"
echo " create node(s) giving a JSON string as input (see examples below)"
echo " add"
echo " [-h] [-j <json>] <file>"
echo " create a new node for the specified file"
Expand Down Expand Up @@ -301,6 +314,14 @@ case $ACTION in
echo " remove authorization token"
echo " init"
echo " make your directory and subdirectories available for damas"
echo " stats"
echo " <file>"
echo " read stats and update file_mtime and file_size keys of file"
echo ""
echo "EXAMPLES"
echo ""
echo " create an arbitrary node giving a JSON"
echo " damas create '{\"#parent\":\"value\",\"comment\":\"created with cli\"}'"
exit 0
;;
Expand Down Expand Up @@ -382,6 +403,11 @@ case $ACTION in
damas_update $@
;;
stats)
auth
damas_stats $@
;;
remove)
auth
damas_remove $@
Expand Down
1 change: 1 addition & 0 deletions server-nodejs/db/mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = function (conf) {

var mongo = require('mongodb');
var ObjectID = mongo.ObjectID;
require('./utils');

/*
* Initialize the connection.
Expand Down
28 changes: 28 additions & 0 deletions server-nodejs/db/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

/*
* Polyfill for the native Object.assign() method
* Source: MDN
*/
if (typeof Object.assign != 'function') {
Object.assign = function (target) {
'use strict';
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}

target = Object(target);
for (var index = 1; index < arguments.length; index++) {
var source = arguments[index];
if (source != null) {
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
}
return target;
};
}


2 changes: 1 addition & 1 deletion server-nodejs/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<script type="text/javascript">//<![CDATA[
document.addEventListener('DOMContentLoaded', function() {
document.querySelector('#title').innerHTML = window.location.host;
document.querySelector('#srv_py').innerHTML = window.location+'api/';
document.querySelector('#srv_py').innerHTML = window.location+'api';
document.querySelector('#srv_js').innerHTML = window.location+'damas.js';
});
</script>
Expand Down
64 changes: 34 additions & 30 deletions server-nodejs/routes/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,40 @@ module.exports = function (app, routes) {
return httpStatus(res, 500, 'Upload');
}
//var sha1 = checksum.digest('hex');
var node = {
'#parent': path,
author: req.user.username,
comment: req.body.comment,
file_size: file.size,
'origin': 'online',
//sha1: sha1,
time: Date.now()
};
db.create([node], function(err,nodes){
db.read([path], function ( err, nodes){
var node = {
'_id': path,
author: req.user.username,
comment: req.body.comment,
file_size: file.size,
'origin': 'online',
//sha1: sha1,
time: Date.now()
};
if (nodes[0] === null) {
db.create([node], function(err,nodes){
return httpStatus(res, 201, nodes[0]);
});
}
else {
db.update([node], function(err,nodes){
return httpStatus(res, 201, nodes[0]);
});
}
fs.stat(dest, function(err, stats){
var node = {
'#parent': path,
author: req.user.username,
comment: req.body.comment,
file_mtime: stats.mtime.getTime(),
file_size: file.size,
'origin': 'online',
//sha1: sha1,
time: Date.now()
};
db.create([node], function(err,nodes){
db.read([path], function ( err, nodes){
var node = {
'_id': path,
author: req.user.username,
comment: req.body.comment,
file_mtime: stats.mtime.getTime(),
file_size: file.size,
'origin': 'online',
//sha1: sha1,
time: Date.now()
};
if (nodes[0] === null) {
db.create([node], function(err,nodes){
return httpStatus(res, 201, nodes[0]);
});
}
else {
db.update([node], function(err,nodes){
return httpStatus(res, 201, nodes[0]);
});
}
});
});
});
});
Expand Down

0 comments on commit 52f87cb

Please sign in to comment.