mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Merge pull request #2024 from jgillich/0.4-maintenance
Use absolute path when storing images
This commit is contained in:
commit
b0345b6238
2 changed files with 18 additions and 18 deletions
|
@ -20,7 +20,7 @@ localFileStore = _.extend(baseStore, {
|
||||||
// - returns a promise which ultimately returns the full url to the uploaded image
|
// - returns a promise which ultimately returns the full url to the uploaded image
|
||||||
'save': function (image) {
|
'save': function (image) {
|
||||||
var saved = when.defer(),
|
var saved = when.defer(),
|
||||||
targetDir = this.getTargetDir(configPaths().imagesRelPath),
|
targetDir = this.getTargetDir(configPaths().imagesPath),
|
||||||
targetFilename;
|
targetFilename;
|
||||||
|
|
||||||
this.getUniqueFileName(this, image, targetDir).then(function (filename) {
|
this.getUniqueFileName(this, image, targetDir).then(function (filename) {
|
||||||
|
@ -33,7 +33,7 @@ localFileStore = _.extend(baseStore, {
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
// The src for the image must be in URI format, not a file system path, which in Windows uses \
|
// The src for the image must be in URI format, not a file system path, which in Windows uses \
|
||||||
// For local file system storage can use relative path so add a slash
|
// For local file system storage can use relative path so add a slash
|
||||||
var fullUrl = (configPaths().subdir + '/' + targetFilename).replace(new RegExp('\\' + path.sep, 'g'), '/');
|
var fullUrl = (configPaths().subdir + '/' + path.relative(configPaths().appRoot, targetFilename)).replace(new RegExp('\\' + path.sep, 'g'), '/');
|
||||||
return saved.resolve(fullUrl);
|
return saved.resolve(fullUrl);
|
||||||
}).otherwise(function (e) {
|
}).otherwise(function (e) {
|
||||||
errors.logError(e);
|
errors.logError(e);
|
||||||
|
|
|
@ -61,7 +61,7 @@ describe('Local File System Storage', function () {
|
||||||
it('should create month and year directory', function (done) {
|
it('should create month and year directory', function (done) {
|
||||||
localfilesystem.save(image).then(function (url) {
|
localfilesystem.save(image).then(function (url) {
|
||||||
fs.mkdirs.calledOnce.should.be.true;
|
fs.mkdirs.calledOnce.should.be.true;
|
||||||
fs.mkdirs.args[0][0].should.equal(path.join('content/images/2013/Sep'));
|
fs.mkdirs.args[0][0].should.equal(path.resolve('./content/images/2013/Sep'));
|
||||||
done();
|
done();
|
||||||
}).then(null, done);
|
}).then(null, done);
|
||||||
});
|
});
|
||||||
|
@ -70,7 +70,7 @@ describe('Local File System Storage', function () {
|
||||||
localfilesystem.save(image).then(function (url) {
|
localfilesystem.save(image).then(function (url) {
|
||||||
fs.copy.calledOnce.should.be.true;
|
fs.copy.calledOnce.should.be.true;
|
||||||
fs.copy.args[0][0].should.equal('tmp/123456.jpg');
|
fs.copy.args[0][0].should.equal('tmp/123456.jpg');
|
||||||
fs.copy.args[0][1].should.equal(path.join('content/images/2013/Sep/IMAGE.jpg'));
|
fs.copy.args[0][1].should.equal(path.resolve('./content/images/2013/Sep/IMAGE.jpg'));
|
||||||
done();
|
done();
|
||||||
}).then(null, done);
|
}).then(null, done);
|
||||||
});
|
});
|
||||||
|
@ -86,13 +86,13 @@ describe('Local File System Storage', function () {
|
||||||
it('can upload two different images with the same name without overwriting the first', function (done) {
|
it('can upload two different images with the same name without overwriting the first', function (done) {
|
||||||
// Sun Sep 08 2013 10:57
|
// Sun Sep 08 2013 10:57
|
||||||
this.clock = sinon.useFakeTimers(new Date(2013, 8, 8, 10, 57).getTime());
|
this.clock = sinon.useFakeTimers(new Date(2013, 8, 8, 10, 57).getTime());
|
||||||
fs.exists.withArgs('content/images/2013/Sep/IMAGE.jpg').yields(true);
|
fs.exists.withArgs(path.resolve('./content/images/2013/Sep/IMAGE.jpg')).yields(true);
|
||||||
fs.exists.withArgs('content/images/2013/Sep/IMAGE-1.jpg').yields(false);
|
fs.exists.withArgs(path.resolve('./content/images/2013/Sep/IMAGE-1.jpg')).yields(false);
|
||||||
|
|
||||||
// if on windows need to setup with back slashes
|
// if on windows need to setup with back slashes
|
||||||
// doesn't hurt for the test to cope with both
|
// doesn't hurt for the test to cope with both
|
||||||
fs.exists.withArgs('content\\images\\2013\\Sep\\IMAGE.jpg').yields(true);
|
fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE.jpg')).yields(true);
|
||||||
fs.exists.withArgs('content\\images\\2013\\Sep\\IMAGE-1.jpg').yields(false);
|
fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-1.jpg')).yields(false);
|
||||||
|
|
||||||
localfilesystem.save(image).then(function (url) {
|
localfilesystem.save(image).then(function (url) {
|
||||||
url.should.equal('/content/images/2013/Sep/IMAGE-1.jpg');
|
url.should.equal('/content/images/2013/Sep/IMAGE-1.jpg');
|
||||||
|
@ -103,18 +103,18 @@ describe('Local File System Storage', function () {
|
||||||
it('can upload five different images with the same name without overwriting the first', function (done) {
|
it('can upload five different images with the same name without overwriting the first', function (done) {
|
||||||
// Sun Sep 08 2013 10:57
|
// Sun Sep 08 2013 10:57
|
||||||
this.clock = sinon.useFakeTimers(new Date(2013, 8, 8, 10, 57).getTime());
|
this.clock = sinon.useFakeTimers(new Date(2013, 8, 8, 10, 57).getTime());
|
||||||
fs.exists.withArgs('content/images/2013/Sep/IMAGE.jpg').yields(true);
|
fs.exists.withArgs(path.resolve('./content/images/2013/Sep/IMAGE.jpg')).yields(true);
|
||||||
fs.exists.withArgs('content/images/2013/Sep/IMAGE-1.jpg').yields(true);
|
fs.exists.withArgs(path.resolve('./content/images/2013/Sep/IMAGE-1.jpg')).yields(true);
|
||||||
fs.exists.withArgs('content/images/2013/Sep/IMAGE-2.jpg').yields(true);
|
fs.exists.withArgs(path.resolve('./content/images/2013/Sep/IMAGE-2.jpg')).yields(true);
|
||||||
fs.exists.withArgs('content/images/2013/Sep/IMAGE-3.jpg').yields(true);
|
fs.exists.withArgs(path.resolve('./content/images/2013/Sep/IMAGE-3.jpg')).yields(true);
|
||||||
fs.exists.withArgs('content/images/2013/Sep/IMAGE-4.jpg').yields(false);
|
fs.exists.withArgs(path.resolve('./content/images/2013/Sep/IMAGE-4.jpg')).yields(false);
|
||||||
|
|
||||||
// windows setup
|
// windows setup
|
||||||
fs.exists.withArgs('content\\images\\2013\\Sep\\IMAGE.jpg').yields(true);
|
fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE.jpg')).yields(true);
|
||||||
fs.exists.withArgs('content\\images\\2013\\Sep\\IMAGE-1.jpg').yields(true);
|
fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-1.jpg')).yields(true);
|
||||||
fs.exists.withArgs('content\\images\\2013\\Sep\\IMAGE-2.jpg').yields(true);
|
fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-2.jpg')).yields(true);
|
||||||
fs.exists.withArgs('content\\images\\2013\\Sep\\IMAGE-3.jpg').yields(true);
|
fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-3.jpg')).yields(true);
|
||||||
fs.exists.withArgs('content\\images\\2013\\Sep\\IMAGE-4.jpg').yields(false);
|
fs.exists.withArgs(path.resolve('.\\content\\images\\2013\\Sep\\IMAGE-4.jpg')).yields(false);
|
||||||
|
|
||||||
localfilesystem.save(image).then(function (url) {
|
localfilesystem.save(image).then(function (url) {
|
||||||
url.should.equal('/content/images/2013/Sep/IMAGE-4.jpg');
|
url.should.equal('/content/images/2013/Sep/IMAGE-4.jpg');
|
||||||
|
|
Loading…
Reference in a new issue