2017-09-23 19:01:50 +00:00
|
|
|
import store from '../../store';
|
|
|
|
import googleHelper from './helpers/googleHelper';
|
2018-04-27 14:37:05 +00:00
|
|
|
import Provider from './common/Provider';
|
2017-09-23 19:01:50 +00:00
|
|
|
|
2018-04-27 14:37:05 +00:00
|
|
|
export default new Provider({
|
2017-09-23 19:01:50 +00:00
|
|
|
id: 'blogger',
|
2018-07-17 19:58:40 +00:00
|
|
|
name: 'Blogger',
|
2018-07-03 23:41:24 +00:00
|
|
|
getToken({ sub }) {
|
|
|
|
const token = store.getters['data/googleTokensBySub'][sub];
|
2017-09-23 19:01:50 +00:00
|
|
|
return token && token.isBlogger ? token : null;
|
|
|
|
},
|
2018-07-03 23:41:24 +00:00
|
|
|
getLocationUrl({ blogId, postId }) {
|
|
|
|
return `https://www.blogger.com/blogger.g?blogID=${blogId}#editor/target=post;postID=${postId}`;
|
2017-09-23 19:01:50 +00:00
|
|
|
},
|
2018-07-03 23:41:24 +00:00
|
|
|
getLocationDescription({ postId }) {
|
|
|
|
return postId;
|
2017-09-23 19:01:50 +00:00
|
|
|
},
|
2018-05-13 13:27:33 +00:00
|
|
|
async publish(token, html, metadata, publishLocation) {
|
|
|
|
const post = await googleHelper.uploadBlogger({
|
|
|
|
...publishLocation,
|
2017-09-23 19:01:50 +00:00
|
|
|
token,
|
2018-05-13 13:27:33 +00:00
|
|
|
title: metadata.title,
|
|
|
|
content: html,
|
|
|
|
labels: metadata.tags,
|
|
|
|
isDraft: metadata.status === 'draft',
|
|
|
|
published: metadata.date,
|
|
|
|
});
|
|
|
|
return {
|
|
|
|
...publishLocation,
|
|
|
|
blogId: post.blog.id,
|
|
|
|
postId: post.id,
|
|
|
|
};
|
2017-09-23 19:01:50 +00:00
|
|
|
},
|
|
|
|
makeLocation(token, blogUrl, postId) {
|
|
|
|
const location = {
|
|
|
|
providerId: this.id,
|
|
|
|
sub: token.sub,
|
|
|
|
blogUrl,
|
|
|
|
};
|
|
|
|
if (postId) {
|
|
|
|
location.postId = postId;
|
|
|
|
}
|
|
|
|
return location;
|
|
|
|
},
|
|
|
|
});
|