mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -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")
|
settings = require("settings-sharelatex")
|
||||||
logger = require("logger-sharelatex")
|
logger = require("logger-sharelatex")
|
||||||
FileHandler = require("./FileHandler")
|
FileHandler = require("./FileHandler")
|
||||||
|
@ -37,7 +37,7 @@ module.exports =
|
||||||
oldProject_id = req.body.source.project_id
|
oldProject_id = req.body.source.project_id
|
||||||
oldFile_id = req.body.source.file_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"
|
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?
|
if err?
|
||||||
logger.log err:err, oldProject_id:oldProject_id, oldFile_id:oldFile_id, "something went wrong copying file"
|
logger.log err:err, oldProject_id:oldProject_id, oldFile_id:oldFile_id, "something went wrong copying file"
|
||||||
res.send 500
|
res.send 500
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
settings = require("settings-sharelatex")
|
settings = require("settings-sharelatex")
|
||||||
fsWrapper = require("./fsWrapper")
|
PersistorManager = require("./PersistorManager")
|
||||||
LocalFileWriter = require("./LocalFileWriter")
|
LocalFileWriter = require("./LocalFileWriter")
|
||||||
logger = require("logger-sharelatex")
|
logger = require("logger-sharelatex")
|
||||||
FileConverter = require("./FileConverter")
|
FileConverter = require("./FileConverter")
|
||||||
|
@ -12,15 +12,15 @@ module.exports =
|
||||||
|
|
||||||
insertFile: (bucket, key, stream, callback)->
|
insertFile: (bucket, key, stream, callback)->
|
||||||
convetedKey = KeyBuilder.getConvertedFolderKey(key)
|
convetedKey = KeyBuilder.getConvertedFolderKey(key)
|
||||||
fsWrapper.deleteDirectory bucket, convetedKey, ->
|
PersistorManager.deleteDirectory bucket, convetedKey, ->
|
||||||
fsWrapper.sendStreamToS3 bucket, key, stream, ->
|
PersistorManager.sendStreamToS3 bucket, key, stream, ->
|
||||||
callback()
|
callback()
|
||||||
|
|
||||||
deleteFile: (bucket, key, callback)->
|
deleteFile: (bucket, key, callback)->
|
||||||
convetedKey = KeyBuilder.getConvertedFolderKey(bucket, key)
|
convetedKey = KeyBuilder.getConvertedFolderKey(bucket, key)
|
||||||
async.parallel [
|
async.parallel [
|
||||||
(done)-> fsWrapper.deleteFile bucket, key, done
|
(done)-> PersistorManager.deleteFile bucket, key, done
|
||||||
(done)-> fsWrapper.deleteFile bucket, convetedKey, done
|
(done)-> PersistorManager.deleteFile bucket, convetedKey, done
|
||||||
], callback
|
], callback
|
||||||
|
|
||||||
getFile: (bucket, key, opts = {}, callback)->
|
getFile: (bucket, key, opts = {}, callback)->
|
||||||
|
@ -31,16 +31,16 @@ module.exports =
|
||||||
@_getConvertedFile bucket, key, opts, callback
|
@_getConvertedFile bucket, key, opts, callback
|
||||||
|
|
||||||
_getStandardFile: (bucket, key, opts, callback)->
|
_getStandardFile: (bucket, key, opts, callback)->
|
||||||
fsWrapper.getFileStream bucket, key, (err, fileStream)->
|
PersistorManager.getFileStream bucket, key, (err, fileStream)->
|
||||||
if err?
|
if err?
|
||||||
logger.err bucket:bucket, key:key, opts:opts, "error getting fileStream"
|
logger.err bucket:bucket, key:key, opts:opts, "error getting fileStream"
|
||||||
callback err, fileStream
|
callback err, fileStream
|
||||||
|
|
||||||
_getConvertedFile: (bucket, key, opts, callback)->
|
_getConvertedFile: (bucket, key, opts, callback)->
|
||||||
convetedKey = KeyBuilder.addCachingToKey(key, opts)
|
convetedKey = KeyBuilder.addCachingToKey(key, opts)
|
||||||
fsWrapper.checkIfFileExists bucket, convetedKey, (err, exists)=>
|
PersistorManager.checkIfFileExists bucket, convetedKey, (err, exists)=>
|
||||||
if exists
|
if exists
|
||||||
fsWrapper.getFileStream bucket, convetedKey, callback
|
PersistorManager.getFileStream bucket, convetedKey, callback
|
||||||
else
|
else
|
||||||
@_getConvertedFileAndCache bucket, key, convetedKey, opts, callback
|
@_getConvertedFileAndCache bucket, key, convetedKey, opts, callback
|
||||||
|
|
||||||
|
@ -53,11 +53,11 @@ module.exports =
|
||||||
if err?
|
if err?
|
||||||
logger.err err:err, fsPath:fsPath, bucket:bucket, key:key, opts:opts, "something went wrong optimising png file"
|
logger.err err:err, fsPath:fsPath, bucket:bucket, key:key, opts:opts, "something went wrong optimising png file"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
fsWrapper.sendFileToS3 bucket, convetedKey, fsPath, (err)->
|
PersistorManager.sendFileToS3 bucket, convetedKey, fsPath, (err)->
|
||||||
if err?
|
if err?
|
||||||
logger.err err:err, bucket:bucket, key:key, convetedKey:convetedKey, opts:opts, "something went wrong sending the file"
|
logger.err err:err, bucket:bucket, key:key, convetedKey:convetedKey, opts:opts, "something went wrong sending the file"
|
||||||
return callback(err)
|
return callback(err)
|
||||||
fsWrapper.getFileStream bucket, convetedKey, callback
|
PersistorManager.getFileStream bucket, convetedKey, callback
|
||||||
|
|
||||||
_convertFile: (bucket, origonalKey, opts, callback)->
|
_convertFile: (bucket, origonalKey, opts, callback)->
|
||||||
@_writeS3FileToDisk bucket, origonalKey, (err, origonalFsPath)->
|
@_writeS3FileToDisk bucket, origonalKey, (err, origonalFsPath)->
|
||||||
|
@ -72,6 +72,6 @@ module.exports =
|
||||||
|
|
||||||
|
|
||||||
_writeS3FileToDisk: (bucket, key, callback)->
|
_writeS3FileToDisk: (bucket, key, callback)->
|
||||||
fsWrapper.getFileStream bucket, key, (err, fileStream)->
|
PersistorManager.getFileStream bucket, key, (err, fileStream)->
|
||||||
LocalFileWriter.writeStream fileStream, key, callback
|
LocalFileWriter.writeStream fileStream, key, callback
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ settings = require("settings-sharelatex")
|
||||||
logger = require("logger-sharelatex")
|
logger = require("logger-sharelatex")
|
||||||
s3Wrapper = require("./s3Wrapper")
|
s3Wrapper = require("./s3Wrapper")
|
||||||
|
|
||||||
logger.log backend:settings.filestoreBackend,"Loading backend"
|
logger.log backend:settings.filestoreBackend, "Loading backend"
|
||||||
module.exports = switch settings.filestoreBackend
|
module.exports = switch settings.filestoreBackend
|
||||||
when "s3"
|
when "s3"
|
||||||
s3Wrapper
|
s3Wrapper
|
|
@ -26,7 +26,7 @@ describe "FileController", ->
|
||||||
@controller = SandboxedModule.require modulePath, requires:
|
@controller = SandboxedModule.require modulePath, requires:
|
||||||
"./LocalFileWriter":@LocalFileWriter
|
"./LocalFileWriter":@LocalFileWriter
|
||||||
"./FileHandler": @FileHandler
|
"./FileHandler": @FileHandler
|
||||||
"./fsWrapper":@FsWrapper
|
"./PersistorManager":@FsWrapper
|
||||||
"settings-sharelatex": @settings
|
"settings-sharelatex": @settings
|
||||||
"logger-sharelatex":
|
"logger-sharelatex":
|
||||||
log:->
|
log:->
|
||||||
|
|
|
@ -33,7 +33,7 @@ describe "FileHandler", ->
|
||||||
compressPng: sinon.stub()
|
compressPng: sinon.stub()
|
||||||
@handler = SandboxedModule.require modulePath, requires:
|
@handler = SandboxedModule.require modulePath, requires:
|
||||||
"settings-sharelatex": @settings
|
"settings-sharelatex": @settings
|
||||||
"./fsWrapper":@FsWrapper
|
"./PersistorManager":@FsWrapper
|
||||||
"./LocalFileWriter":@LocalFileWriter
|
"./LocalFileWriter":@LocalFileWriter
|
||||||
"./FileConverter":@FileConverter
|
"./FileConverter":@FileConverter
|
||||||
"./KeyBuilder": @keyBuilder
|
"./KeyBuilder": @keyBuilder
|
||||||
|
|
|
@ -4,11 +4,11 @@ sinon = require('sinon')
|
||||||
chai = require('chai')
|
chai = require('chai')
|
||||||
should = chai.should()
|
should = chai.should()
|
||||||
expect = chai.expect
|
expect = chai.expect
|
||||||
modulePath = "../../../app/js/fsWrapper.js"
|
modulePath = "../../../app/js/PersistorManager.js"
|
||||||
SandboxedModule = require('sandboxed-module')
|
SandboxedModule = require('sandboxed-module')
|
||||||
|
|
||||||
|
|
||||||
describe "fsWrapperTests", ->
|
describe "PersistorManagerTests", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@s3Wrapper =
|
@s3Wrapper =
|
||||||
|
@ -29,36 +29,36 @@ describe "fsWrapperTests", ->
|
||||||
"logger-sharelatex":
|
"logger-sharelatex":
|
||||||
log:->
|
log:->
|
||||||
err:->
|
err:->
|
||||||
@fsWrapper = SandboxedModule.require modulePath, requires: @requires
|
@PersistorManager = SandboxedModule.require modulePath, requires: @requires
|
||||||
|
|
||||||
it "should load getFileStream", (done) ->
|
it "should load getFileStream", (done) ->
|
||||||
@fsWrapper.should.respondTo("getFileStream")
|
@PersistorManager.should.respondTo("getFileStream")
|
||||||
@fsWrapper.getFileStream()
|
@PersistorManager.getFileStream()
|
||||||
@s3Wrapper.getFileStream.calledOnce.should.equal true
|
@s3Wrapper.getFileStream.calledOnce.should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "should load checkIfFileExists", (done) ->
|
it "should load checkIfFileExists", (done) ->
|
||||||
@fsWrapper.checkIfFileExists()
|
@PersistorManager.checkIfFileExists()
|
||||||
@s3Wrapper.checkIfFileExists.calledOnce.should.equal true
|
@s3Wrapper.checkIfFileExists.calledOnce.should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "should load deleteFile", (done) ->
|
it "should load deleteFile", (done) ->
|
||||||
@fsWrapper.deleteFile()
|
@PersistorManager.deleteFile()
|
||||||
@s3Wrapper.deleteFile.calledOnce.should.equal true
|
@s3Wrapper.deleteFile.calledOnce.should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "should load deleteDirectory", (done) ->
|
it "should load deleteDirectory", (done) ->
|
||||||
@fsWrapper.deleteDirectory()
|
@PersistorManager.deleteDirectory()
|
||||||
@s3Wrapper.deleteDirectory.calledOnce.should.equal true
|
@s3Wrapper.deleteDirectory.calledOnce.should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "should load sendStreamToS3", (done) ->
|
it "should load sendStreamToS3", (done) ->
|
||||||
@fsWrapper.sendStreamToS3()
|
@PersistorManager.sendStreamToS3()
|
||||||
@s3Wrapper.sendStreamToS3.calledOnce.should.equal true
|
@s3Wrapper.sendStreamToS3.calledOnce.should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "should load insertFile", (done) ->
|
it "should load insertFile", (done) ->
|
||||||
@fsWrapper.insertFile()
|
@PersistorManager.insertFile()
|
||||||
@s3Wrapper.insertFile.calledOnce.should.equal true
|
@s3Wrapper.insertFile.calledOnce.should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ describe "fsWrapperTests", ->
|
||||||
log:->
|
log:->
|
||||||
err:->
|
err:->
|
||||||
try
|
try
|
||||||
@fsWrapper=SandboxedModule.require modulePath, requires: @requires
|
@PersistorManager=SandboxedModule.require modulePath, requires: @requires
|
||||||
catch error
|
catch error
|
||||||
assert.equal("Unknown filestore backend: null",error.message)
|
assert.equal("Unknown filestore backend: null",error.message)
|
||||||
done()
|
done()
|
||||||
|
@ -88,7 +88,7 @@ describe "fsWrapperTests", ->
|
||||||
log:->
|
log:->
|
||||||
err:->
|
err:->
|
||||||
try
|
try
|
||||||
@fsWrapper=SandboxedModule.require modulePath, requires: @requires
|
@PersistorManager=SandboxedModule.require modulePath, requires: @requires
|
||||||
catch error
|
catch error
|
||||||
assert.equal("Unknown filestore backend: magic",error.message)
|
assert.equal("Unknown filestore backend: magic",error.message)
|
||||||
done()
|
done()
|
Loading…
Reference in a new issue