Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Virgile JARRY
cloudfrag
Commits
847e22ab
Commit
847e22ab
authored
Mar 23, 2016
by
Giome
Browse files
[Ref] TTL is now handled in url rather than http headers
parent
28755025
Changes
2
Hide whitespace changes
Inline
Side-by-side
code/storageServer/functional_test.js
View file @
847e22ab
...
...
@@ -13,16 +13,10 @@ test_post_request();
function
test_post_request
()
{
var
post_options
=
{
uri
:
'
http://localhost:3000/api/chunks
'
,
method
:
'
POST
'
,
headers
:
{
'
ttl
'
:
'
30
'
},
};
var
uri
=
'
http://localhost:3000/api/chunks?ttl=30
'
;
fs
.
createReadStream
(
'
./tests/thegreatwave.jpg
'
)
.
pipe
(
request
.
post
(
post_options
,
function
(
err
,
res
,
body
)
{
.
pipe
(
request
.
post
(
uri
,
function
(
err
,
res
,
body
)
{
assert
.
equal
(
err
,
undefined
,
'
Unable to do POST request. Server may not be running !
'
);
...
...
@@ -43,8 +37,9 @@ function test_post_request() {
function
test_get_request
(
id
)
{
var
writeStream
=
fs
.
createWriteStream
(
'
./tests/
'
+
id
+
'
.jpg
'
);
var
uri
=
'
http://localhost:3000/api/chunks/
'
+
id
;
request
.
get
(
'
http://localhost:3000/api/chunks/
'
+
id
)
request
.
get
(
uri
)
.
pipe
(
writeStream
)
.
on
(
'
finish
'
,
function
()
{
var
file_stats
=
fs
.
statSync
(
'
./tests/thegreatwave.jpg
'
);
...
...
@@ -60,31 +55,23 @@ function test_get_request(id) {
// Now he asks the server to update the TTL of his chunk to 1 month.
function
test_put_request
(
id
)
{
var
put_options
=
{
uri
:
'
http://localhost:3000/api/chunks/
'
+
id
,
method
:
'
PUT
'
,
headers
:
{
'
ttl
'
:
'
60
'
},
};
request
.
put
(
put_options
,
function
(
err
,
res
,
body
)
{
var
uri
=
'
http://localhost:3000/api/chunks/
'
+
id
+
'
?ttl=60
'
;
request
.
put
(
uri
,
function
(
err
,
res
,
body
)
{
body
=
JSON
.
parse
(
body
);
assert
.
notEqual
(
body
.
id
,
undefined
,
'
Empty chunk ID in PUT request.
'
);
assert
.
equal
(
body
.
ttl
,
put_options
.
headers
.
ttl
,
'
Modified TTL not set as expected.
'
);
assert
.
equal
(
body
.
ttl
,
60
,
'
Modified TTL not set as expected.
'
);
test_delete_request
(
body
.
id
);
});
}
function
test_delete_request
(
id
)
{
var
del_options
=
{
uri
:
'
http://localhost:3000/api/chunks/
'
+
id
,
method
:
'
DELETE
'
,
};
request
.
del
(
del_options
,
function
(
err
,
res
,
body
)
{
var
uri
=
'
http://localhost:3000/api/chunks/
'
+
id
;
request
.
del
(
uri
,
function
(
err
,
res
,
body
)
{
body
=
JSON
.
parse
(
body
);
assert
.
notEqual
(
body
.
id
,
undefined
,
'
Empty chunk ID in DEL request.
'
);
});
...
...
code/storageServer/routes/chunks.js
View file @
847e22ab
...
...
@@ -9,8 +9,11 @@
var
Chunks
=
require
(
'
../models/Chunks
'
);
var
uuid
=
require
(
'
node-uuid
'
);
var
db
=
require
(
'
../db
'
)
var
url
=
require
(
'
url
'
);
var
fs
=
require
(
'
fs
'
);
var
express
=
require
(
'
express
'
);
var
router
=
express
.
Router
();
...
...
@@ -22,7 +25,9 @@ var router = express.Router();
// - id -> (Str) The unique filename of the chunk.
// - ttl -> (Date) The date of removal of the chunk in MongoDB.
router
.
post
(
'
/
'
,
function
(
req
,
res
)
{
var
ttl
=
req
.
headers
.
ttl
;
var
query
=
url
.
parse
(
req
.
url
,
true
).
query
;
var
ttl
=
query
.
ttl
;
var
id
=
uuid
.
v4
();
var
chunk
=
{
'
id
'
:
id
,
'
ttl
'
:
ttl
};
...
...
@@ -57,9 +62,9 @@ router.get('/:access_hash', function(req, res) {
// - id -> (Str) The unique filename of the chunk.
// - ttl -> (Date) The new date of removal of the chunk in MongoDB.
router
.
put
(
'
/:access_hash
'
,
function
(
req
,
res
)
{
var
id
=
req
.
params
[
'
access_hash
'
];
var
ttl
=
req
.
headers
.
ttl
;
var
query
=
url
.
parse
(
req
.
url
,
true
).
query
;
var
ttl
=
query
.
ttl
;
var
chunk
=
{
'
id
'
:
id
,
'
ttl
'
:
ttl
};
Chunks
.
update
(
chunk
,
function
()
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
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 comment