Stackedit/src/services/providers/wordpressProvider.js

42 lines
986 B
JavaScript
Raw Normal View History

2017-09-26 22:54:26 +00:00
import store from '../../store';
import wordpressHelper from './helpers/wordpressHelper';
2018-04-27 14:37:05 +00:00
import Provider from './common/Provider';
2017-09-26 22:54:26 +00:00
2018-04-27 14:37:05 +00:00
export default new Provider({
2017-09-26 22:54:26 +00:00
id: 'wordpress',
2018-07-17 19:58:40 +00:00
name: 'WordPress',
2018-09-19 08:59:22 +00:00
getToken({ sub }) {
return store.getters['data/wordpressTokensBySub'][sub];
2017-09-26 22:54:26 +00:00
},
2018-09-19 08:59:22 +00:00
getLocationUrl({ siteId, postId }) {
return `https://wordpress.com/post/${siteId}/${postId}`;
2017-09-26 22:54:26 +00:00
},
getLocationDescription({ postId }) {
return postId;
2017-09-26 22:54:26 +00:00
},
2018-05-13 13:27:33 +00:00
async publish(token, html, metadata, publishLocation) {
const post = await wordpressHelper.uploadPost({
...publishLocation,
...metadata,
2017-09-26 22:54:26 +00:00
token,
2018-05-13 13:27:33 +00:00
content: html,
});
return {
...publishLocation,
siteId: `${post.site_ID}`,
postId: `${post.ID}`,
};
2017-09-26 22:54:26 +00:00
},
makeLocation(token, domain, postId) {
const location = {
providerId: this.id,
sub: token.sub,
domain,
};
if (postId) {
location.postId = postId;
}
return location;
},
});