mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +03:00
2887e416da
refs: TryGhost/Toolbox#147 * Replaces all references to isIgnitionError with isGhostError * Switches use of GhostError to InternalServerError - as GhostError is no longer public There are places where InternalServerError is not the valid error, and new errors should be added to the @tryghost/errors package to ensure that we can use semantically correct errors in those cases.
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
const models = require('../../models');
|
|
const tpl = require('@tryghost/tpl');
|
|
const errors = require('@tryghost/errors');
|
|
|
|
const messages = {
|
|
couldNotGenerateSlug: 'Could not generate slug.'
|
|
};
|
|
|
|
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.InternalServerError({
|
|
message: tpl(messages.couldNotGenerateSlug)
|
|
}));
|
|
}
|
|
return slug;
|
|
});
|
|
}
|
|
}
|
|
};
|