mirror of
https://github.com/searxng/searxng.git
synced 2026-06-07 02:17:16 +02:00
[feat] engines: add swisscows images engine
The implementation is basically a 1:1 port of the reverse engineered
swisscows JavaScript code. (it's been obfuscated, so I've restructured it
and made the variable names idiomatic instead of obfuscated var names like "a", "o", "i")
```js
/*
e: "/v5/images/search"
t: {
itemsCount: "50"
locale: "de-DE"
offset: "50"
query: "test"
spellcheck: "true"
}
*/
// HASH library used: https://github.com/h2non/jshashes
function generateNonceAndSignature(queryParams, urlPath) {
// urlPath = "/v5/images/search"
// sort keys alphabetically and join to query string
let queryStringSorted = '?' + U().stringify(queryParams, {
arrayFormat: 'repeat',
allowDots: !0
}).split('&').map(e => {
let[key, value] = e.split('=');
return [key, decodeURIComponent(value)]
}).sort((e, t) => e[0].localeCompare(t[0])).map(e => e.join('=')).join('&');
function caesarShift(str, offset = 13) {
const alphabet = 'abcdefghijklmnopqrstuvwxyz';
let result = [];
for (let a = 0; a < str.length; a++) {
let c = str[a],
alphabetIndex = alphabet.indexOf(c.toLowerCase());
if ( - 1 !== alphabetIndex) {
alphabetIndex += offset;
while (alphabetIndex >= alphabet.length) alphabetIndex -= alphabet.length;
c = c === c.toUpperCase() ? alphabet[alphabetIndex] : alphabet[alphabetIndex].toUpperCase()
}
result.push(c)
}
return result.join('')
}
const r = new (sha256Instance()).SHA256;
const random = randomString(32);
const randomShifted = caesarShift(random);
let to_hash = [urlPath, queryStringSorted, randomShifted].join('');
let signature = r.b64(to_hash);
signature = signature.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
return {
nonce: random,
signature: signature
}
}
function randomString(length) {
let t = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~',
n = '';
for (let r = 0; r < length; r++) n += t.charAt(Math.floor(Math.random() * t.length));
return n
}
```
This commit is contained in:
@@ -2540,6 +2540,11 @@ engines:
|
||||
disabled: true
|
||||
inactive: true
|
||||
|
||||
- name: swisscows images
|
||||
engine: swisscows_images
|
||||
shortcut: swi
|
||||
disabled: true
|
||||
|
||||
- name: wordnik
|
||||
engine: wordnik
|
||||
shortcut: wnik
|
||||
|
||||
Reference in New Issue
Block a user