fileport-gateway 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/ui.js +1 -1
  2. package/package.json +1 -1
package/dist/ui.js CHANGED
@@ -10,7 +10,7 @@ const esc=s=>String(s).replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;'
10
10
  const enc=p=>p.split('/').filter(Boolean).map(encodeURIComponent).join('/');const fsUrl=p=>'/s/'+CONFIG.shareId+'/fs/'+enc(p);const apiUrl=(kind,p)=>'/s/'+CONFIG.shareId+'/api/'+kind+'/'+enc(p);const current=()=>new URL(location.href).searchParams.get('path')??CONFIG.initialPath;
11
11
  function navigate(p){const u=new URL(location.href);p?u.searchParams.set('path',p):u.searchParams.delete('path');history.pushState({},'',u);render()}
12
12
  function csv(text){const rows=text.trim().split(/\\r?\\n/).map(r=>r.split(','));return '<table>'+rows.map((r,i)=>'<tr>'+r.map(c=>'<'+(i?'td':'th')+'>'+esc(c)+'</'+(i?'td':'th')+'>').join('')+'</tr>').join('')+'</table>'}
13
- async function sourceView(p,text,type){const ext=p.toLowerCase().split('.').pop();if(type.includes('text/html')||ext==='html'){const url=URL.createObjectURL(new Blob([text],{type:'text/html'}));view.innerHTML='<iframe sandbox style="width:100%;height:75vh;border:0" src="'+url+'"></iframe>';return}let formatted=text;if(ext==='json'){try{formatted=JSON.stringify(JSON.parse(text),null,2)}catch{}}if(ext==='md'||ext==='markdown'){const response=await fetch(apiUrl('render/markdown',p),{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({source:text})});const data=await response.json();if(!response.ok)throw new Error(data.error||'Markdown render failed');view.innerHTML='<article class="content markdown-body">'+data.html+'</article>';return}if(ext==='csv'||ext==='tsv'){view.innerHTML='<div class="content">'+(ext==='csv'?csv(formatted):csv(formatted.replaceAll('\\t',',')))+'</div>';return}view.innerHTML='<div class="content"><pre>'+esc(formatted)+'</pre></div>'}
13
+ async function sourceView(p,text,type){const ext=p.toLowerCase().split('.').pop();if(type.includes('text/html')||ext==='html'){const url=URL.createObjectURL(new Blob([text],{type:'text/html'}));view.innerHTML='<iframe sandbox="allow-scripts" style="width:100%;height:75vh;border:0" src="'+url+'"></iframe>';return}let formatted=text;if(ext==='json'){try{formatted=JSON.stringify(JSON.parse(text),null,2)}catch{}}if(ext==='md'||ext==='markdown'){const response=await fetch(apiUrl('render/markdown',p),{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({source:text})});const data=await response.json();if(!response.ok)throw new Error(data.error||'Markdown render failed');view.innerHTML='<article class="content markdown-body">'+data.html+'</article>';return}if(ext==='csv'||ext==='tsv'){view.innerHTML='<div class="content">'+(ext==='csv'?csv(formatted):csv(formatted.replaceAll('\\t',',')))+'</div>';return}view.innerHTML='<div class="content"><pre>'+esc(formatted)+'</pre></div>'}
14
14
  async function showFile(p){const response=await fetch(fsUrl(p));if(!response.ok)throw new Error('HTTP '+response.status);const type=response.headers.get('content-type')||'';if(type.startsWith('image/')){const url=URL.createObjectURL(await response.blob());view.innerHTML='<div class="content"><img alt="preview" src="'+url+'"></div>';return}let text=await response.text(),version='',editable=false;if(CONFIG.permission==='rw'){const editResponse=await fetch(apiUrl('edit',p));if(editResponse.ok){const snapshot=await editResponse.json();text=snapshot.content;version=snapshot.version;editable=snapshot.editable===true}}active={path:p,text,version,editable,editing:false,type};await sourceView(p,text,type);edit.hidden=!active.editable;edit.onclick=()=>{active.editing=true;view.innerHTML='<textarea id="editor"></textarea>';document.getElementById('editor').value=active.text;edit.hidden=true;save.hidden=false;status.textContent='Unsaved changes'};save.onclick=async()=>{if(!confirm('Save changes to the authoritative file?'))return;save.disabled=true;const content=document.getElementById('editor').value,response=await fetch(apiUrl('save',active.path),{method:'PUT',headers:{'content-type':'application/json'},body:JSON.stringify({content,expectedVersion:active.version})}),data=await response.json();save.disabled=false;if(!response.ok){status.textContent='Save failed: '+data.error;return}active.text=content;active.version=data.version;active.editing=false;status.textContent='Saved';edit.hidden=false;save.hidden=true;await sourceView(active.path,active.text,active.type)}}
15
15
  async function showDirectory(p){const response=await fetch((p?fsUrl(p)+'/':fsUrl(''))+'?json');if(!response.ok)throw new Error('HTTP '+response.status);const data=await response.json(),entries=data.paths||[];view.innerHTML=entries.length?entries.map(item=>{const name=String(item.name),leaf=name.includes('/')?name.slice(name.lastIndexOf('/')+1):name,next=[p,leaf].filter(Boolean).join('/'),icon=item.path_type==='Dir'?'📁':'📄';return '<a class="entry" href="?path='+encodeURIComponent(next)+'" data-path="'+esc(next)+'"><span>'+icon+'</span><span>'+esc(leaf)+'</span></a>'}).join(''):'<div class="content">Empty directory</div>';view.querySelectorAll('[data-path]').forEach(a=>a.addEventListener('click',e=>{e.preventDefault();navigate(a.dataset.path)}))}
16
16
  async function render(){const p=current();edit.hidden=true;save.hidden=true;status.textContent='';pathLabel.textContent='/'+p;up.disabled=!p||CONFIG.kind==='file';up.onclick=()=>navigate(p.split('/').slice(0,-1).join('/'));view.innerHTML='<div class="content">Loading…</div>';try{if(CONFIG.kind==='file')await showFile(CONFIG.initialPath);else{const probe=await fetch(fsUrl(p)+(p?'/':'')+'?json');if(probe.ok){const data=await probe.clone().json().catch(()=>null);if(data?.kind==='Index'){await showDirectory(p);return}}await showFile(p)}}catch(e){view.innerHTML='<div class="error">'+esc(e.message||e)+'</div>'}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fileport-gateway",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Secure Agent Artifact Gateway with capability URLs, strict saves, and Dufs-backed file serving.",
5
5
  "type": "module",
6
6
  "bin": {