[feature] Add discovery handler "formats.json"

This commit is contained in:
Sergey Konovalov
2026-01-15 17:53:23 +03:00
parent 1c0dbeaa4d
commit 7a241af09f
4 changed files with 47 additions and 2 deletions

3
.gitignore vendored
View File

@ -11,4 +11,5 @@ node_modules
local-development-*.json
*.pyc
run-develop-local.py
runtime.json
runtime.json
document-formats/

View File

@ -507,6 +507,10 @@
"themes": {
"uri": "/web-apps/apps/common/main/resources/themes"
},
"documentFormats": {
"path": "./document-formats/formats.json",
"cacheTTL": "5m"
},
"editor": {
"spellcheckerUrl": "",
"reconnection": {

View File

@ -453,6 +453,44 @@ docsCoServer.install(server, app, () => {
}
});
});
app.get('/formats.json', apicache.middleware('5 minutes'), (req, res) => {
return co(function* () {
let formats = null;
const ctx = new operationContext.Context();
try {
ctx.initFromRequest(req);
yield ctx.initTenantCache();
ctx.logger.info('formats.json start');
if (!config.has('services.CoAuthoring.documentFormats.path')) {
ctx.logger.warn('formats.json: documentFormats.path not configured');
res.sendStatus(404);
return;
}
const formatsPath = config.get('services.CoAuthoring.documentFormats.path');
const resolvedPath = path.resolve(__dirname, '../../..', formatsPath);
ctx.logger.debug('formats.json path:%s', resolvedPath);
const data = yield utils.readFile(resolvedPath, true);
const text = new TextDecoder('utf-8', {ignoreBOM: false}).decode(data);
formats = JSON.parse(text);
ctx.logger.debug('formats.json loaded successfully');
} catch (err) {
ctx.logger.error('formats.json error:%s', err.stack);
} finally {
if (formats) {
res.setHeader('Content-Type', 'application/json');
res.send(formats);
} else {
res.sendStatus(404);
}
ctx.logger.info('formats.json end');
}
});
});
app.get('/document_editor_service_worker.js', apicache.middleware('5 min'), async (req, res) => {
const staticContent = config.get('services.CoAuthoring.server.static_content');
if (staticContent['/sdkjs']) {

View File

@ -13,6 +13,7 @@
"@eslint/js": "9.16.0",
"@jest/globals": "29.7.0",
"cross-env": "7.0.3",
"degit": "2.8.4",
"eslint": "9.16.0",
"eslint-config-prettier": "10.1.8",
"eslint-plugin-react": "^7.37.2",
@ -31,6 +32,7 @@
"format:check": "prettier . --check",
"code:check": "run-s lint:check format:check",
"code:fix": "run-s lint:fix format:fix",
"download:document-formats": "degit ONLYOFFICE/document-formats document-formats --force",
"perf-expired": "cd ./DocService&& cross-env NODE_ENV=development-windows NODE_CONFIG_DIR=../Common/config node ../tests/perf/checkFileExpire.js",
"unit tests": "cd ./DocService && jest unit --inject-globals=false --config=../tests/jest.config.js",
"integration tests with server instance": "cd ./DocService && jest integration/withServerInstance --inject-globals=false --config=../tests/jest.config.js",
@ -56,6 +58,6 @@
"3d-party-lic-report:FileConverter": "run-s 3d-party-lic-json:FileConverter 3d-party-lic-downloader 3d-party-lic-md",
"3d-party-lic-report:Metrics": "run-s 3d-party-lic-json:Metrics 3d-party-lic-downloader 3d-party-lic-md",
"3d-party-lic-report": "run-s 3d-party-lic-md-header 3d-party-lic-report:*",
"build": "run-p install:*"
"build": "run-s download:document-formats && run-p install:*"
}
}