@a11ywatch/core
Version:
a11ywatch central API
55 lines • 2.73 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.setWebsiteScore = void 0;
const update_1 = require("../../controllers/pages/update");
const websites_1 = require("../../controllers/websites");
const static_1 = require("../../static");
const pubsub_1 = require("../../../database/pubsub");
const collection_upsert_1 = require("../collection-upsert");
function setWebsiteScore({ domain, userId, duration, shutdown = false, }) {
return __awaiter(this, void 0, void 0, function* () {
const [website, websiteCollection] = yield (0, websites_1.getWebsite)({
domain,
userId,
});
const targetDomain = (website === null || website === void 0 ? void 0 : website.domain) || domain;
const { issuesInfo } = yield (0, update_1.generateWebsiteScore)({
domain: targetDomain,
userId,
all: (website === null || website === void 0 ? void 0 : website.subdomains) || (website === null || website === void 0 ? void 0 : website.tld),
});
if (issuesInfo && website) {
yield (0, collection_upsert_1.collectionUpsert)(Object.assign(Object.assign({}, website), { issuesInfo, crawlDuration: duration, shutdown }), [websiteCollection, !!website], {
searchProps: {
domain: targetDomain,
userId,
},
});
}
try {
yield pubsub_1.pubsub.publish(static_1.CRAWL_COMPLETE, {
crawlComplete: {
userId,
domain: website === null || website === void 0 ? void 0 : website.domain,
accessScoreAverage: issuesInfo === null || issuesInfo === void 0 ? void 0 : issuesInfo.accessScoreAverage,
shutdown,
},
});
}
catch (e) {
console.error(e);
}
return Promise.resolve(true);
});
}
exports.setWebsiteScore = setWebsiteScore;
//# sourceMappingURL=score.js.map
;