-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
verify action IDs #519
verify action IDs #519
Changes from all commits
e241673
4ba7c67
99947f6
b9b84d9
aef6950
21eed02
9dc15b3
8cbe997
bcf2cb2
1860817
42900a3
f1c976e
619e5b5
6d4287a
a839945
23a1685
7ecc216
d214fc6
bc06925
b8d208e
484e34d
3ef849b
6657998
613ba37
67d2390
a2ed355
308b33f
5b39bbe
4862ff6
c40378b
ffc741e
ee093a5
3516917
6846092
312a17f
581f587
4347cb1
f4e97c3
83b2bdb
16de8bc
8a623aa
e5bdcd2
91ad0ad
08fd1fb
21dbcbb
e0dd19f
60a9d48
eb27e16
5beccf0
a614836
e360c40
fa0b091
57e00d7
42ef45f
0385ef8
e1180d4
1a046c3
0a94773
e6cdb6b
2fb4760
8025d4a
adec480
8d81ed4
87e3887
4c56116
ae3b734
78f05ea
fb9bf68
8c49c2d
b645fd8
9d46d35
b3eda51
478f145
5f58852
bbae64a
a80b98e
82bf909
335aa30
3dd8211
93bbce7
18cc28e
4672afc
d9183fb
a5e5fc7
06608aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,7 +11,7 @@ var fs = require('fs'), | |||||
path = require('path'), | ||||||
needle = require('needle'), | ||||||
common = require('./../../common'), | ||||||
files = require('./storage'), | ||||||
storage = require('./../../utils/storage'), | ||||||
Emitter = require('events').EventEmitter; | ||||||
|
||||||
var system = common.system, | ||||||
|
@@ -26,6 +26,7 @@ var config = common.config, | |||||
url = protocol + '://' + host; | ||||||
|
||||||
var UPLOAD_SERVER = url + '/upload/upload'; | ||||||
const { v4: uuidv4 } = require('uuid'); | ||||||
|
||||||
var em, | ||||||
cp; | ||||||
|
@@ -36,6 +37,33 @@ var path_arg, | |||||
// check_pending_files is used to resume any files that might been pending. It's called from | ||||||
// filesagent/providers/network. | ||||||
|
||||||
var run_stored = (host, cb) => { | ||||||
if (host != 'solid.preyproject.com') return; | ||||||
|
||||||
storage.do('all', { type: 'files' }, (err, files) => { | ||||||
if (err) return cb(new Error('Error retrieving file from local database')) | ||||||
|
||||||
var count = Object.keys(files).length; | ||||||
if (count <= 0) | ||||||
return; | ||||||
logger.warn('Re-uploading ' + count + ' pending files.'); | ||||||
|
||||||
files.forEach(file => { | ||||||
var opts = { | ||||||
path: file.path, | ||||||
user: file.user, | ||||||
name: file.name, | ||||||
size: file.size, | ||||||
file_id: file.id, | ||||||
attempts: file.attempts, | ||||||
resumable: file.resumable | ||||||
} | ||||||
let id = uuidv4(); | ||||||
exports.start(id, opts, cb); | ||||||
}); | ||||||
}) | ||||||
} | ||||||
|
||||||
var retrieve_file_as_user = function(options, cb) { | ||||||
if (os_name == 'windows') { | ||||||
path_arg = path.resolve(options.path); | ||||||
|
@@ -61,11 +89,13 @@ var retrieve_file_as_user = function(options, cb) { | |||||
} | ||||||
logger.info("Ran as user: " + out); | ||||||
if (out.indexOf("File succesfuly uploaded") != -1) { | ||||||
files.del(options.file_id); | ||||||
logger.debug('Removing file_id from DB: ' + options.file_id); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
storage.do('del', { type: 'files', id: options.file_id }); | ||||||
return; | ||||||
} | ||||||
if (out.includes("EPIPE") || out.includes("EACCES")) { | ||||||
files.update(options.file_id, options.path, options.size, options.user, options.name, options.resumable, function(err) { | ||||||
let resumable_value = options.resumable == 1 ? 0 : 1; | ||||||
storage.do('update', { type: 'files', id: file_id, columns: 'resumable', values: resumable_value }, (err) => { // resumable | ||||||
if (err) logger.error("Database update error"); | ||||||
logger.info("Resume file option activated for ID: " + options.file_id); | ||||||
}); | ||||||
|
@@ -74,10 +104,12 @@ var retrieve_file_as_user = function(options, cb) { | |||||
} | ||||||
|
||||||
exports.check_pending_files = function() { | ||||||
files.run_stored(host); | ||||||
run_stored(host, (err) => { | ||||||
if (err) logger.error(err.message) | ||||||
}); | ||||||
} | ||||||
|
||||||
exports.start = function(options, cb) { | ||||||
exports.start = function(id, options, cb) { | ||||||
|
||||||
var url = UPLOAD_SERVER + '?uploadID=' + options.file_id; | ||||||
// Make a call to get the last byte processed by the upload server | ||||||
|
@@ -88,25 +120,44 @@ exports.start = function(options, cb) { | |||||
return; | ||||||
} | ||||||
if (res.statusCode == 404) { | ||||||
files.del(options.file_id); | ||||||
logger.debug('Removing file_id from DB: ' + options.file_id); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
storage.do('del', { type: 'files', id: options.file_id }); | ||||||
return; | ||||||
} | ||||||
var data = JSON.parse(res.body); | ||||||
var file_status = JSON.parse(res.body).Status | ||||||
options.total = data.Total; | ||||||
|
||||||
if (file_status == 0 || file_status == 4) { // File in progress(0) or Pending(4) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Es preferible usar el |
||||||
files.exist(options.file_id, function(err, exist) { | ||||||
if (!exist) { | ||||||
options.resumable = false; | ||||||
storage.do('query', {type: 'files', column: "id", data: options.file_id,}, (err, files) => { | ||||||
if (files.length == 0) { | ||||||
options.resumable = 0; | ||||||
options.total = 0; | ||||||
files.store(options.file_id, options.path, options.size, options.user, options.name, options.resumable); | ||||||
retrieve_file_as_user(options); | ||||||
|
||||||
var data = { | ||||||
name: options.name, | ||||||
path: options.path, | ||||||
size: options.size, | ||||||
user: options.user, | ||||||
attempts: 0, | ||||||
resumable: options.resumable | ||||||
} | ||||||
|
||||||
logger.debug('Storing file_id in DB: ' + options.file_id); | ||||||
storage.do('set', {type: 'files', id: options.file_id, data: data}, () => { | ||||||
retrieve_file_as_user(options); | ||||||
}); | ||||||
|
||||||
} else { | ||||||
setTimeout(function() { | ||||||
if (options.resumable) { | ||||||
files.update(options.file_id, options.path, options.size, options.user, options.name, options.resumable, function(err) { | ||||||
var file_attempts = files[0].attempts; | ||||||
if (file_attempts >= 3) { | ||||||
logger.info('File ' + options.file_id + 'has no more attempts, deleting...'); | ||||||
return; | ||||||
} | ||||||
|
||||||
if (options.resumable == 1) { | ||||||
storage.do('update', { type: 'files', id: file_id, columns: ['attempts', 'resumable'], values: [file_attempts + 1, 0] }, (err) => { // resumable | ||||||
if (err) logger.error("Database update error"); | ||||||
logger.info("Resume file option deactivated for ID: " + options.file_id); | ||||||
retrieve_file_as_user(options); | ||||||
|
@@ -121,15 +172,17 @@ exports.start = function(options, cb) { | |||||
logger.debug("File already uploaded, deleting from db..."); | ||||||
else | ||||||
logger.debug("File cancelled or with an error, deleting from db..."); | ||||||
files.del(options.file_id); | ||||||
|
||||||
logger.info('Removing file_id from DB: ' + options.file_id); | ||||||
storage.do('del', { type: 'files', id: options.file_id }); | ||||||
return; | ||||||
} | ||||||
}) | ||||||
|
||||||
em = em || new Emitter(); | ||||||
|
||||||
if (cb) cb(null, em); | ||||||
em.emit('end'); | ||||||
em.emit('end', id); | ||||||
} | ||||||
|
||||||
exports.stop = function() { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seria bueno por temas de estandares pasar todas las variables que estan en
snake_case
acamelCase
. Entiendo que es algo que se puede ir haciendo poco a poco.