mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
remove project controller / handler
add unit test scaffolding
This commit is contained in:
parent
1f20744a68
commit
0bb12f32fa
13 changed files with 50 additions and 36 deletions
|
@ -4,7 +4,6 @@ logger.initialize("filestore")
|
||||||
settings = require("settings-sharelatex")
|
settings = require("settings-sharelatex")
|
||||||
request = require("request")
|
request = require("request")
|
||||||
fileController = require("./app/js/FileController")
|
fileController = require("./app/js/FileController")
|
||||||
projectController = require("./app/js/ProjectController")
|
|
||||||
keyBuilder = require("./app/js/KeyBuilder")
|
keyBuilder = require("./app/js/KeyBuilder")
|
||||||
domain = require("domain")
|
domain = require("domain")
|
||||||
appIsOk = true
|
appIsOk = true
|
||||||
|
@ -86,7 +85,7 @@ app.post "/project/:project_id/public/:public_file_id", keyBuilder.publicFileKey
|
||||||
app.put "/project/:project_id/public/:public_file_id", keyBuilder.publicFileKey, express.bodyParser(), fileController.copyFile
|
app.put "/project/:project_id/public/:public_file_id", keyBuilder.publicFileKey, express.bodyParser(), fileController.copyFile
|
||||||
app.del "/project/:project_id/public/:public_file_id", keyBuilder.publicFileKey, fileController.deleteFile
|
app.del "/project/:project_id/public/:public_file_id", keyBuilder.publicFileKey, fileController.deleteFile
|
||||||
|
|
||||||
app.get "/project/:project_id/size", keyBuilder.publicProjectKey, projectController.projectSize
|
app.get "/project/:project_id/size", keyBuilder.publicProjectKey, fileController.directorySize
|
||||||
|
|
||||||
app.get "/heapdump", (req, res)->
|
app.get "/heapdump", (req, res)->
|
||||||
require('heapdump').writeSnapshot '/tmp/' + Date.now() + '.filestore.heapsnapshot', (err, filename)->
|
require('heapdump').writeSnapshot '/tmp/' + Date.now() + '.filestore.heapsnapshot', (err, filename)->
|
||||||
|
|
|
@ -85,7 +85,7 @@ module.exports =
|
||||||
return callback err
|
return callback err
|
||||||
callback null, data.ETag?
|
callback null, data.ETag?
|
||||||
|
|
||||||
getProjectSize:(bucketName, key, callback)->
|
directorySize:(bucketName, key, callback)->
|
||||||
logger.log bucketName:bucketName, key:key, "get project size in s3"
|
logger.log bucketName:bucketName, key:key, "get project size in s3"
|
||||||
s3.listObjects {Bucket: bucketName, Prefix: key}, (err, data) ->
|
s3.listObjects {Bucket: bucketName, Prefix: key}, (err, data) ->
|
||||||
if err?
|
if err?
|
||||||
|
|
|
@ -88,7 +88,7 @@ module.exports =
|
||||||
logger.log location:location, name:filteredName, exists:exists, "checked if file exists"
|
logger.log location:location, name:filteredName, exists:exists, "checked if file exists"
|
||||||
callback null, exists
|
callback null, exists
|
||||||
|
|
||||||
getProjectSize:(location, name, callback)->
|
directorySize:(location, name, callback)->
|
||||||
filteredName = filterName name.replace(/\/$/,'')
|
filteredName = filterName name.replace(/\/$/,'')
|
||||||
logger.log location:location, name:filteredName, "get project size in file system"
|
logger.log location:location, name:filteredName, "get project size in file system"
|
||||||
fs.readdir "#{location}/#{filteredName}", (err, files) ->
|
fs.readdir "#{location}/#{filteredName}", (err, files) ->
|
||||||
|
|
|
@ -83,3 +83,14 @@ module.exports = FileController =
|
||||||
else
|
else
|
||||||
range = parsed[0]
|
range = parsed[0]
|
||||||
{start: range.start, end: range.end}
|
{start: range.start, end: range.end}
|
||||||
|
|
||||||
|
directorySize: (req, res)->
|
||||||
|
metrics.inc "projectSize"
|
||||||
|
{project_id, bucket} = req
|
||||||
|
logger.log project_id:project_id, bucket:bucket, "reciving request to project size"
|
||||||
|
FileHandler.getDirectorySize bucket, project_id, (err, size)->
|
||||||
|
if err?
|
||||||
|
logger.log err: err, project_id: project_id, bucket: bucket, "error inserting file"
|
||||||
|
res.send 500
|
||||||
|
else
|
||||||
|
res.json {'total bytes' : size}
|
||||||
|
|
|
@ -87,3 +87,10 @@ module.exports =
|
||||||
if err?
|
if err?
|
||||||
return callback(err)
|
return callback(err)
|
||||||
LocalFileWriter.writeStream fileStream, key, callback
|
LocalFileWriter.writeStream fileStream, key, callback
|
||||||
|
|
||||||
|
getDirectorySize: (bucket, project_id, callback)->
|
||||||
|
logger.log bucket:bucket, project_id:project_id, "getting project size"
|
||||||
|
PersistorManager.directorySize bucket, project_id, (err, size)->
|
||||||
|
if err?
|
||||||
|
logger.err bucket:bucket, project_id:project_id, "error getting size"
|
||||||
|
callback err, size
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
settings = require("settings-sharelatex")
|
|
||||||
logger = require("logger-sharelatex")
|
|
||||||
metrics = require("metrics-sharelatex")
|
|
||||||
Errors = require('./Errors')
|
|
||||||
ProjectHandler = require("./ProjectHandler")
|
|
||||||
|
|
||||||
module.exports = projectController =
|
|
||||||
|
|
||||||
projectSize: (req, res)->
|
|
||||||
metrics.inc "projectSize"
|
|
||||||
{project_id, bucket} = req
|
|
||||||
logger.log project_id:project_id, bucket:bucket, "reciving request to project size"
|
|
||||||
ProjectHandler.getSize bucket, project_id, (err, size)->
|
|
||||||
if err?
|
|
||||||
logger.log err: err, project_id: project_id, bucket: bucket, "error inserting file"
|
|
||||||
res.send 500
|
|
||||||
else
|
|
||||||
res.json {'total bytes' : size}
|
|
|
@ -1,13 +0,0 @@
|
||||||
settings = require("settings-sharelatex")
|
|
||||||
PersistorManager = require("./PersistorManager")
|
|
||||||
logger = require("logger-sharelatex")
|
|
||||||
async = require("async")
|
|
||||||
|
|
||||||
module.exports =
|
|
||||||
|
|
||||||
getSize: (bucket, project_id, callback)->
|
|
||||||
logger.log bucket:bucket, project_id:project_id, "getting project size"
|
|
||||||
PersistorManager.getProjectSize bucket, project_id, (err, size)->
|
|
||||||
if err?
|
|
||||||
logger.err bucket:bucket, project_id:project_id, "error getting size"
|
|
||||||
callback err, size
|
|
|
@ -138,7 +138,7 @@ module.exports =
|
||||||
logger.log bucketName:bucketName, key:key, exists:exists, "checked if file exsists in s3"
|
logger.log bucketName:bucketName, key:key, exists:exists, "checked if file exsists in s3"
|
||||||
callback(err, exists)
|
callback(err, exists)
|
||||||
|
|
||||||
getProjectSize:(bucketName, key, callback)->
|
directorySize:(bucketName, key, callback)->
|
||||||
logger.log bucketName:bucketName, key:key, "get project size in s3"
|
logger.log bucketName:bucketName, key:key, "get project size in s3"
|
||||||
s3Client = knox.createClient
|
s3Client = knox.createClient
|
||||||
key: settings.filestore.s3.key
|
key: settings.filestore.s3.key
|
||||||
|
|
|
@ -247,3 +247,11 @@ describe "AWSSDKPersistorManager", ->
|
||||||
@AWSSDKPersistorManager.checkIfFileExists @bucketName, @key, (err, exists) =>
|
@AWSSDKPersistorManager.checkIfFileExists @bucketName, @key, (err, exists) =>
|
||||||
expect(err).to.equal @error
|
expect(err).to.equal @error
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
describe "directorySize", ->
|
||||||
|
|
||||||
|
it "should list the directory content using s3.listObjects", (done) ->
|
||||||
|
done()
|
||||||
|
|
||||||
|
it "should sum directory files size", (done) ->
|
||||||
|
done()
|
||||||
|
|
|
@ -208,3 +208,8 @@ describe "FSPersistorManagerTests", ->
|
||||||
@FSPersistorManager.checkIfFileExists @location, @name1, (err,exists) =>
|
@FSPersistorManager.checkIfFileExists @location, @name1, (err,exists) =>
|
||||||
exists.should.be.false
|
exists.should.be.false
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
describe "directorySize", ->
|
||||||
|
|
||||||
|
it "should sum directory files size", (done) ->
|
||||||
|
done()
|
|
@ -152,3 +152,8 @@ describe "FileController", ->
|
||||||
result = @controller._get_range('carrots=0-200')
|
result = @controller._get_range('carrots=0-200')
|
||||||
expect(result).to.equal null
|
expect(result).to.equal null
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
describe "directorySize", ->
|
||||||
|
|
||||||
|
it "should call the file handler the directory size", (done) ->
|
||||||
|
done()
|
||||||
|
|
|
@ -192,3 +192,8 @@ describe "FileHandler", ->
|
||||||
@FileConverter.convert.calledWith(@stubbedPath, @format).should.equal true
|
@FileConverter.convert.calledWith(@stubbedPath, @format).should.equal true
|
||||||
@LocalFileWriter.deleteFile.calledWith(@stubbedPath).should.equal true
|
@LocalFileWriter.deleteFile.calledWith(@stubbedPath).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
describe "directorySize", ->
|
||||||
|
|
||||||
|
it "should call the filestore manager to get directory size", (done) ->
|
||||||
|
done()
|
||||||
|
|
|
@ -256,3 +256,8 @@ describe "S3PersistorManagerTests", ->
|
||||||
@S3PersistorManager.checkIfFileExists @bucketName, @key, (err)=>
|
@S3PersistorManager.checkIfFileExists @bucketName, @key, (err)=>
|
||||||
err.should.equal @error
|
err.should.equal @error
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
describe "directorySize", ->
|
||||||
|
|
||||||
|
it "should sum directory files size", (done) ->
|
||||||
|
done()
|
||||||
|
|
Loading…
Reference in a new issue