2016-08-23 15:07:25 +03:00
|
|
|
// # Themes API
|
|
|
|
// RESTful API for Themes
|
2017-08-15 14:29:27 +03:00
|
|
|
var debug = require('ghost-ignition').debug('api:themes'),
|
2017-03-13 23:13:17 +03:00
|
|
|
Promise = require('bluebird'),
|
2016-08-23 15:07:25 +03:00
|
|
|
fs = require('fs-extra'),
|
2017-09-12 18:31:14 +03:00
|
|
|
apiUtils = require('./utils'),
|
2016-08-23 15:07:25 +03:00
|
|
|
errors = require('../errors'),
|
2016-08-25 11:36:12 +03:00
|
|
|
events = require('../events'),
|
2016-08-23 15:07:25 +03:00
|
|
|
i18n = require('../i18n'),
|
2017-09-12 18:31:14 +03:00
|
|
|
logging = require('../logging'),
|
2017-03-13 14:44:44 +03:00
|
|
|
settingsModel = require('../models/settings').Settings,
|
2017-03-08 13:46:03 +03:00
|
|
|
settingsCache = require('../settings/cache'),
|
2017-02-22 02:26:19 +03:00
|
|
|
themeUtils = require('../themes'),
|
2017-03-02 19:53:48 +03:00
|
|
|
themeList = themeUtils.list,
|
2016-08-23 15:07:25 +03:00
|
|
|
themes;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ## Themes API Methods
|
|
|
|
*
|
|
|
|
* **See:** [API Methods](index.js.html#api%20methods)
|
|
|
|
*/
|
|
|
|
themes = {
|
2017-10-10 15:36:35 +03:00
|
|
|
/**
|
|
|
|
* Every role can browse all themes. The response contains a list of all available themes in your content folder.
|
|
|
|
* The active theme get's marked as `active:true` and contains an extra object `templates`, which
|
|
|
|
* contains the custom templates of the active theme. These custom templates are used to show a dropdown
|
|
|
|
* in the PSM to be able to choose a custom post template.
|
|
|
|
*/
|
2017-03-20 21:02:44 +03:00
|
|
|
browse: function browse(options) {
|
|
|
|
return apiUtils
|
|
|
|
// Permissions
|
|
|
|
.handlePermissions('themes', 'browse')(options)
|
|
|
|
// Main action
|
|
|
|
.then(function makeApiResult() {
|
|
|
|
// Return JSON result
|
|
|
|
return themeUtils.toJSON();
|
|
|
|
});
|
2017-02-21 17:59:03 +03:00
|
|
|
},
|
|
|
|
|
2017-03-08 13:46:03 +03:00
|
|
|
activate: function activate(options) {
|
|
|
|
var themeName = options.name,
|
|
|
|
newSettings = [{
|
2017-04-24 20:41:00 +03:00
|
|
|
key: 'active_theme',
|
2017-03-08 13:46:03 +03:00
|
|
|
value: themeName
|
2017-03-13 14:44:44 +03:00
|
|
|
}],
|
|
|
|
loadedTheme,
|
|
|
|
checkedTheme;
|
|
|
|
|
|
|
|
return apiUtils
|
2017-03-20 21:02:44 +03:00
|
|
|
// Permissions
|
2017-03-13 14:44:44 +03:00
|
|
|
.handlePermissions('themes', 'activate')(options)
|
2017-03-20 21:02:44 +03:00
|
|
|
// Validation
|
|
|
|
.then(function validateTheme() {
|
2017-03-13 14:44:44 +03:00
|
|
|
loadedTheme = themeList.get(themeName);
|
|
|
|
|
|
|
|
if (!loadedTheme) {
|
|
|
|
return Promise.reject(new errors.ValidationError({
|
|
|
|
message: i18n.t('notices.data.validation.index.themeCannotBeActivated', {themeName: themeName}),
|
2017-04-24 20:41:00 +03:00
|
|
|
context: 'active_theme'
|
2017-03-13 14:44:44 +03:00
|
|
|
}));
|
|
|
|
}
|
2017-03-08 13:46:03 +03:00
|
|
|
|
2017-03-13 14:44:44 +03:00
|
|
|
return themeUtils.validate.check(loadedTheme);
|
|
|
|
})
|
2017-03-20 21:02:44 +03:00
|
|
|
// Update setting
|
|
|
|
.then(function changeActiveThemeSetting(_checkedTheme) {
|
2017-03-13 14:44:44 +03:00
|
|
|
checkedTheme = _checkedTheme;
|
|
|
|
// We use the model, not the API here, as we don't want to trigger permissions
|
|
|
|
return settingsModel.edit(newSettings, options);
|
|
|
|
})
|
2017-03-20 21:02:44 +03:00
|
|
|
// Call activate
|
2017-03-13 14:44:44 +03:00
|
|
|
.then(function hasEditedSetting() {
|
2017-03-13 23:13:17 +03:00
|
|
|
// Activate! (sort of)
|
|
|
|
debug('Activating theme (method B on API "activate")', themeName);
|
|
|
|
themeUtils.activate(loadedTheme, checkedTheme);
|
|
|
|
|
2017-03-20 21:02:44 +03:00
|
|
|
// Return JSON result
|
2017-03-13 14:44:44 +03:00
|
|
|
return themeUtils.toJSON(themeName, checkedTheme);
|
|
|
|
});
|
2017-03-08 13:46:03 +03:00
|
|
|
},
|
|
|
|
|
2016-08-23 15:07:25 +03:00
|
|
|
upload: function upload(options) {
|
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
// consistent filename uploads
|
|
|
|
options.originalname = options.originalname.toLowerCase();
|
|
|
|
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
var zip = {
|
2016-10-06 15:27:35 +03:00
|
|
|
path: options.path,
|
|
|
|
name: options.originalname,
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
shortName: themeUtils.storage.getSanitizedFileName(options.originalname.split('.zip')[0])
|
2017-03-13 14:44:44 +03:00
|
|
|
},
|
|
|
|
checkedTheme;
|
2016-08-23 15:07:25 +03:00
|
|
|
|
|
|
|
// check if zip name is casper.zip
|
|
|
|
if (zip.name === 'casper.zip') {
|
2016-10-06 15:27:35 +03:00
|
|
|
throw new errors.ValidationError({message: i18n.t('errors.api.themes.overrideCasper')});
|
2016-08-23 15:07:25 +03:00
|
|
|
}
|
|
|
|
|
2017-03-20 21:02:44 +03:00
|
|
|
return apiUtils
|
|
|
|
// Permissions
|
|
|
|
.handlePermissions('themes', 'add')(options)
|
|
|
|
// Validation
|
2017-03-13 14:44:44 +03:00
|
|
|
.then(function validateTheme() {
|
|
|
|
return themeUtils.validate.check(zip, true);
|
2016-08-23 15:07:25 +03:00
|
|
|
})
|
2017-03-20 21:02:44 +03:00
|
|
|
// More validation (existence check)
|
2017-03-13 14:44:44 +03:00
|
|
|
.then(function checkExists(_checkedTheme) {
|
|
|
|
checkedTheme = _checkedTheme;
|
2016-08-23 15:07:25 +03:00
|
|
|
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
return themeUtils.storage.exists(zip.shortName);
|
2016-08-23 15:07:25 +03:00
|
|
|
})
|
2017-03-20 21:02:44 +03:00
|
|
|
// If the theme existed we need to delete it
|
|
|
|
.then(function removeOldTheme(themeExists) {
|
2016-08-23 15:07:25 +03:00
|
|
|
// delete existing theme
|
|
|
|
if (themeExists) {
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
return themeUtils.storage.delete(zip.shortName);
|
2016-08-23 15:07:25 +03:00
|
|
|
}
|
|
|
|
})
|
2017-03-20 21:02:44 +03:00
|
|
|
.then(function storeNewTheme() {
|
2016-08-25 11:36:12 +03:00
|
|
|
events.emit('theme.uploaded', zip.shortName);
|
2016-08-23 15:07:25 +03:00
|
|
|
// store extracted theme
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
return themeUtils.storage.save({
|
2016-08-23 15:07:25 +03:00
|
|
|
name: zip.shortName,
|
2017-03-13 14:44:44 +03:00
|
|
|
path: checkedTheme.path
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
});
|
2016-08-23 15:07:25 +03:00
|
|
|
})
|
2017-03-20 21:02:44 +03:00
|
|
|
.then(function loadNewTheme() {
|
2017-03-13 14:44:44 +03:00
|
|
|
// Loads the theme from the filesystem
|
|
|
|
// Sets the theme on the themeList
|
2017-03-02 19:53:48 +03:00
|
|
|
return themeUtils.loadOne(zip.shortName);
|
2016-08-23 15:07:25 +03:00
|
|
|
})
|
2017-03-20 21:02:44 +03:00
|
|
|
.then(function activateAndReturn(loadedTheme) {
|
2017-03-13 23:13:17 +03:00
|
|
|
// If this is the active theme, we are overriding
|
|
|
|
// This is a special case of activation
|
2017-04-24 20:41:00 +03:00
|
|
|
if (zip.shortName === settingsCache.get('active_theme')) {
|
2017-03-13 23:13:17 +03:00
|
|
|
// Activate! (sort of)
|
|
|
|
debug('Activating theme (method C, on API "override")', zip.shortName);
|
|
|
|
themeUtils.activate(loadedTheme, checkedTheme);
|
|
|
|
}
|
|
|
|
|
2017-03-13 14:44:44 +03:00
|
|
|
// @TODO: unify the name across gscan and Ghost!
|
|
|
|
return themeUtils.toJSON(zip.shortName, checkedTheme);
|
2016-08-23 15:07:25 +03:00
|
|
|
})
|
|
|
|
.finally(function () {
|
2017-03-13 14:44:44 +03:00
|
|
|
// @TODO we should probably do this as part of saving the theme
|
2016-08-23 15:07:25 +03:00
|
|
|
// remove zip upload from multer
|
|
|
|
// happens in background
|
2017-06-01 15:11:50 +03:00
|
|
|
Promise.promisify(fs.remove)(zip.path)
|
2016-08-23 15:07:25 +03:00
|
|
|
.catch(function (err) {
|
2016-10-06 15:27:35 +03:00
|
|
|
logging.error(new errors.GhostError({err: err}));
|
2016-08-23 15:07:25 +03:00
|
|
|
});
|
|
|
|
|
2017-03-13 14:44:44 +03:00
|
|
|
// @TODO we should probably do this as part of saving the theme
|
2016-08-23 15:07:25 +03:00
|
|
|
// remove extracted dir from gscan
|
|
|
|
// happens in background
|
2017-03-13 14:44:44 +03:00
|
|
|
if (checkedTheme) {
|
2017-06-01 15:11:50 +03:00
|
|
|
Promise.promisify(fs.remove)(checkedTheme.path)
|
2016-08-23 15:07:25 +03:00
|
|
|
.catch(function (err) {
|
2016-10-06 15:27:35 +03:00
|
|
|
logging.error(new errors.GhostError({err: err}));
|
2016-08-23 15:07:25 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
download: function download(options) {
|
|
|
|
var themeName = options.name,
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
theme = themeList.get(themeName);
|
2016-08-23 15:07:25 +03:00
|
|
|
|
|
|
|
if (!theme) {
|
2016-10-06 15:27:35 +03:00
|
|
|
return Promise.reject(new errors.BadRequestError({message: i18n.t('errors.api.themes.invalidRequest')}));
|
2016-08-23 15:07:25 +03:00
|
|
|
}
|
|
|
|
|
2017-03-20 21:02:44 +03:00
|
|
|
return apiUtils
|
|
|
|
// Permissions
|
|
|
|
.handlePermissions('themes', 'read')(options)
|
|
|
|
.then(function sendTheme() {
|
2016-08-25 11:36:12 +03:00
|
|
|
events.emit('theme.downloaded', themeName);
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
return themeUtils.storage.serve({
|
|
|
|
name: themeName
|
|
|
|
});
|
2016-08-23 15:07:25 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* remove theme zip
|
|
|
|
* remove theme folder
|
|
|
|
*/
|
|
|
|
destroy: function destroy(options) {
|
2017-03-20 21:02:44 +03:00
|
|
|
var themeName = options.name,
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
theme;
|
2016-08-23 15:07:25 +03:00
|
|
|
|
2017-03-20 21:02:44 +03:00
|
|
|
return apiUtils
|
|
|
|
// Permissions
|
|
|
|
.handlePermissions('themes', 'destroy')(options)
|
|
|
|
// Validation
|
|
|
|
.then(function validateTheme() {
|
|
|
|
if (themeName === 'casper') {
|
2016-10-06 15:27:35 +03:00
|
|
|
throw new errors.ValidationError({message: i18n.t('errors.api.themes.destroyCasper')});
|
2016-08-23 15:07:25 +03:00
|
|
|
}
|
|
|
|
|
2017-04-24 20:41:00 +03:00
|
|
|
if (themeName === settingsCache.get('active_theme')) {
|
2017-03-13 14:44:44 +03:00
|
|
|
throw new errors.ValidationError({message: i18n.t('errors.api.themes.destroyActive')});
|
|
|
|
}
|
|
|
|
|
2017-03-20 21:02:44 +03:00
|
|
|
theme = themeList.get(themeName);
|
2016-08-23 15:07:25 +03:00
|
|
|
|
|
|
|
if (!theme) {
|
2016-10-06 15:27:35 +03:00
|
|
|
throw new errors.NotFoundError({message: i18n.t('errors.api.themes.themeDoesNotExist')});
|
2016-08-23 15:07:25 +03:00
|
|
|
}
|
|
|
|
|
2017-03-20 21:02:44 +03:00
|
|
|
// Actually do the deletion here
|
😱 🎨 Refactor storage adapter (#8229)
refs #7687
There are four main changes in this PR:
we have outsourced the base storage adapter to npm, because for storage developers it's annoying to inherit from a script within Ghost
we hacked theme storage handling into the default local storage adapter - this was reverted, instead we have added a static theme storage here
use classes instead of prototyping
optimise the storage adapter in general - everything is explained in each commit
----
* rename local-file-store to LocalFileStorage
I would like to keep the name pattern i have used for scheduling.
If a file is a class, the file name reflects the class name.
We can discuss this, if concerns are raised.
* Transform LocalFileStorage to class and inherit from new base
- inherit from npm ghost-storage-base
- rewrite to class
- no further refactoring, happens later
* Rename core/test/unit/storage/local-file-store_spec.js -> core/test/unit/storage/LocalFileStorage_spec.js
* Fix wrong require in core/test/unit/storage/LocalFileStorage_spec.js
* remove base storage and test
- see https://github.com/kirrg001/Ghost-Storage-Base
- the test has moved to this repo as well
* Use npm ghost-storage-base in storage/index.js
* remove the concept of getStorage('themes')
This concept was added when we added themes as a feature.
Back then, we have changed the local storage adapter to support images and themes.
This has added some hacks into the local storage adapters.
We want to revert this change and add a simple static theme storage.
Will adapt the api/themes layer in the next commits.
* Revert LocalFileStorage
- revert serve
- revert delete
* add storagePath as property to LocalFileStorage
- define one property which holds the storage path
- could be considered to pass from outside, but found that not helpful, as other storage adapters do not need this property
- IMPORTANT: save has no longer a targetDir option, because this was used to pass the alternative theme storage path
- IMPORTANT: exists has now an alternative targetDir, this makes sense, because
- you can either ask the storage exists('my-file') and it will look in the base storage path
- or you pass a specific path where to look exists('my-file', /path/to/dir)
* LocalFileStorage: get rid of store pattern
- getUniqueFileName(THIS)
- this doesn't make sense, instances always have access to this by default
* Add static theme storage
- inherits from the local file storage, because they both operate on the file system
- IMPORTANT: added a TODO to consider a merge of themes/loader and themes/storage
- but will be definitely not part of this PR
* Use new static theme storage in api/themes
- storage functions are simplified!
* Add https://github.com/kirrg001/Ghost-Storage-Base as dependency
- tarball for now, as i am still testing
- will release if PR review get's accepted
* Adapt tests and jscs/jshint
* 🐛 fix storage.read in favicon utility
- wrong implementation of error handling
* 🎨 optimise error messages for custom storage adapter errors
* little renaming in the storage utlity
- purpose is to have access to the custom storage instance and to the custom storage class
- see next commit why
* optimise instanceof base storage
- instanceof is always tricky in javascript
- if multiple modules exist, it can happen that instanceof is false
* fix getTargetDir
- the importer uses the `targetDir` option to ensure that images land in the correct folder
* ghost-storage-base@0.0.1 package.json dependency
2017-04-05 17:10:34 +03:00
|
|
|
return themeUtils.storage.delete(themeName);
|
2016-08-23 15:07:25 +03:00
|
|
|
})
|
2017-03-20 21:02:44 +03:00
|
|
|
// And some extra stuff to maintain state here
|
|
|
|
.then(function deleteTheme() {
|
|
|
|
themeList.del(themeName);
|
|
|
|
events.emit('theme.deleted', themeName);
|
2017-03-08 13:46:03 +03:00
|
|
|
// Delete returns an empty 204 response
|
2016-08-23 15:07:25 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = themes;
|