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 552d44bb
authored
May 17, 2018
by
Johannes Zellner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make folder listing a global setting
1 parent
f2f2b693
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
17 deletions
.gitignore
frontend/404.html
frontend/js/app.js
frontend/welcome.html
server.js
.gitignore
View file @
552d44b
node_modules/
files/
.users.json
.config.json
frontend/404.html
0 → 100644
View file @
552d44b
<html>
<head>
<title>
Surfer - File not found
</title>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
>
<link
rel=
"stylesheet"
href=
"/_admin/css/style.css"
>
</head>
<body>
<div
class=
"wrapper"
>
<div
class=
"content"
>
<h2>
Surfer
</h2>
<p>
File not found
</p>
</div>
</div>
</body>
</html>
frontend/js/app.js
View file @
552d44b
...
...
@@ -211,7 +211,9 @@ var app = new Vue({
},
onOptionsMenu
:
function
(
command
)
{
if
(
command
===
'folderListing'
)
{
console
.
log
(
'Not implemented'
);
superagent
.
put
(
'/api/settings'
).
send
({
folderListingEnabled
:
this
.
folderListingEnabled
}).
query
({
access_token
:
localStorage
.
accessToken
}).
end
(
function
(
error
)
{
if
(
error
)
console
.
error
(
error
);
});
}
else
if
(
command
===
'about'
)
{
this
.
$msgbox
({
title
:
'About Surfer'
,
...
...
@@ -337,6 +339,12 @@ getProfile(localStorage.accessToken, function (error) {
if
(
error
)
return
console
.
error
(
error
);
loadDirectory
(
window
.
location
.
hash
.
slice
(
1
));
superagent
.
get
(
'/api/settings'
).
query
({
access_token
:
localStorage
.
accessToken
}).
end
(
function
(
error
,
result
)
{
if
(
error
)
console
.
error
(
error
);
app
.
folderListingEnabled
=
!!
result
.
body
.
folderListingEnabled
;
});
});
$
(
window
).
on
(
'hashchange'
,
function
()
{
...
...
frontend/welcome.html
View file @
552d44b
<html>
<head>
<title>
Surfer
</title>
<title>
Surfer
- Welcome
</title>
<
link
rel=
"stylesheet"
href=
"/_admin/css/style.css
"
>
<
meta
name=
"viewport"
content=
"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no
"
>
<link
rel=
"stylesheet"
href=
"/_admin/css/style.css"
>
</head>
<body>
...
...
server.js
View file @
552d44b
...
...
@@ -7,17 +7,58 @@ var express = require('express'),
morgan
=
require
(
'morgan'
),
passport
=
require
(
'passport'
),
path
=
require
(
'path'
),
fs
=
require
(
'fs'
),
compression
=
require
(
'compression'
),
session
=
require
(
'express-session'
),
bodyParser
=
require
(
'body-parser'
),
cookieParser
=
require
(
'cookie-parser'
),
lastMile
=
require
(
'connect-lastmile'
),
HttpError
=
require
(
'connect-lastmile'
).
HttpError
,
HttpSuccess
=
require
(
'connect-lastmile'
).
HttpSuccess
,
multipart
=
require
(
'./src/multipart'
),
mkdirp
=
require
(
'mkdirp'
),
auth
=
require
(
'./src/auth.js'
),
serveIndex
=
require
(
'serve-index'
),
files
=
require
(
'./src/files.js'
)(
path
.
resolve
(
__dirname
,
process
.
argv
[
2
]
||
'files'
));
var
rootFolder
=
path
.
resolve
(
__dirname
,
process
.
argv
[
2
]
||
'files'
);
var
configFile
=
path
.
resolve
(
__dirname
,
process
.
argv
[
3
]
||
'./config.json'
);
// Ensure the root folder exists
mkdirp
.
sync
(
rootFolder
);
var
config
=
{
folderListingEnabled
:
true
};
function
getSettings
(
req
,
res
,
next
)
{
res
.
send
({
folderListingEnabled
:
!!
config
.
folderListingEnabled
});
}
function
setSettings
(
req
,
res
,
next
)
{
if
(
typeof
req
.
body
.
folderListingEnabled
===
'undefined'
)
return
next
(
new
HttpError
(
400
,
'missing folderListingEnabled boolean'
));
config
.
folderListingEnabled
=
!!
req
.
body
.
folderListingEnabled
;
fs
.
writeFile
(
configFile
,
JSON
.
stringify
(
config
),
function
(
error
)
{
if
(
error
)
return
next
(
new
HttpError
(
500
,
'unable to save settings'
));
next
(
new
HttpSuccess
(
201
,
{}));
});
}
// Load the config file
try
{
config
=
require
(
configFile
);
}
catch
(
e
)
{
if
(
e
.
code
===
'MODULE_NOT_FOUND'
)
console
.
log
(
`Config file
${
configFile
}
not found`
);
else
console
.
log
(
`Cannot load config file
${
configFile
}
`
,
e
);
}
if
(
typeof
config
.
folderListingEnabled
===
'undefined'
)
config
.
folderListingEnabled
=
true
;
// Setup the express server and routes
var
app
=
express
();
var
router
=
new
express
.
Router
();
...
...
@@ -25,6 +66,8 @@ var multipart = multipart({ maxFieldsSize: 2 * 1024, limit: '512mb', timeout: 3
router
.
post
(
'/api/login'
,
auth
.
login
);
router
.
post
(
'/api/logout'
,
auth
.
verify
,
auth
.
logout
);
router
.
get
(
'/api/settings'
,
auth
.
verify
,
getSettings
);
router
.
put
(
'/api/settings'
,
auth
.
verify
,
setSettings
);
router
.
get
(
'/api/profile'
,
auth
.
verify
,
auth
.
getProfile
);
router
.
get
(
'/api/files/*'
,
auth
.
verify
,
files
.
get
);
router
.
post
(
'/api/files/*'
,
auth
.
verify
,
multipart
,
files
.
post
);
...
...
@@ -32,14 +75,6 @@ router.put ('/api/files/*', auth.verify, files.put);
router
.
delete
(
'/api/files/*'
,
auth
.
verify
,
files
.
del
);
router
.
get
(
'/api/healthcheck'
,
function
(
req
,
res
)
{
res
.
status
(
200
).
send
();
});
// welcome screen in case / does not serve up any file yet
function
welcomePage
(
req
,
res
,
next
)
{
if
(
req
.
path
!==
'/'
)
return
next
();
res
.
status
(
200
).
sendFile
(
path
.
join
(
__dirname
,
'/frontend/welcome.html'
));
}
var
rootFolder
=
path
.
resolve
(
__dirname
,
process
.
argv
[
2
]
||
'files'
);
app
.
use
(
morgan
(
'dev'
));
app
.
use
(
compression
());
app
.
use
(
'/api'
,
bodyParser
.
json
());
...
...
@@ -51,7 +86,14 @@ app.use('/api', passport.session());
app
.
use
(
router
);
app
.
use
(
'/_admin'
,
express
.
static
(
__dirname
+
'/frontend'
));
app
.
use
(
'/'
,
express
.
static
(
rootFolder
));
app
.
use
(
'/'
,
welcomePage
);
app
.
use
(
'/'
,
function
welcomePage
(
req
,
res
,
next
)
{
if
(
req
.
path
!==
'/'
)
return
next
();
res
.
status
(
200
).
sendFile
(
path
.
join
(
__dirname
,
'/frontend/welcome.html'
));
});
app
.
use
(
'/'
,
function
(
req
,
res
,
next
)
{
if
(
config
.
folderListingEnabled
)
return
next
();
res
.
sendFile
(
__dirname
+
'/frontend/404.html'
);
});
app
.
use
(
'/'
,
serveIndex
(
rootFolder
,
{
icons
:
true
}));
app
.
use
(
lastMile
());
...
...
@@ -59,9 +101,6 @@ 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'
,
basePath
);
console
.
log
(
'Surfer listening on http://%s:%s'
,
host
,
port
);
console
.
log
(
'Using base path'
,
rootFolder
);
});
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