Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7317711
file-manager.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
file-manager.js
View Options
var
Promise
=
require
(
"bluebird"
);
var
UUIDGenerator
=
require
(
"uid"
);
var
path
=
require
(
'path'
);
var
fse
=
require
(
"fs-extra"
);
var
fs
=
require
(
"fs"
);
var
Sealious
=
require
(
"sealious"
);
/**
* Manages files
* @class
*/
var
root_path
=
function
(){
var
parent_tmp
=
module
.
parent
;
var
parent
=
null
;
while
(
parent_tmp
)
{
parent
=
parent_tmp
;
parent_tmp
=
parent_tmp
.
parent
;
}
return
parent
.
filename
;
}
var
FileManager
=
new
function
(
upload_path
){
this
.
name
=
"files"
;
if
(
!
upload_path
)
{
upload_path
=
"./uploaded_files/"
;
}
var
upload_path_abs
=
path
.
resolve
(
root_path
(),
"../"
+
upload_path
);
this
.
save_file
=
function
(
file
,
upload_path
){
if
(
!
fs
.
existsSync
(
upload_path_abs
))
{
fse
.
mkdirs
(
upload_path_abs
,
function
(
err
){});
}
var
newID
=
UUIDGenerator
(
10
);
var
upload_path_with_sealious_name
=
upload_path_abs
+
"/"
+
newID
;
fs
.
writeFile
(
upload_path_with_sealious_name
,
file
.
data
,
function
(
err
,
data
){
if
(
err
)
{
throw
(
err
);
}
});
var
file_database_entry
=
{
original_name
:
file
.
filename
,
creation_context
:
file
.
context
,
id
:
newID
,
mime_type
:
file
.
mime
,
}
return
Sealious
.
Datastore
.
insert
(
"files"
,
file_database_entry
,
{})
.
then
(
function
(){
return
Promise
.
resolve
({
id
:
newID
,
filename
:
file
.
filename
});
})
}
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
(
context
,
query
){
return
Sealious
.
Datastore
.
find
(
"files"
,
query
)
.
then
(
function
(
documents
){
var
parsed_documents
=
documents
.
map
(
function
(
document
){
var
ret
=
Sealious
.
File
.
from_db_entry
(
document
);
ret
.
path_on_hdd
=
upload_path
+
ret
.
id
;
return
ret
;
});
return
Promise
.
resolve
(
parsed_documents
);
})
}
this
.
change_name
=
function
(
dispatcher
,
sealious_name
,
new_name
){
return
Sealious
.
Datastore
.
update
(
"files"
,
{
sealious_id
:
sealious_name
},
{
$set
:
{
"body.original_name"
:
new_name
}
});
}
this
.
delete
=
function
(
dispatcher
,
query
){
}
}
//wersjonowanie, historia dostępu, przetrzymywanie poprzednich wersji
module
.
exports
=
FileManager
;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Jul 13, 04:59 (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
818593
Default Alt Text
file-manager.js (2 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment