@sugarcube/plugin-instagram
Version:
A SugarCube plugin to query Instagram.
66 lines (60 loc) • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.postEntity = void 0;
var _fp = require("lodash/fp");
const TAG = /(?:#)([A-Za-z0-9_](?:(?:[A-Za-z0-9_]|(?:\.(?!\.))){0,28}(?:[A-Za-z0-9_]))?)/g;
const MENTION = /(?:@)([A-Za-z0-9_](?:(?:[A-Za-z0-9_]|(?:\.(?!\.))){0,28}(?:[A-Za-z0-9_]))?)/g;
const tags = str => str.match(TAG) || [];
const mentions = str => str.match(MENTION) || [];
const postEntity = (0, _fp.curry)((username, post) => {
const entity = {
postId: (0, _fp.get)("id", post),
postCode: (0, _fp.get)("code", post),
postUrl: (0, _fp.get)("link", post),
userId: (0, _fp.get)("user.id", post),
userFullName: (0, _fp.get)("user.full_name", post),
userProfilePicture: (0, _fp.get)("user.profile_picture", post),
userName: (0, _fp.get)("user.username", post),
imageUrl: (0, _fp.get)("images.standard_resolution.url", post),
caption: (0, _fp.get)("caption.text", post),
createdAt: (0, _fp.get)("caption.created_time", post),
likesCount: (0, _fp.get)("likes.count", post),
commentsCount: (0, _fp.get)("comments.count", post),
location: (0, _fp.get)("location.name", post),
hashtags: tags((0, _fp.getOr)("", "caption.text", post)),
mentions: mentions((0, _fp.getOr)("", "caption.text", post)),
_sc_id_fields: ["postId"],
_sc_content_fields: ["imageUrl", "caption"],
_sc_query: username
};
const lfMedia = [{
type: "url",
term: entity.postUrl
}, {
type: "image",
term: entity.imageUrl
}, {
type: "image",
term: entity.userProfilePicture
}];
const lfHashtags = (0, _fp.map)(term => ({
type: "hashtag",
term
}), entity.hashtags);
const lfMentions = (0, _fp.map)(term => ({
type: "mention",
term
}), entity.mentions);
const lfRelations = (0, _fp.flatten)([lfHashtags, lfMentions, lfMedia]);
return (0, _fp.merge)(entity, {
_sc_media: lfMedia,
_sc_relations: lfRelations
});
});
exports.postEntity = postEntity;
var _default = {
postEntity
};
exports.default = _default;