mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 02:11:44 +03:00
829e8ed010
- Having these as destructured from the same package is hindering refactoring now - Events should really only ever be used server-side - i18n should be a shared module for now so it can be used everywhere until we figure out something better - Having them seperate also allows us to lint them properly
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
const models = require('../../models');
|
|
const i18n = require('../../lib/common/i18n');
|
|
const errors = require('@tryghost/errors');
|
|
|
|
const allowedTypes = {
|
|
post: models.Post,
|
|
tag: models.Tag,
|
|
user: models.User
|
|
};
|
|
|
|
module.exports = {
|
|
docName: 'slugs',
|
|
generate: {
|
|
options: [
|
|
'include',
|
|
'type'
|
|
],
|
|
data: [
|
|
'name'
|
|
],
|
|
permissions: true,
|
|
validation: {
|
|
options: {
|
|
type: {
|
|
required: true,
|
|
values: Object.keys(allowedTypes)
|
|
}
|
|
},
|
|
data: {
|
|
name: {
|
|
required: true
|
|
}
|
|
}
|
|
},
|
|
query(frame) {
|
|
return models.Base.Model.generateSlug(allowedTypes[frame.options.type], frame.data.name, {status: 'all'})
|
|
.then((slug) => {
|
|
if (!slug) {
|
|
return Promise.reject(new errors.GhostError({
|
|
message: i18n.t('errors.api.slugs.couldNotGenerateSlug')
|
|
}));
|
|
}
|
|
return slug;
|
|
});
|
|
}
|
|
}
|
|
};
|