Fix assets:create 404: form-urlencoded mot /apps/richdocuments/assets, intern CODE över HTTP
- lib/bridge.js createAssetLink: POST <nextcloudUrl>/apps/richdocuments/assets (utan index.php), Content-Type application/x-www-form-urlencoded med body path=<urlencoded>, path trimmad utan ledande slash (userFolder->get relativt filrot), OCS-APIRequest borttagen. Fel inkluderar statusCode + svarskropp. - Intern collaboraUrl är HTTP: http://code:9980 (fallback http://<bridge-ip>:9980) i nc-collab-config default, .env.example, example-flows.json, docker-compose, install.sh och integrate-into-nodered.sh resolve_collabora_url. - Publik WOPI-URL dokumenterad som https://docs.domain.name. - package-lock.json för deterministisk form-data-install i Docker.
This commit is contained in:
+26
-12
@@ -2,6 +2,7 @@
|
||||
|
||||
const { webdavGet, webdavPut, webdavPropfindFileId } = require('./webdav');
|
||||
const { ocsRequest } = require('./ocs');
|
||||
const { requestBuffer } = require('./http-client');
|
||||
const { convertTo, extractStructure, transformStructure } = require('./collabora');
|
||||
const {
|
||||
resolveDestNcPath,
|
||||
@@ -210,33 +211,46 @@ async function extractToPayload(config, msg) {
|
||||
}
|
||||
|
||||
async function createAssetLink(config, msg) {
|
||||
const assetPath = pickMsgField(msg, 'ncPath');
|
||||
const assetPath = pickMsgField(msg, 'ncPath', 'path');
|
||||
if (!assetPath) {
|
||||
throw new Error('createAssetLink kräver msg.ncPath');
|
||||
throw new Error('createAssetLink kräver msg.ncPath eller msg.path');
|
||||
}
|
||||
|
||||
const relPath = normalizeNcPath(assetPath);
|
||||
const { requestBuffer } = require('./http-client');
|
||||
const base = config.nextcloudUrl.replace(/\/$/, '');
|
||||
// richdocuments AssetsController::create($path) läser form-parametern 'path'
|
||||
// och slår upp filen relativt användarens filrot → ingen ledande slash.
|
||||
const relPath = String(assetPath).trim().replace(/^\/+/, '').replace(/\/{2,}/g, '/');
|
||||
const base = String(config.nextcloudUrl || '').replace(/\/+$/, '');
|
||||
const token = Buffer.from(`${config.username}:${config.password}`).toString('base64');
|
||||
|
||||
const res = await requestBuffer({
|
||||
url: `${base}/index.php/apps/richdocuments/assets`,
|
||||
url: `${base}/apps/richdocuments/assets`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Basic ${token}`,
|
||||
'OCS-APIRequest': 'true',
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json'
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
body: Buffer.from(JSON.stringify({ path: relPath }), 'utf8'),
|
||||
body: Buffer.from(`path=${encodeURIComponent(relPath)}`, 'utf8'),
|
||||
rejectUnauthorized: config.verifyTls !== false && config.verifyTls !== 'false'
|
||||
});
|
||||
|
||||
const bodyText = res.body.toString('utf8').trim();
|
||||
|
||||
if (res.statusCode < 200 || res.statusCode >= 300) {
|
||||
throw new Error(`assets:create misslyckades (${res.statusCode})`);
|
||||
throw new Error(
|
||||
`assets:create misslyckades (${res.statusCode}): ${bodyText || '<tom body>'} — ` +
|
||||
`path=${relPath}, url=${base}/apps/richdocuments/assets. ` +
|
||||
'404 = filen saknas i användarens rot eller fel nextcloudUrl.'
|
||||
);
|
||||
}
|
||||
|
||||
let json;
|
||||
try {
|
||||
json = JSON.parse(bodyText);
|
||||
} catch (e) {
|
||||
throw new Error(`assets:create: ogiltigt JSON-svar (${res.statusCode}): ${bodyText.slice(0, 200)}`);
|
||||
}
|
||||
|
||||
const json = JSON.parse(res.body.toString('utf8'));
|
||||
return {
|
||||
assetUrl: json.url || json.assetUrl || json,
|
||||
ncPath: relPath
|
||||
|
||||
Reference in New Issue
Block a user