mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 01:41:46 +03:00
605b042a33
issue https://github.com/TryGhost/Team/issues/859 - Added invalidation to PUT /authentication/setup - Added invalidation to POST /db - Added invalidation to DELETE /db - Added invalidation to GET /slugs/:type/:name - Removed invalidation from PUT /users/:id/token
51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
const models = require('../../models');
|
|
const i18n = require('../../../shared/i18n');
|
|
const errors = require('@tryghost/errors');
|
|
|
|
const allowedTypes = {
|
|
post: models.Post,
|
|
tag: models.Tag,
|
|
user: models.User
|
|
};
|
|
|
|
module.exports = {
|
|
docName: 'slugs',
|
|
generate: {
|
|
headers: {
|
|
cacheInvalidate: true
|
|
},
|
|
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;
|
|
});
|
|
}
|
|
}
|
|
};
|