mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Renamed fsWrapper to PersistorManager
not 100% happy with that still but its the best I can see so far
This commit is contained in:
parent
49ffeb633d
commit
c9af5e5420
6 changed files with 28 additions and 28 deletions
|
@ -1,4 +1,4 @@
|
|||
fsWrapper = require("./fsWrapper")
|
||||
PersistorManager = require("./PersistorManager")
|
||||
settings = require("settings-sharelatex")
|
||||
logger = require("logger-sharelatex")
|
||||
FileHandler = require("./FileHandler")
|
||||
|
@ -37,7 +37,7 @@ module.exports =
|
|||
oldProject_id = req.body.source.project_id
|
||||
oldFile_id = req.body.source.file_id
|
||||
logger.log key:key, bucket:bucket, oldProject_id:oldProject_id, oldFile_id:oldFile_id, "reciving request to copy file"
|
||||
fsWrapper.copyFile bucket, "#{oldProject_id}/#{oldFile_id}", key, (err)->
|
||||
PersistorManager.copyFile bucket, "#{oldProject_id}/#{oldFile_id}", key, (err)->
|
||||
if err?
|
||||
logger.log err:err, oldProject_id:oldProject_id, oldFile_id:oldFile_id, "something went wrong copying file"
|
||||
res.send 500
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
settings = require("settings-sharelatex")
|
||||
fsWrapper = require("./fsWrapper")
|
||||
PersistorManager = require("./PersistorManager")
|
||||
LocalFileWriter = require("./LocalFileWriter")
|
||||
logger = require("logger-sharelatex")
|
||||
FileConverter = require("./FileConverter")
|
||||
|
@ -12,15 +12,15 @@ module.exports =
|
|||
|
||||
insertFile: (bucket, key, stream, callback)->
|
||||
convetedKey = KeyBuilder.getConvertedFolderKey(key)
|
||||
fsWrapper.deleteDirectory bucket, convetedKey, ->
|
||||
fsWrapper.sendStreamToS3 bucket, key, stream, ->
|
||||
PersistorManager.deleteDirectory bucket, convetedKey, ->
|
||||
PersistorManager.sendStreamToS3 bucket, key, stream, ->
|
||||
callback()
|
||||
|
||||
deleteFile: (bucket, key, callback)->
|
||||
convetedKey = KeyBuilder.getConvertedFolderKey(bucket, key)
|
||||
async.parallel [
|
||||
(done)-> fsWrapper.deleteFile bucket, key, done
|
||||
(done)-> fsWrapper.deleteFile bucket, convetedKey, done
|
||||
(done)-> PersistorManager.deleteFile bucket, key, done
|
||||
(done)-> PersistorManager.deleteFile bucket, convetedKey, done
|
||||
], callback
|
||||
|
||||
getFile: (bucket, key, opts = {}, callback)->
|
||||
|
@ -31,16 +31,16 @@ module.exports =
|
|||
@_getConvertedFile bucket, key, opts, callback
|
||||
|
||||
_getStandardFile: (bucket, key, opts, callback)->
|
||||
fsWrapper.getFileStream bucket, key, (err, fileStream)->
|
||||
PersistorManager.getFileStream bucket, key, (err, fileStream)->
|
||||
if err?
|
||||
logger.err bucket:bucket, key:key, opts:opts, "error getting fileStream"
|
||||
callback err, fileStream
|
||||
|
||||
_getConvertedFile: (bucket, key, opts, callback)->
|
||||
convetedKey = KeyBuilder.addCachingToKey(key, opts)
|
||||
fsWrapper.checkIfFileExists bucket, convetedKey, (err, exists)=>
|
||||
PersistorManager.checkIfFileExists bucket, convetedKey, (err, exists)=>
|
||||
if exists
|
||||
fsWrapper.getFileStream bucket, convetedKey, callback
|
||||
PersistorManager.getFileStream bucket, convetedKey, callback
|
||||
else
|
||||
@_getConvertedFileAndCache bucket, key, convetedKey, opts, callback
|
||||
|
||||
|
@ -53,11 +53,11 @@ module.exports =
|
|||
if err?
|
||||
logger.err err:err, fsPath:fsPath, bucket:bucket, key:key, opts:opts, "something went wrong optimising png file"
|
||||
return callback(err)
|
||||
fsWrapper.sendFileToS3 bucket, convetedKey, fsPath, (err)->
|
||||
PersistorManager.sendFileToS3 bucket, convetedKey, fsPath, (err)->
|
||||
if err?
|
||||
logger.err err:err, bucket:bucket, key:key, convetedKey:convetedKey, opts:opts, "something went wrong sending the file"
|
||||
return callback(err)
|
||||
fsWrapper.getFileStream bucket, convetedKey, callback
|
||||
PersistorManager.getFileStream bucket, convetedKey, callback
|
||||
|
||||
_convertFile: (bucket, origonalKey, opts, callback)->
|
||||
@_writeS3FileToDisk bucket, origonalKey, (err, origonalFsPath)->
|
||||
|
@ -72,6 +72,6 @@ module.exports =
|
|||
|
||||
|
||||
_writeS3FileToDisk: (bucket, key, callback)->
|
||||
fsWrapper.getFileStream bucket, key, (err, fileStream)->
|
||||
PersistorManager.getFileStream bucket, key, (err, fileStream)->
|
||||
LocalFileWriter.writeStream fileStream, key, callback
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ settings = require("settings-sharelatex")
|
|||
logger = require("logger-sharelatex")
|
||||
s3Wrapper = require("./s3Wrapper")
|
||||
|
||||
logger.log backend:settings.filestoreBackend,"Loading backend"
|
||||
logger.log backend:settings.filestoreBackend, "Loading backend"
|
||||
module.exports = switch settings.filestoreBackend
|
||||
when "s3"
|
||||
s3Wrapper
|
|
@ -26,7 +26,7 @@ describe "FileController", ->
|
|||
@controller = SandboxedModule.require modulePath, requires:
|
||||
"./LocalFileWriter":@LocalFileWriter
|
||||
"./FileHandler": @FileHandler
|
||||
"./fsWrapper":@FsWrapper
|
||||
"./PersistorManager":@FsWrapper
|
||||
"settings-sharelatex": @settings
|
||||
"logger-sharelatex":
|
||||
log:->
|
||||
|
|
|
@ -33,7 +33,7 @@ describe "FileHandler", ->
|
|||
compressPng: sinon.stub()
|
||||
@handler = SandboxedModule.require modulePath, requires:
|
||||
"settings-sharelatex": @settings
|
||||
"./fsWrapper":@FsWrapper
|
||||
"./PersistorManager":@FsWrapper
|
||||
"./LocalFileWriter":@LocalFileWriter
|
||||
"./FileConverter":@FileConverter
|
||||
"./KeyBuilder": @keyBuilder
|
||||
|
|
|
@ -4,11 +4,11 @@ sinon = require('sinon')
|
|||
chai = require('chai')
|
||||
should = chai.should()
|
||||
expect = chai.expect
|
||||
modulePath = "../../../app/js/fsWrapper.js"
|
||||
modulePath = "../../../app/js/PersistorManager.js"
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
|
||||
|
||||
describe "fsWrapperTests", ->
|
||||
describe "PersistorManagerTests", ->
|
||||
|
||||
beforeEach ->
|
||||
@s3Wrapper =
|
||||
|
@ -29,36 +29,36 @@ describe "fsWrapperTests", ->
|
|||
"logger-sharelatex":
|
||||
log:->
|
||||
err:->
|
||||
@fsWrapper = SandboxedModule.require modulePath, requires: @requires
|
||||
@PersistorManager = SandboxedModule.require modulePath, requires: @requires
|
||||
|
||||
it "should load getFileStream", (done) ->
|
||||
@fsWrapper.should.respondTo("getFileStream")
|
||||
@fsWrapper.getFileStream()
|
||||
@PersistorManager.should.respondTo("getFileStream")
|
||||
@PersistorManager.getFileStream()
|
||||
@s3Wrapper.getFileStream.calledOnce.should.equal true
|
||||
done()
|
||||
|
||||
it "should load checkIfFileExists", (done) ->
|
||||
@fsWrapper.checkIfFileExists()
|
||||
@PersistorManager.checkIfFileExists()
|
||||
@s3Wrapper.checkIfFileExists.calledOnce.should.equal true
|
||||
done()
|
||||
|
||||
it "should load deleteFile", (done) ->
|
||||
@fsWrapper.deleteFile()
|
||||
@PersistorManager.deleteFile()
|
||||
@s3Wrapper.deleteFile.calledOnce.should.equal true
|
||||
done()
|
||||
|
||||
it "should load deleteDirectory", (done) ->
|
||||
@fsWrapper.deleteDirectory()
|
||||
@PersistorManager.deleteDirectory()
|
||||
@s3Wrapper.deleteDirectory.calledOnce.should.equal true
|
||||
done()
|
||||
|
||||
it "should load sendStreamToS3", (done) ->
|
||||
@fsWrapper.sendStreamToS3()
|
||||
@PersistorManager.sendStreamToS3()
|
||||
@s3Wrapper.sendStreamToS3.calledOnce.should.equal true
|
||||
done()
|
||||
|
||||
it "should load insertFile", (done) ->
|
||||
@fsWrapper.insertFile()
|
||||
@PersistorManager.insertFile()
|
||||
@s3Wrapper.insertFile.calledOnce.should.equal true
|
||||
done()
|
||||
|
||||
|
@ -73,7 +73,7 @@ describe "fsWrapperTests", ->
|
|||
log:->
|
||||
err:->
|
||||
try
|
||||
@fsWrapper=SandboxedModule.require modulePath, requires: @requires
|
||||
@PersistorManager=SandboxedModule.require modulePath, requires: @requires
|
||||
catch error
|
||||
assert.equal("Unknown filestore backend: null",error.message)
|
||||
done()
|
||||
|
@ -88,7 +88,7 @@ describe "fsWrapperTests", ->
|
|||
log:->
|
||||
err:->
|
||||
try
|
||||
@fsWrapper=SandboxedModule.require modulePath, requires: @requires
|
||||
@PersistorManager=SandboxedModule.require modulePath, requires: @requires
|
||||
catch error
|
||||
assert.equal("Unknown filestore backend: magic",error.message)
|
||||
done()
|
Loading…
Reference in a new issue