mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
filter /s from key ids
This commit is contained in:
parent
7c5634044f
commit
88cc89a0d1
2 changed files with 34 additions and 22 deletions
|
@ -2,12 +2,17 @@ logger = require("logger-sharelatex")
|
||||||
fs = require("fs")
|
fs = require("fs")
|
||||||
LocalFileWriter = require("./LocalFileWriter")
|
LocalFileWriter = require("./LocalFileWriter")
|
||||||
|
|
||||||
module.exports =
|
filterName = (key) ->
|
||||||
|
return key.replace /\//, "_"
|
||||||
|
|
||||||
|
|
||||||
|
module.exports =
|
||||||
sendFile: ( location, target, source, callback = (err)->) ->
|
sendFile: ( location, target, source, callback = (err)->) ->
|
||||||
logger.log location:location, target:target, source:source, "sending file"
|
filteredTarget = filterName target
|
||||||
fs.rename source, "#{location}/#{target}", (err) ->
|
logger.log location:location, target:filteredTarget, source:source, "sending file"
|
||||||
logger.err err:err, location:location, target:target, source:source, "Error on put of file"
|
fs.rename source, "#{location}/#{filteredTarget}", (err) ->
|
||||||
|
if err!=null
|
||||||
|
logger.err err:err, location:location, target:filteredTarget, source:source, "Error on put of file"
|
||||||
callback err
|
callback err
|
||||||
|
|
||||||
sendStream: ( location, target, sourceStream, callback = (err)->) ->
|
sendStream: ( location, target, sourceStream, callback = (err)->) ->
|
||||||
|
@ -21,8 +26,9 @@ module.exports =
|
||||||
@sendFile location, target, fsPath, callback
|
@sendFile location, target, fsPath, callback
|
||||||
|
|
||||||
getFileStream: (location, name, callback = (err, res)->)->
|
getFileStream: (location, name, callback = (err, res)->)->
|
||||||
logger.log location:location, name:name, "getting file"
|
filteredName = filterName name
|
||||||
sourceStream = fs.createReadStream "#{location}/#{name}"
|
logger.log location:location, name:filteredName, "getting file"
|
||||||
|
sourceStream = fs.createReadStream "#{location}/#{filteredName}"
|
||||||
sourceStream.on 'error', (err) ->
|
sourceStream.on 'error', (err) ->
|
||||||
logger.err err:err, location:location, name:name, "Error reading from file"
|
logger.err err:err, location:location, name:name, "Error reading from file"
|
||||||
callback err
|
callback err
|
||||||
|
@ -30,30 +36,35 @@ module.exports =
|
||||||
|
|
||||||
|
|
||||||
copyFile: (location, fromName, toName, callback = (err)->)->
|
copyFile: (location, fromName, toName, callback = (err)->)->
|
||||||
logger.log location:location, fromName:fromName, toName:toName, "copying file"
|
filteredFromName=filterName fromName
|
||||||
sourceStream = fs.createReadStream "#{location}/#{fromName}"
|
filteredToName=filterName toName
|
||||||
|
logger.log location:location, fromName:filteredFromName, toName:filteredToName, "copying file"
|
||||||
|
sourceStream = fs.createReadStream "#{location}/#{filteredFromName}"
|
||||||
sourceStream.on 'error', (err) ->
|
sourceStream.on 'error', (err) ->
|
||||||
logger.err err:err, location:location, key:fromName, "Error reading from file"
|
logger.err err:err, location:location, key:filteredFromName, "Error reading from file"
|
||||||
callback err
|
callback err
|
||||||
targetStream = fs.createWriteStream "#{location}/#{toName}"
|
targetStream = fs.createWriteStream "#{location}/#{filteredToName}"
|
||||||
targetStream.on 'error', (err) ->
|
targetStream.on 'error', (err) ->
|
||||||
logger.err err:err, location:location, key:targetKey, "Error writing to file"
|
logger.err err:err, location:location, key:filteredToName, "Error writing to file"
|
||||||
callback err
|
callback err
|
||||||
sourceStream.pipe targetStream
|
sourceStream.pipe targetStream
|
||||||
|
|
||||||
deleteFile: (location, name, callback)->
|
deleteFile: (location, name, callback)->
|
||||||
logger.log location:location, name:name, "delete file"
|
filteredName = filterName name
|
||||||
fs.unlink "#{location}/#{name}", (err) ->
|
logger.log location:location, name:filteredName, "delete file"
|
||||||
logger.err err:err, location:location, name:name, "Error on delete."
|
fs.unlink "#{location}/#{filteredName}", (err) ->
|
||||||
|
logger.err err:err, location:location, name:filteredName, "Error on delete."
|
||||||
callback err
|
callback err
|
||||||
|
|
||||||
deleteDirectory: (location, name, callback = (err)->)->
|
deleteDirectory: (location, name, callback = (err)->)->
|
||||||
fs.rmdir "#{location}/#{name}", (err) ->
|
filteredName = filterName name
|
||||||
logger.err err:err, location:location, name:name, "Error on rmdir."
|
fs.rmdir "#{location}/#{filteredName}", (err) ->
|
||||||
|
logger.err err:err, location:location, name:filteredName, "Error on rmdir."
|
||||||
callback err
|
callback err
|
||||||
|
|
||||||
checkIfFileExists:(location, name, callback = (err,exists)->)->
|
checkIfFileExists:(location, name, callback = (err,exists)->)->
|
||||||
logger.log location:location, name:name, "checking if file exists"
|
filteredName = filterName name
|
||||||
fs.exists "#{location}/#{name}", (exists) ->
|
logger.log location:location, name:filteredName, "checking if file exists"
|
||||||
logger.log location:location, name:name, exists:exists, "checked if file exists"
|
fs.exists "#{location}/#{filteredName}", (exists) ->
|
||||||
|
logger.log location:location, name:filteredName, exists:exists, "checked if file exists"
|
||||||
callback null, exists
|
callback null, exists
|
||||||
|
|
|
@ -26,7 +26,8 @@ describe "FSPersistorManagerTests", ->
|
||||||
log:->
|
log:->
|
||||||
err:->
|
err:->
|
||||||
@location = "/tmp"
|
@location = "/tmp"
|
||||||
@name1 = "first_file"
|
@name1 = "530f2407e7ef165704000007/530f838b46d9a9e859000008"
|
||||||
|
@name1Filtered ="530f2407e7ef165704000007_530f838b46d9a9e859000008"
|
||||||
@name2 = "second_file"
|
@name2 = "second_file"
|
||||||
@error = "error_message"
|
@error = "error_message"
|
||||||
@FSPersistorManager = SandboxedModule.require modulePath, requires: @requires
|
@FSPersistorManager = SandboxedModule.require modulePath, requires: @requires
|
||||||
|
@ -35,7 +36,7 @@ describe "FSPersistorManagerTests", ->
|
||||||
it "should put the file", (done) ->
|
it "should put the file", (done) ->
|
||||||
@Fs.rename.callsArgWith(2,@error)
|
@Fs.rename.callsArgWith(2,@error)
|
||||||
@FSPersistorManager.sendFile @location, @name1, @name2, (err)=>
|
@FSPersistorManager.sendFile @location, @name1, @name2, (err)=>
|
||||||
@Fs.rename.calledWith( @name2, "#{@location}/#{@name1}" ).should.equal true
|
@Fs.rename.calledWith( @name2, "#{@location}/#{@name1Filtered}" ).should.equal true
|
||||||
err.should.equal @error
|
err.should.equal @error
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
@ -69,7 +70,7 @@ describe "FSPersistorManagerTests", ->
|
||||||
on:->
|
on:->
|
||||||
)
|
)
|
||||||
@FSPersistorManager.getFileStream @location, @name1, (err,res)=>
|
@FSPersistorManager.getFileStream @location, @name1, (err,res)=>
|
||||||
@Fs.createReadStream.calledWith("#{@location}/#{@name1}").should.equal.true
|
@Fs.createReadStream.calledWith("#{@location}/#{@name1Filtered}").should.equal.true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
describe "copyFile", ->
|
describe "copyFile", ->
|
||||||
|
|
Loading…
Reference in a new issue