UNPKG

agentscript

Version:

AgentScript Model in Model/View architecture

76 lines (65 loc) 2.74 kB
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>AgentScript Examples (WebDAV)</title> </head> <body> <h1>AgentScript Examples (WebDAV)</h1> <div id="examples"></div> <script type="module"> import { createClient } from 'https://esm.sh/webdav/web' const examples = ['Ants', 'Template'] const idePath = '/agentscript/ide/examples' const usersPath = '/agentscript/users' const endpoint = 'https://agentscript.webdav.acequia.io:3334' const token = '' // Empty token = public access for now const userId = `user-${Math.floor(Math.random() * 10000)}` const base = `${usersPath}/${userId}` const client = createClient(endpoint, { authType: 0, token }) async function ensureDir(path) { try { await client.stat(path) } catch (e) { await client.createDirectory(path) } } async function copyExample(example) { const srcPath = `${idePath}/${example}` const destPath = `${base}/${example}` await ensureDir(destPath) const files = ['Model.js', 'View.js', 'index.html'] for (const file of files) { const srcFile = `${srcPath}/${file}` const destFile = `${destPath}/${file}` try { const data = await client.getFileContents(srcFile, { format: 'text', }) await client.putFileContents(destFile, data, { overwrite: true, }) } catch (e) { console.warn(`Failed to copy ${file}:`, e) } } return destPath } async function setup() { const container = document.getElementById('examples') for (const example of examples) { const div = document.createElement('div') div.textContent = `Loading ${example}...` container.appendChild(div) const destPath = await copyExample(example) const link = document.createElement('a') link.href = `${endpoint}${destPath}/index.html` link.textContent = `Open ${example}` div.innerHTML = '' div.appendChild(link) } } setup() </script> </body> </html>