mirror of https://gitgud.io/fatchan/jschan.git
489-more-captcha-customisation See merge request fatchan/jschan!269jschan
commit
caab78c0ef
16 changed files with 89 additions and 54 deletions
Binary file not shown.
@ -1,21 +1,25 @@ |
||||
'use strict'; |
||||
|
||||
const fontList = require('child_process') |
||||
.execSync('fc-list -f "%{file}:%{family[0]} %{style[0]}\n"') |
||||
.toString() |
||||
.split('\n') //split by newlines, like here ^
|
||||
.filter(line => line) //filter empty lines
|
||||
.map(line => { |
||||
//map to an object with path and name
|
||||
const [path, name] = line.split(':'); |
||||
return { path, name }; |
||||
}) |
||||
.sort((a, b) => { |
||||
//alphabetical name sort
|
||||
return a.name.localeCompare(b.name); |
||||
}); |
||||
const { debugLogs } = require(__dirname+'/../../configs/secrets.js') |
||||
, fontList = require('child_process') |
||||
.execSync('fc-list -f "%{file}:%{family[0]} %{style[0]}\n"') |
||||
.toString() |
||||
.split('\n') //split by newlines, like here ^
|
||||
.filter(line => line) //filter empty lines
|
||||
.map(line => { |
||||
//map to an object with path and name
|
||||
const [path, name] = line.split(':'); |
||||
return { path, name }; |
||||
}) |
||||
.sort((a, b) => { |
||||
//alphabetical name sort
|
||||
return a.name.localeCompare(b.name); |
||||
}); |
||||
|
||||
debugLogs && console.log(`${fontList.length} system fonts available`); |
||||
|
||||
module.exports = { |
||||
fontList, |
||||
fontPaths: new Set(['default', ...fontList.map(f => f.path)]), //memoize paths
|
||||
DejaVuSans: fontList.find(f => f.name === 'DejaVu Sans Book'), //default for grid captchas
|
||||
}; |
||||
|
@ -0,0 +1,15 @@ |
||||
'use strict'; |
||||
|
||||
module.exports = async(db, redis) => { |
||||
console.log('make captcha font option apply to grid captcha too'); |
||||
await db.collection('globalsettings').updateOne({ _id: 'globalsettings' }, { |
||||
'$unset': { |
||||
'captchaOptions.text.font': '', |
||||
}, |
||||
'$set': { |
||||
'captchaOptions.font': 'default', |
||||
} |
||||
}); |
||||
console.log('Clearing globalsettings cache'); |
||||
await redis.deletePattern('globalsettings'); |
||||
}; |
Loading…
Reference in new issue