Set logging searches to off by default, add setter function
This commit is contained in:
20
index.js
20
index.js
@@ -7,7 +7,8 @@ function Searxng(matrixClient) {
|
|||||||
this.roomCooldowns = new Map();
|
this.roomCooldowns = new Map();
|
||||||
this.roomUserWhitelists = new Map();
|
this.roomUserWhitelists = new Map();
|
||||||
this.searxngInstance = "";
|
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; };
|
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.setRoomUserWhitelists = function(roomUserWhitelists){ this.roomUserWhitelists = roomUserWhitelists; };
|
||||||
Searxng.prototype.setSearxngInstance = function(searxngInstance){ this.searxngInstance = searxngInstance; };
|
Searxng.prototype.setSearxngInstance = function(searxngInstance){ this.searxngInstance = searxngInstance; };
|
||||||
Searxng.prototype.setSearxngParameters = function(searxngParameters){ this.searxngParameters = searxngParameters; };
|
Searxng.prototype.setSearxngParameters = function(searxngParameters){ this.searxngParameters = searxngParameters; };
|
||||||
|
Searxng.prototype.setLogSearches = function(logSearches){ this.logSearches = logSearches; };
|
||||||
|
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const request = require('request');
|
const request = require('request');
|
||||||
|
//const LogLevel = require('loglevel');
|
||||||
|
|
||||||
const lastCooldownTimes = new Map();
|
const lastCooldownTimes = new Map();
|
||||||
const lastWarningTimes = new Map();
|
const lastWarningTimes = new Map();
|
||||||
@@ -33,9 +36,9 @@ const searxngCommands = [
|
|||||||
unsafeImageSearchCmd
|
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;
|
var imageURL;
|
||||||
if (typeof resultObj === 'undefined' || resultObj == null || typeof resultObj.img_src === 'undefined' || resultObj.img_src == null || resultObj.img_src === '') {
|
if (typeof resultObj === 'undefined' || resultObj == null || typeof resultObj.img_src === 'undefined' || resultObj.img_src == null || resultObj.img_src === '') {
|
||||||
imageURL = "";
|
imageURL = "";
|
||||||
@@ -51,8 +54,10 @@ function sendImage(results, resultIndex, roomId, name, searchCommand, retryCount
|
|||||||
try {
|
try {
|
||||||
const imageResponse = await axios.get(imageURL, { responseType: 'arraybuffer' });
|
const imageResponse = await axios.get(imageURL, { responseType: 'arraybuffer' });
|
||||||
var imageType = imageResponse.headers['content-type'];
|
var imageType = imageResponse.headers['content-type'];
|
||||||
console.debug("[Search text: "+searchCommand+"], "+"[imageURL: "+imageURL+"], "+"[retryCount: "+retryCount+"]"+", [Engines: "+resultObj.engines.join(",")+"]"+", [content-type: "+imageType+"]");
|
if (logSearches) {
|
||||||
const uploadResponse = await uploadMatrixClient.uploadContent(imageResponse.data, { rawResponse: false, type: imageType });
|
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;
|
const matrixUrl = uploadResponse.content_uri;
|
||||||
var filename;
|
var filename;
|
||||||
switch(imageType) {
|
switch(imageType) {
|
||||||
@@ -125,7 +130,7 @@ function sendImage(results, resultIndex, roomId, name, searchCommand, retryCount
|
|||||||
else {
|
else {
|
||||||
console.warn("Trying next result for '"+searchCommand+"'");
|
console.warn("Trying next result for '"+searchCommand+"'");
|
||||||
console.error(error);
|
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);
|
this.matrixClient.sendTyping(room.roomId, true, 3000);
|
||||||
const matrixClient = this.matrixClient;
|
const matrixClient = this.matrixClient;
|
||||||
const uploadMatrixClient = this.uploadMatrixClient;
|
const uploadMatrixClient = this.uploadMatrixClient;
|
||||||
|
const logSearches = this.logSearches;
|
||||||
request(searchURL, function (error, response, body) {
|
request(searchURL, function (error, response, body) {
|
||||||
try {
|
try {
|
||||||
if (error == null || error == "") {
|
if (error == null || error == "") {
|
||||||
@@ -238,7 +244,7 @@ Searxng.prototype.handleMessage = function(event, room) {
|
|||||||
return;
|
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 {
|
else {
|
||||||
matrixClient.sendNotice(room.roomId, "Error occurred during \"" + event.getContent().body + "\"");
|
matrixClient.sendNotice(room.roomId, "Error occurred during \"" + event.getContent().body + "\"");
|
||||||
|
Reference in New Issue
Block a user