Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F10361166
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/chip-types/uploader.js b/lib/chip-types/uploader.js
deleted file mode 100644
index aa9e02ad..00000000
--- a/lib/chip-types/uploader.js
+++ /dev/null
@@ -1,39 +0,0 @@
-var fs = require("fs");
-var fse = require('fs-extra');
-var path = require('path');
-var uid = require('uid');
-
-module.exports = function(uploader, dispatcher, dependencies){
- this.save_file = function(payload, upload_path) {
- var photos = payload["photos"];
-
- if(photos.hapi)
- if(photos.hapi.filename=='')
- return [{ upload_path: "./resources/default/book.png"}];
-
- var parent_tmp = module.parent;
- var parent = null;
- while(parent_tmp){
- parent=parent_tmp;
- parent_tmp = parent_tmp.parent;
- }
-
- var upload_path_abs = path.resolve(parent.filename, "../"+upload_path);
-
- if (!fs.existsSync(upload_path_abs)) {
- fse.mkdirs(upload_path_abs, function(err) {
- if (err) return console.error(err);
- });
- }
-
- if (!photos[0]) {
- photos = [photos];
- }
- for (var i in photos) {
- var upload_path_with_filename = upload_path_abs + "/" + photos[i].hapi.filename;
- photos[i].pipe(fs.createWriteStream(upload_path_with_filename));
- }
-
- }
-
-}
diff --git a/lib/core-services/file-manager.js b/lib/core-services/file-manager.js
index b821e1a4..c88d6382 100644
--- a/lib/core-services/file-manager.js
+++ b/lib/core-services/file-manager.js
@@ -1,58 +1,107 @@
var Promise = require("bluebird");
var UUIDGenerator = require("uid");
var path = require('path');
var fse = require("fs-extra");
var fs = require("fs");
+var ResourceRepresentation = require("../chip-types/resource-representation.js");
/**
* Manages files
* @class
*/
var FileManager = new function() {
this.name = "files";
- this.save_file = function(dispatcher, files, upload_path) {
+ this.save_file = function(dispatcher, files_data, upload_path) {
+ var files = files_data.files;
+ var owner = files_data.owner;
- if(!upload_path){
- upload_path = "./resources/";
+ if (!upload_path) {
+ upload_path = "./uploaded_files/";
}
- if(files.hapi)
- if(files.hapi.filename=='')
- return [{ upload_path: "./resources/default/book.png"}];
-
- var upload_path_abs = path.resolve(root_path(), "../"+upload_path);
+ var upload_path_abs = path.resolve(root_path(), "../" + upload_path);
if (!fs.existsSync(upload_path_abs)) {
fse.mkdirs(upload_path_abs, function(err) {
if (err) return console.error(err);
});
}
if (!files[0]) {
files = [files];
}
+
+ var saved_files_data = [];
+
for (var i in files) {
- var upload_path_with_filename = upload_path_abs + "/" + files[i].hapi.filename;
+ var newID = UUIDGenerator(10);
+
+ var upload_path_with_filename = upload_path_abs + "/" + newID;
files[i].pipe(fs.createWriteStream(upload_path_with_filename));
+
+ var hapi_filename = files[i].hapi.filename;
+ var file_details = {
+ sealious_name: newID,
+ original_name: hapi_filename.substr(0, hapi_filename.lastIndexOf('.')),
+ extension: hapi_filename.split(".").reverse()[0],
+ path: upload_path,
+ owner: owner
+ }
+
+ var file_data = {
+ sealious_id: newID,
+ body: file_details
+ };
+
+ dispatcher.datastore.insert("files", file_data, {});
+ saved_files_data.push(file_data);
}
- return files;
+ return saved_files_data;
+ }
+
+ this.diff = function(dispatcher, file) {
+
+ }
+
+ this.get_list = function(dispatcher, owner) {
+ var query = {
+ "body.owner": owner
+ };
+ Sealious.Logger.info("List for owner '" + owner +"' has been created");
+ return this.find(dispatcher, query);
+ }
+
+ this.find = function(dispatcher, query) {
+ return new Promise(function(resolve, reject) {
+ dispatcher.datastore.find("files", query)
+ .then(function(documents) {
+ var parsed_documents = documents.map(function(document) {
+ return new ResourceRepresentation(document).getData()
+ });
+ resolve(parsed_documents);
+ })
+ })
+ }
+ this.change_name = function(dispatcher, sealious_name, new_name) {
+ return dispatcher.datastore.update("files", {sealious_id: sealious_name }, { $set: { "body.original_name":new_name} });
+
}
var root_path = function() {
var parent_tmp = module.parent;
var parent = null;
- while(parent_tmp){
- parent=parent_tmp;
+ while (parent_tmp) {
+ parent = parent_tmp;
parent_tmp = parent_tmp.parent;
}
return parent.filename;
}
}
//wersjonowanie, historia dostępu, przetrzymywanie poprzednich wersji
module.exports = FileManager;
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Nov 8, 11:47 (16 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1034540
Default Alt Text
(5 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment