Set logging searches to off by default, add setter function
This commit is contained in:
16
index.js
16
index.js
@@ -7,7 +7,8 @@ function Searxng(matrixClient) {
|
||||
this.roomCooldowns = new Map();
|
||||
this.roomUserWhitelists = new Map();
|
||||
this.searxngInstance = "";
|
||||
this.searxngParameters = "enabled_engines=duckduckgo images__images,google images__images,bing images__images&disabled_engines=flickr__images,nyaa__images,qwant images__images,artic__images,deviantart__images,library of congress__images,unsplash__images,openverse__images"
|
||||
this.searxngParameters = "enabled_engines=duckduckgo images__images,google images__images,bing images__images&disabled_engines=flickr__images,nyaa__images,qwant images__images,artic__images,deviantart__images,library of congress__images,unsplash__images,openverse__images";
|
||||
this.logSearches = false;
|
||||
}
|
||||
|
||||
Searxng.prototype.setUploadMatrixClient = function(uploadMatrixClient){ this.uploadMatrixClient = uploadMatrixClient; };
|
||||
@@ -18,9 +19,11 @@ Searxng.prototype.setRoomCooldowns = function(roomCooldowns){ this.roomCooldowns
|
||||
Searxng.prototype.setRoomUserWhitelists = function(roomUserWhitelists){ this.roomUserWhitelists = roomUserWhitelists; };
|
||||
Searxng.prototype.setSearxngInstance = function(searxngInstance){ this.searxngInstance = searxngInstance; };
|
||||
Searxng.prototype.setSearxngParameters = function(searxngParameters){ this.searxngParameters = searxngParameters; };
|
||||
Searxng.prototype.setLogSearches = function(logSearches){ this.logSearches = logSearches; };
|
||||
|
||||
const axios = require('axios');
|
||||
const request = require('request');
|
||||
//const LogLevel = require('loglevel');
|
||||
|
||||
const lastCooldownTimes = new Map();
|
||||
const lastWarningTimes = new Map();
|
||||
@@ -33,9 +36,9 @@ const searxngCommands = [
|
||||
unsafeImageSearchCmd
|
||||
];
|
||||
|
||||
function sendImage(results, resultIndex, roomId, name, searchCommand, retryCount, matrixClient, uploadMatrixClient, requester) {
|
||||
function sendImage(results, resultIndex, roomId, name, searchCommand, retryCount, matrixClient, uploadMatrixClient, requester, logSearches) {
|
||||
|
||||
const resultObj = results[resultIndex]
|
||||
const resultObj = results[resultIndex];
|
||||
var imageURL;
|
||||
if (typeof resultObj === 'undefined' || resultObj == null || typeof resultObj.img_src === 'undefined' || resultObj.img_src == null || resultObj.img_src === '') {
|
||||
imageURL = "";
|
||||
@@ -51,7 +54,9 @@ function sendImage(results, resultIndex, roomId, name, searchCommand, retryCount
|
||||
try {
|
||||
const imageResponse = await axios.get(imageURL, { responseType: 'arraybuffer' });
|
||||
var imageType = imageResponse.headers['content-type'];
|
||||
if (logSearches) {
|
||||
console.debug("[Search text: "+searchCommand+"], "+"[imageURL: "+imageURL+"], "+"[retryCount: "+retryCount+"]"+", [Engines: "+resultObj.engines.join(",")+"]"+", [content-type: "+imageType+"]");
|
||||
}
|
||||
const uploadResponse = await uploadMatrixClient.uploadContent(imageResponse.data, { rawResponse: false, type: imageType });
|
||||
const matrixUrl = uploadResponse.content_uri;
|
||||
var filename;
|
||||
@@ -125,7 +130,7 @@ function sendImage(results, resultIndex, roomId, name, searchCommand, retryCount
|
||||
else {
|
||||
console.warn("Trying next result for '"+searchCommand+"'");
|
||||
console.error(error);
|
||||
sendImage(results, resultIndex, roomId, name, searchCommand, retryCount, matrixClient, uploadMatrixClient, requester);
|
||||
sendImage(results, resultIndex, roomId, name, searchCommand, retryCount, matrixClient, uploadMatrixClient, requester, logSearches);
|
||||
}
|
||||
}
|
||||
})();
|
||||
@@ -223,6 +228,7 @@ Searxng.prototype.handleMessage = function(event, room) {
|
||||
this.matrixClient.sendTyping(room.roomId, true, 3000);
|
||||
const matrixClient = this.matrixClient;
|
||||
const uploadMatrixClient = this.uploadMatrixClient;
|
||||
const logSearches = this.logSearches;
|
||||
request(searchURL, function (error, response, body) {
|
||||
try {
|
||||
if (error == null || error == "") {
|
||||
@@ -238,7 +244,7 @@ Searxng.prototype.handleMessage = function(event, room) {
|
||||
return;
|
||||
}
|
||||
|
||||
sendImage(results, resultIndex, room.roomId, name.trim(), event.getContent().body, 0, matrixClient, uploadMatrixClient, event.getSender());
|
||||
sendImage(results, resultIndex, room.roomId, name.trim(), event.getContent().body, 0, matrixClient, uploadMatrixClient, event.getSender(), logSearches);
|
||||
}
|
||||
else {
|
||||
matrixClient.sendNotice(room.roomId, "Error occurred during \"" + event.getContent().body + "\"");
|
||||
|
Reference in New Issue
Block a user