Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
PUBLIC
/
surfer-okd
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 7bb99aff
authored
Sep 08, 2015
by
Johannes Zellner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use 222 status code to indicate folder listing and use stdout only for data
1 parent
b9ad5d91
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
12 deletions
app.js
cli/actions.js
cli/surfer.js
package.json
src/files.js
app.js
View file @
7bb99af
...
...
@@ -15,6 +15,7 @@ var express = require('express'),
cookieParser
=
require
(
'cookie-parser'
),
lastMile
=
require
(
'connect-lastmile'
),
multipart
=
require
(
'./src/multipart'
),
mkdirp
=
require
(
'mkdirp'
),
auth
=
require
(
'./src/auth.js'
),
files
=
require
(
'./src/files.js'
)(
path
.
resolve
(
__dirname
,
process
.
argv
[
2
]
||
'files'
));
...
...
@@ -49,6 +50,9 @@ var server = app.listen(3000, function () {
var
host
=
server
.
address
().
address
;
var
port
=
server
.
address
().
port
;
var
basePath
=
path
.
resolve
(
__dirname
,
process
.
argv
[
2
]
||
'files'
);
mkdirp
.
sync
(
basePath
);
console
.
log
(
'Surfer listening at http://%s:%s'
,
host
,
port
);
console
.
log
(
'Using base path'
,
path
.
resolve
(
__dirname
,
process
.
argv
[
2
]
||
'files'
)
);
console
.
log
(
'Using base path'
,
basePath
);
});
\ No newline at end of file
cli/actions.js
View file @
7bb99af
...
...
@@ -10,6 +10,7 @@ var superagent = require('superagent'),
readlineSync
=
require
(
'readline-sync'
),
async
=
require
(
'async'
),
fs
=
require
(
'fs'
),
request
=
require
(
'request'
),
url
=
require
(
'url'
),
path
=
require
(
'path'
);
...
...
@@ -27,7 +28,7 @@ function checkConfig() {
gQuery
=
{
username
:
config
.
username
(),
password
:
config
.
password
()
};
console
.
log
(
'Using server %s'
,
config
.
server
().
yellow
);
console
.
error
(
'Using server %s'
,
config
.
server
().
yellow
);
}
function
collectFiles
(
filesOrFolders
)
{
...
...
@@ -110,20 +111,40 @@ function put(filePath, otherFilePaths, options) {
function
get
(
filePath
)
{
checkConfig
();
superagent
.
get
(
config
.
server
()
+
API
+
filePath
).
query
(
gQuery
).
end
(
function
(
error
,
result
)
{
if
(
error
&&
error
.
status
===
401
)
return
console
.
log
(
'Login failed'
);
if
(
error
&&
error
.
status
===
404
)
return
console
.
log
(
'No such file or directory'
);
if
(
error
)
return
console
.
log
(
'Failed'
,
result
?
result
.
body
:
error
);
// if no argument provided, fetch root
filePath
=
filePath
||
'/'
;
request
.
get
(
config
.
server
()
+
API
+
filePath
,
{
qs
:
gQuery
},
function
(
error
,
result
,
body
)
{
if
(
error
)
return
console
.
error
(
error
);
if
(
result
.
statusCode
===
401
)
return
console
.
log
(
'Login failed'
);
if
(
result
.
statusCode
===
404
)
return
console
.
log
(
'No such file or directory'
);
if
(
result
.
body
&&
result
.
body
.
entries
)
{
// 222 indicates directory listing
if
(
result
.
statusCode
===
222
)
{
console
.
log
(
'Files:'
);
result
.
body
.
entries
.
forEach
(
function
(
entry
)
{
JSON
.
parse
(
body
)
.
entries
.
forEach
(
function
(
entry
)
{
console
.
log
(
'\t %s'
,
entry
);
});
}
else
{
console
.
log
(
result
.
text
);
console
.
log
(
body
);
}
});
// var req = superagent.get(config.server() + API + filePath);
// req.query(gQuery);
// req.end(function (error, result) {
// if (error && error.status === 401) return console.log('Login failed');
// if (error && error.status === 404) return console.log('No such file or directory');
// if (error) return console.log('Failed', result ? result.body : error);
// if (result.body && result.body.entries) {
// console.log('Files:');
// result.body.entries.forEach(function (entry) {
// console.log('\t %s', entry);
// });
// } else {
// req.pipe(process.stdout);
// }
// });
}
function
del
(
filePath
)
{
...
...
cli/surfer.js
View file @
7bb99af
...
...
@@ -19,7 +19,7 @@ program.command('put <file> [files...]')
.
description
(
'Put a file'
)
.
action
(
actions
.
put
);
program
.
command
(
'get'
)
program
.
command
(
'get
[file]
'
)
.
description
(
'Get a file or directory'
)
.
action
(
actions
.
get
);
...
...
package.json
View file @
7bb99af
...
...
@@ -35,6 +35,7 @@
"passport"
:
"^0.2.2"
,
"passport-ldapjs"
:
"^1.0.2"
,
"readline-sync"
:
"^1.2.19"
,
"request"
:
"^2.61.0"
,
"safetydance"
:
"0.0.16"
,
"superagent"
:
"^1.2.0"
,
"underscore"
:
"^1.8.3"
...
...
src/files.js
View file @
7bb99af
...
...
@@ -54,7 +54,7 @@ function copyFile(source, target, cb) {
}
function
getAbsolutePath
(
filePath
)
{
var
absoluteFilePath
=
path
.
resolve
(
gBasePath
,
filePath
);
var
absoluteFilePath
=
path
.
resolve
(
path
.
join
(
gBasePath
,
filePath
)
);
if
(
absoluteFilePath
.
indexOf
(
gBasePath
)
!==
0
)
return
null
;
return
absoluteFilePath
;
...
...
@@ -71,7 +71,7 @@ function get(req, res, next) {
debug
(
'get'
,
absoluteFilePath
);
if
(
result
.
isFile
())
return
res
.
sendFile
(
absoluteFilePath
);
if
(
result
.
isDirectory
())
return
res
.
status
(
2
00
).
send
({
entries
:
fs
.
readdirSync
(
absoluteFilePath
)
});
if
(
result
.
isDirectory
())
return
res
.
status
(
2
22
).
send
({
entries
:
fs
.
readdirSync
(
absoluteFilePath
)
});
return
next
(
new
HttpError
(
500
,
'unsupported type'
));
});
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment