mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-30 22:34:01 -05:00
revert writing / retrieving public files from tmp dir
This commit is contained in:
parent
61bd938280
commit
d85ef0a4d8
2 changed files with 1 additions and 50 deletions
|
@ -1,5 +1,3 @@
|
|||
const crypto = require('crypto');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const {URL} = require('url');
|
||||
|
||||
|
@ -66,24 +64,6 @@ const isPrivacyDisabled = function isPrivacyDisabled(privacyFlag) {
|
|||
return this.get('privacy')[privacyFlag] === false;
|
||||
};
|
||||
|
||||
/** @type {string|null} */
|
||||
let processTmpDirPath = null;
|
||||
|
||||
/**
|
||||
* Get a tmp dir path for the current process
|
||||
*
|
||||
* @returns {string} - tmp dir path for the current process
|
||||
*/
|
||||
function getProcessTmpDirPath() {
|
||||
// Memoize the computed path to avoid re-computing it on each call - The
|
||||
// value should not change during the lifetime of the process.
|
||||
if (processTmpDirPath === null) {
|
||||
processTmpDirPath = path.join(os.tmpdir(), `ghost_${crypto.randomUUID()}`);
|
||||
}
|
||||
|
||||
return processTmpDirPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @callback getContentPathFn
|
||||
* @param {string} type - the type of context you want the path for
|
||||
|
@ -108,7 +88,7 @@ const getContentPath = function getContentPath(type) {
|
|||
case 'settings':
|
||||
return path.join(this.get('paths:contentPath'), 'settings/');
|
||||
case 'public':
|
||||
return path.join(getProcessTmpDirPath(this), 'public/');
|
||||
return path.join(this.get('paths:contentPath'), 'public/');
|
||||
default:
|
||||
// new Error is allowed here, as we do not want config to depend on @tryghost/error
|
||||
// @TODO: revisit this decision when @tryghost/error is no longer dependent on all of ghost-ignition
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
const os = require('os');
|
||||
const should = require('should');
|
||||
|
||||
const configUtils = require('../../../utils/configUtils');
|
||||
|
||||
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
||||
|
||||
describe('vhost utils', function () {
|
||||
beforeEach(function () {
|
||||
configUtils.set('url', 'http://ghost.blog');
|
||||
|
@ -56,29 +53,3 @@ describe('vhost utils', function () {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getContentPath', function () {
|
||||
it('should return the correct path for type: public', function () {
|
||||
const publicPath = configUtils.config.getContentPath('public');
|
||||
|
||||
// Path should be in the tmpdir
|
||||
const tmpdir = os.tmpdir();
|
||||
|
||||
publicPath.startsWith(tmpdir).should.be.true();
|
||||
|
||||
// Path should end with /public/
|
||||
publicPath.endsWith('/public/').should.be.true();
|
||||
|
||||
// Path should include /ghost_
|
||||
publicPath.includes('/ghost_').should.be.true();
|
||||
|
||||
// Path should contain a uuid at the correct location
|
||||
const publicPathParts = publicPath.split('/');
|
||||
const uuidPart = publicPathParts[publicPathParts.length - 3].replace('ghost_', '');
|
||||
|
||||
UUID_REGEX.test(uuidPart).should.be.true();
|
||||
|
||||
// Path should be memoized
|
||||
configUtils.config.getContentPath('public').should.eql(publicPath);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue