CJVT updates August and September 2026

This commit is contained in:
Luka Romih
2026-10-01 00:49:26 +02:00
parent fd02e25719
commit 83f73aeb58
135 changed files with 6146 additions and 1970 deletions
@@ -193,7 +193,10 @@ function handleEntryXml(
) {
debug(`TOTAL ENTRIES: ${progress.totalCount}`)
debug(`VALID ENTRIES: ${progress.validCount}`)
resolve()
resolve({
totalCount: progress.totalCount,
validCount: progress.validCount
})
}
}
}
@@ -0,0 +1,26 @@
const { readFile } = require('fs/promises')
const { insertSuggestionEntry } = require('./index')
// Import given JSON export of extraction term candidates into given dictionary.
exports.readJsonFileIntoDb = async (
userId,
dictionaryId,
importFilePath,
dbClient
) => {
const fileContent = await readFile(importFilePath, 'utf8')
const { terminoloski_kandidati: termCandidates } = JSON.parse(fileContent)
if (!Array.isArray(termCandidates)) {
throw Error('Invalid term candidates JSON: terminoloski_kandidati is not an array')
}
for (const {
kanonicnaoblika: term,
definicija: other
} of termCandidates) {
await insertSuggestionEntry(dbClient, dictionaryId, userId, term, other)
}
return { totalCount: termCandidates.length, validCount: 0 }
}
@@ -1,4 +1,5 @@
const xss = require('xss')
const db = require('../../db')
const { removeHtmlTags } = require('../../helpers')
const { searchEngineClient, ENTRY_INDEX } = require('../../search-engine')
const { DATA_FILES_PATH } = require('../../../config/settings')
@@ -353,3 +354,35 @@ exports.sanitizeField = {
return sanitize(string, markupFilter.mixedOther)
}
}
// Insert a single 'suggestion' status entry (as produced by extraction term
// candidates, whether imported directly or from a JSON export of them).
exports.insertSuggestionEntry = async (dbClient, dictionaryId, userId, term, other) => {
term = term ? exports.sanitizeField.toText(term) : null
other = other ? exports.sanitizeField.toText(other) : null
const values = [
dictionaryId,
false,
'suggestion',
term || null,
userId,
null,
null,
null,
null,
[],
null,
null,
null,
[],
other || null,
[],
null,
null,
null
]
const text = `SELECT entry_new (${db.genParamStr(values)})`
await dbClient.query(text, values)
}
+13
View File
@@ -22,6 +22,19 @@ exports.removeHtmlTags = text => {
return tagFilter.process(text)
}
// Escapes Postgres LIKE metacharacters (\, %, _) in a raw search string so
// it's matched literally rather than as a LIKE pattern - e.g. a user
// searching for a dictionary literally named "100%" gets that dictionary,
// not every dictionary. Backslash must be escaped first, or the escapes
// added for % and _ below would themselves get re-escaped.
//
// Wildcard search (*, ?), if ever added: translate user-facing '*' -> '%'
// and '?' -> '_' AFTER calling this function, on its return value - that
// way literal %, _, and \ in the search text stay literal while the
// user's own * and ? become real SQL wildcards.
exports.escapeLikePattern = value =>
value.replace(/\\/g, '\\\\').replace(/%/g, '\\%').replace(/_/g, '\\_')
// Returns setting value by its name from table instance_settings.
exports.getInstanceSetting = async settingName => {
const settingCacheName = `${INSTANCE_SETTING_NAMESPACE}:${settingName}`
+4
View File
@@ -9,6 +9,7 @@ exports.deserialize = {
status: user.status,
hitsPerPage: user.hits_per_page,
language: user.language,
isSso: user.is_sso,
userRoles: user.user_roles,
assignedConsultancyEntries: user.assigned_consultancy_entries
}
@@ -34,7 +35,10 @@ exports.deserialize = {
const deserializedRights = {
id: userData.id,
userName: userData.username,
firstName: userData.first_name,
lastName: userData.last_name,
email: userData.email,
language: userData.language,
hasAdministration: userData.administration,
hasEditing: userData.editing,
hasTerminologyReview: userData.terminology_review,