Merge pull request #1429 from valadaptive/eslint-fixes-1

ESLint fixes, part 1
This commit is contained in:
Cohee 2023-12-02 18:50:51 +02:00 committed by GitHub
commit 6be07e5ea5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 24 additions and 41 deletions

View File

@ -59,19 +59,9 @@ module.exports = {
'no-extra-semi': 'off',
'no-undef': 'off',
'no-prototype-builtins': 'off',
'no-unused-labels': 'off',
'no-extra-boolean-cast': 'off',
'require-yield': 'off',
'no-case-declarations': 'off',
'use-isnan': 'off',
'no-self-assign': 'off',
'no-unsafe-negation': 'off',
'no-constant-condition': 'off',
'no-empty': 'off',
'no-unsafe-finally': 'off',
'no-dupe-keys': 'off',
'no-irregular-whitespace': 'off',
'no-regex-spaces': 'off',
'no-fallthrough': 'off'
'no-constant-condition': ['error', {checkLoops: false}]
}
};

View File

@ -1,5 +1,3 @@
esversion: 6
import {
Generate,
characters,

View File

@ -178,7 +178,7 @@ async function onRegexEditorOpenClick(existingId) {
.filter(":checked")
.map(function () { return parseInt($(this).val()) })
.get()
.filter((e) => e !== NaN) || [],
.filter((e) => !isNaN(e)) || [],
disabled:
editorHtml
.find(`input[name="disabled"]`)

View File

@ -115,7 +115,6 @@ class ElevenLabsTtsProvider {
await this.fetchTtsVoiceObjects().catch(error => {
throw `TTS API key validation failed`
})
this.settings.apiKey = this.settings.apiKey
console.debug(`Saved new API_KEY: ${this.settings.apiKey}`)
$('#tts_status').text('')
this.onSettingsChange()

View File

@ -421,12 +421,12 @@ function completeCurrentAudioJob() {
/**
* Accepts an HTTP response containing audio/mpeg data, and puts the data as a Blob() on the queue for playback
* @param {*} response
* @param {Response} response
*/
async function addAudioJob(response) {
const audioData = await response.blob()
if (!audioData.type in ['audio/mpeg', 'audio/wav', 'audio/x-wav', 'audio/wave', 'audio/webm']) {
throw `TTS received HTTP response with invalid data format. Expecting audio/mpeg, got ${audioData.type}`
if (!audioData.type.startsWith('audio/')) {
throw `TTS received HTTP response with invalid data format. Expecting audio/*, got ${audioData.type}`
}
audioJobQueue.push(audioData)
console.debug('Pushed audio job to queue.')

View File

@ -1604,10 +1604,8 @@ export async function getGroupPastChats(groupId) {
} catch (err) {
console.error(err);
}
finally {
return chats;
}
}
export async function openGroupChat(groupId, chatId) {
const group = groups.find(x => x.id === groupId);

View File

@ -66,7 +66,9 @@ export function formatKoboldUrl(value) {
url.pathname = '/api';
}
return url.toString();
} catch { } // Just using URL as a validation check
} catch {
// Just using URL as a validation check
}
return null;
}

View File

@ -1696,10 +1696,8 @@ async function calculateLogitBias() {
result = {};
console.error(err);
}
finally {
return result;
}
}
class TokenHandler {
constructor(countTokenFn) {

View File

@ -1281,7 +1281,7 @@ export async function promptQuietForLoudResponse(who, text) {
} else if (who === 'char') {
text = characters[character_id].name + ": " + text;
} else if (who === 'raw') {
text = text;
// We don't need to modify the text
}
//text = `${text}${power_user.instruct.enabled ? '' : '\n'}${(power_user.always_force_name2 && who != 'raw') ? characters[character_id].name + ":" : ""}`

View File

@ -288,7 +288,6 @@ async function statMesProcess(line, type, characters, this_chid, oldMesssage) {
user_word_count: 0,
non_user_msg_count: 0,
user_msg_count: 0,
non_user_msg_count: 0,
total_swipe_count: 0,
date_first_chat: Date.now(),
date_last_chat: Date.now(),

View File

@ -174,7 +174,9 @@ function formatTextGenURL(value) {
url.pathname = '/api';
}
return url.toString();
} catch { } // Just using URL as a validation check
} catch {
// Just using URL as a validation check
}
return null;
}

View File

@ -1908,6 +1908,7 @@ async function checkWorldInfo(chat, maxContext) {
entries: [entry.content]
});
}
break;
default:
break;
}

View File

@ -118,7 +118,9 @@ if (fs.existsSync(whitelistPath)) {
try {
let whitelistTxt = fs.readFileSync(whitelistPath, 'utf-8');
whitelist = whitelistTxt.split("\n").filter(ip => ip).map(ip => ip.trim());
} catch (e) { }
} catch (e) {
// Ignore errors that may occur when reading the whitelist (e.g. permissions)
}
}
const whitelistMode = getConfigValue('whitelistMode', true);
@ -781,7 +783,7 @@ app.post("/getchat", jsonParser, function (request, response) {
const lines = data.split('\n');
// Iterate through the array of strings and parse each line as JSON
const jsonData = lines.map((l) => { try { return JSON.parse(l); } catch (_) { } }).filter(x => x);
const jsonData = lines.map((l) => { try { return JSON.parse(l); } catch (_) { return; } }).filter(x => x);
return response.send(jsonData);
} catch (error) {
console.error(error);
@ -1285,10 +1287,10 @@ async function charaWrite(img_url, data, target_img, response = undefined, mes =
for (let tEXtChunk of tEXtChunks) {
chunks.splice(chunks.indexOf(tEXtChunk), 1);
}
// Add new chunks before the IEND chunk
// Add new chunks before the IEND chunk
const base64EncodedData = Buffer.from(data, 'utf8').toString('base64');
chunks.splice(-1, 0, PNGtext.encode('chara', base64EncodedData));
//chunks.splice(-1, 0, text.encode('lorem', 'ipsum'));
//chunks.splice(-1, 0, text.encode('lorem', 'ipsum'));
writeFileAtomicSync(charactersPath + target_img + '.png', Buffer.from(encode(chunks)));
if (response !== undefined) response.send(mes);

View File

@ -118,9 +118,7 @@ function registerEndpoints(app, jsonParser) {
catch (err) {
console.log(err);
}
finally {
return response.send(output);
}
});
/**

View File

@ -133,9 +133,7 @@ function registerEndpoints(app, jsonParser, urlencodedParser) {
catch (err) {
console.log(err);
}
finally {
return response.send(sprites);
}
});
app.post('/api/sprites/delete', jsonParser, async (request, response) => {

View File

@ -12,9 +12,7 @@ const writeFileAtomicSync = require('write-file-atomic').sync;
*/
function safeStr(x) {
x = String(x);
for (let i = 0; i < 16; i++) {
x = x.replace(/ /g, ' ');
}
x = x.replace(/ +/g, ' ');
x = x.trim();
x = x.replace(/^[\s,.]+|[\s,.]+$/g, '');
return x;