Example-flows + noder: defaults pekar bara på filer som finns
Flöden (flows/example-flows.json): - Kedjor som skapar det de behöver: png→asset, templates:list→create→ extract/fill/transform/extractFields, create A+B→compareVersionsPdf - Defaults /Dokument/Example.md, /Dokument/exempel.odt, dest /Dokument/OfficeOut/, mall-id 230 (Invoice.odt via templates:list) - Ingen referens till /Mallar/avtal.docx, avtal-ny.docx eller logotyp.png - Debug-noder med tostatus=false (undviker TypeError-length i status) Noder: - nc-office templates:create: skickar path+template (richdocuments- kontrakt), ärver extension från mallen, MKCOL av mapp, idempotent (återanvänd existerande fil i stället för 'namn (2)') — fixar OCS 400 - nc-office document:direct: fileId camelCase (+fileid), 996-fel inkluderar nu OCS-body i felmeddelandet - collabora-wopi discovery: rewrite urlsrc/favIconUrl till collaboraPublicUrl så iframe inte går mot CODE bridge-IP - webdavGet/PROPFIND 404: feltext med föreslagen åtgärd - resolveDestNcPath: tvingar rätt filändelse (.pdf/.png/…) - Nytt: listUserExamples (PROPFIND /Dokument+/Documents) + bridge-op pickDemoSource; scripts/discover-examples.js Verifierat mot cloud.domain.name (your-user): capabilities, discovery- rewrite, pdf/png, asset-länk, mall-skapa+extract/fill/transform, compare A/B→pdf, document:direct, htmlToOffice — ALL PASS.
This commit is contained in:
+82
-2
@@ -41,7 +41,11 @@ async function webdavGet(config, ncPath) {
|
||||
});
|
||||
|
||||
if (res.statusCode === 404) {
|
||||
throw new Error(`WebDAV 404: filen finns inte: ${normalizeNcPath(ncPath)}`);
|
||||
throw new Error(
|
||||
`WebDAV 404: filen finns inte: ${normalizeNcPath(ncPath)} — ` +
|
||||
'ange msg.ncPath till en fil som finns; defaults är /Dokument/Example.md ' +
|
||||
'eller en mall via templates:list (se bridge-op pickDemoSource).'
|
||||
);
|
||||
}
|
||||
if (res.statusCode === 401 || res.statusCode === 403) {
|
||||
throw new Error(`WebDAV ${res.statusCode}: kontrollera app-lösenord och användare`);
|
||||
@@ -134,6 +138,12 @@ async function webdavPropfindFileId(config, ncPath) {
|
||||
rejectUnauthorized: tlsOptions(config).rejectUnauthorized
|
||||
});
|
||||
|
||||
if (res.statusCode === 404) {
|
||||
throw new Error(
|
||||
`PROPFIND 404: ${normalizeNcPath(ncPath)} finns inte — ` +
|
||||
'ange msg.ncPath till en fil som finns (t.ex. /Dokument/Example.md).'
|
||||
);
|
||||
}
|
||||
if (res.statusCode < 200 || res.statusCode >= 300) {
|
||||
throw new Error(`PROPFIND misslyckades (${res.statusCode}) för ${normalizeNcPath(ncPath)}`);
|
||||
}
|
||||
@@ -146,10 +156,80 @@ async function webdavPropfindFileId(config, ncPath) {
|
||||
return parseInt(match[1], 10);
|
||||
}
|
||||
|
||||
// Discovery av riktiga defaults: PROPFIND /Dokument och /Documents (Depth 1),
|
||||
// returnera kandidater (.md/.odt/.docx) i prioritetsordning. Används BARA av
|
||||
// example-flow-generator / bridge-op pickDemoSource — aldrig inne i convert.
|
||||
async function listUserExamples(config, folders) {
|
||||
const candidates = folders || ['/Dokument', '/Documents'];
|
||||
const found = [];
|
||||
const wanted = /\.(md|odt|docx)$/i;
|
||||
|
||||
for (const folder of candidates) {
|
||||
let res;
|
||||
try {
|
||||
res = await requestBuffer({
|
||||
url: webDavUrl(config, folder),
|
||||
method: 'PROPFIND',
|
||||
headers: {
|
||||
Authorization: authHeader(config),
|
||||
Depth: '1',
|
||||
'Content-Type': 'application/xml; charset=utf-8'
|
||||
},
|
||||
body: '<?xml version="1.0" encoding="UTF-8"?><d:propfind xmlns:d="DAV:"/>',
|
||||
rejectUnauthorized: tlsOptions(config).rejectUnauthorized
|
||||
});
|
||||
} catch (err) {
|
||||
continue; // mapp finns ej — prova nästa
|
||||
}
|
||||
if (res.statusCode < 200 || res.statusCode >= 300) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const text = res.body.toString('utf8');
|
||||
const responses = text.split('<d:response>').slice(1);
|
||||
for (const chunk of responses) {
|
||||
const hrefMatch = chunk.match(/<d:href>([^<]+)<\/d:href>/i);
|
||||
if (!hrefMatch) {
|
||||
continue;
|
||||
}
|
||||
let href;
|
||||
try {
|
||||
href = decodeURIComponent(hrefMatch[1]);
|
||||
} catch {
|
||||
href = hrefMatch[1];
|
||||
}
|
||||
// href: /remote.php/dav/files/<user>/Dokument/exempel.odt → ncPath
|
||||
const marker = `/files/${config.username}/`;
|
||||
const idx = href.indexOf(marker);
|
||||
if (idx === -1) {
|
||||
continue;
|
||||
}
|
||||
const ncPath = normalizeNcPath(href.substring(idx + marker.length));
|
||||
if (!wanted.test(ncPath)) {
|
||||
continue;
|
||||
}
|
||||
const isCollection = /<d:collection\s*\/?>/i.test(chunk);
|
||||
if (isCollection) {
|
||||
continue;
|
||||
}
|
||||
found.push({ ncPath, folder: normalizeNcPath(folder), name: filenameFromPath(ncPath) });
|
||||
}
|
||||
}
|
||||
|
||||
const priority = { md: 0, odt: 1, docx: 2 };
|
||||
found.sort((a, b) => {
|
||||
const extA = a.ncPath.split('.').pop().toLowerCase();
|
||||
const extB = b.ncPath.split('.').pop().toLowerCase();
|
||||
return (priority[extA] ?? 9) - (priority[extB] ?? 9);
|
||||
});
|
||||
return found;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
webDavUrl,
|
||||
webdavGet,
|
||||
webdavPut,
|
||||
webdavPropfindFileId,
|
||||
ensureFolder
|
||||
ensureFolder,
|
||||
listUserExamples
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user