@sugarcube/plugin-google
Version:
A plugin for SugarCube to interact with some google services.
78 lines (73 loc) • 2.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.imagesEntity = exports.searchEntity = exports.entity = exports.reverseImageSearchFromFile = exports.imageSearch = exports.googleSearch = void 0;
var _fp = require("lodash/fp");
var _browser = require("./browser");
var _parsers = require("./parsers");
const searchUrl = "https://google.com/search";
const imagesUrl = "https://images.google.com";
const googleSearch = (0, _fp.curry)((headless, term) => (0, _browser.search)(searchUrl, headless, term).then((0, _parsers.parseSearches)(searchUrl)));
exports.googleSearch = googleSearch;
const imageSearch = (0, _fp.curry)((scrollCount, headless, term) => (0, _browser.images)(searchUrl, scrollCount, headless, term).then(_parsers.parseImages));
exports.imageSearch = imageSearch;
const reverseImageSearchFromFile = (0, _fp.curry)((headless, term) => (0, _browser.reverseImagesFromFile)(imagesUrl, headless, term).then(_parsers.parseReverseImages));
exports.reverseImageSearchFromFile = reverseImageSearchFromFile;
const entity = (0, _fp.curry)((source, unit) => // TODO: Replace with mergeWith to merge arrays properly.
(0, _fp.merge)(unit, {
_sc_source: source,
_sc_id_fields: ["href"],
_sc_content_fields: ["title"],
_sc_relations: [{
type: "url",
term: unit.href
}],
_sc_media: [{
type: "url",
term: unit.href
}]
}));
exports.entity = entity;
const searchEntity = (0, _fp.curry)((term, unit) => (0, _fp.merge)(unit, {
_sc_pubdates: {
source: unit.date
},
_sc_queries: [{
type: "google_search",
term
}],
_sc_content_fields: ["title", "description"]
}));
exports.searchEntity = searchEntity;
const imagesEntity = (0, _fp.curry)((term, unit) => (0, _fp.merge)(unit, {
_sc_content_fields: [unit.imgHref],
_sc_queries: [{
type: "google_images",
term
}],
_sc_relations: [{
type: "url",
term: unit.href
}, {
type: "url",
term: unit.imgHref
}],
_sc_media: [{
type: "image",
term: unit.href
}, {
type: "url",
term: unit.imgHref
}]
}));
exports.imagesEntity = imagesEntity;
var _default = {
googleSearch,
imageSearch,
reverseImageSearchFromFile,
entity,
searchEntity,
imagesEntity
};
exports.default = _default;