siyuan-jsdraw-plugin/public/webapp/draw.js
MassiveBox 5e51589ffa
Internal file paths are now Markdown image paths
In the last commit, file paths were implemented to be the full path for the API, however that is not necessary.
Before this change: /data/assets/filename.svg
After: assets/filename.svg
The new method is what SiYuan uses for Markdown images, like ![Drawing](assets/filename.svg)
2025-04-03 00:12:36 +02:00

47 lines
No EOL
1.1 KiB
JavaScript

const FALLBACK = "<p>Nothing here yet! Click me to open the editor.</p>"
async function getFile(path) {
const response = await fetch('/api/file/getFile', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({path: path})
});
if (!response.ok) {
console.log('Failed to fetch HTML content');
return null;
}
const blob = await response.blob();
const resTxt = await blob.text();
// if we got a 404 api response, we will return null
try {
const res = JSON.parse(resTxt);
if(res.code === 404) {
return null;
}
}catch {}
return resTxt;
}
async function getSVG(path) {
const resp = await getFile("/data/" + path);
if(resp == null) {
return FALLBACK;
}
return resp;
}
function getEditLink(path) {
const data = encodeURIComponent(
JSON.stringify({
path: path,
})
)
return `siyuan://plugins/siyuan-jsdraw-pluginwhiteboard/?icon=iconDraw&title=Drawing&data=${data}`;
}