diff --git a/router-app/.gitignore b/router-app/.gitignore deleted file mode 100644 index 3c3629e..0000000 --- a/router-app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules diff --git a/router-app/pem/https-cert.pem b/router-app/pem/https-cert.pem deleted file mode 100644 index 68f4fce..0000000 --- a/router-app/pem/https-cert.pem +++ /dev/null @@ -1,15 +0,0 @@ ------BEGIN CERTIFICATE----- -MIICXTCCAcagAwIBAgIJHsP036vqWER/MA0GCSqGSIb3DQEBBQUAMF8xCjAIBgNV -BAMTASoxCzAJBgNVBAYTAkNOMREwDwYDVQQIEwhaaGVKaWFuZzERMA8GA1UEBxMI -SGFuZ3pob3UxETAPBgNVBAoTCEVudmlzaW9uMQswCQYDVQQLEwJJVDAeFw0yNTAz -MDcxNDIwMTJaFw0yNjAzMDcxNDIwMTJaMF8xCjAIBgNVBAMTASoxCzAJBgNVBAYT -AkNOMREwDwYDVQQIEwhaaGVKaWFuZzERMA8GA1UEBxMISGFuZ3pob3UxETAPBgNV -BAoTCEVudmlzaW9uMQswCQYDVQQLEwJJVDCBnzANBgkqhkiG9w0BAQEFAAOBjQAw -gYkCgYEAquA2XnwduVSJHvnTW4r5yodz/joTPUi+r8kS/KJyR/NQ5xovtDY2gJoO -nJk8qekcLKuofskIIu4HFsCE7AYBkQGaYmc+0cCQCmEpwivesbeMB0ydz+6NwLQn -32HVjtMtx3gUcywGdMntiQb/P9FIhtE132wOmW9PeSl0dx/nyrUCAwEAAaMhMB8w -HQYDVR0RBBYwFIIBKoIJbG9jYWxob3N0hwR/AAABMA0GCSqGSIb3DQEBBQUAA4GB -AJsjIZgb6iE4OTXoEDiBPmHM+byWs20K2eCvi79V9/vns90IroBQfGirIsovv923 -SqjmdAFsZkRUbZvX99lBX0mmZK9KTE4K9YUm7bv+d8+fBPxAgNFSTRiSNBeNh0Lh -HdJUiI/tzIfI6RRg1pFDC1tOG083Cl/YElN879w3Iipi ------END CERTIFICATE----- diff --git a/router-app/pem/https-key.pem b/router-app/pem/https-key.pem deleted file mode 100644 index 7263037..0000000 --- a/router-app/pem/https-key.pem +++ /dev/null @@ -1,15 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIICXAIBAAKBgQCq4DZefB25VIke+dNbivnKh3P+OhM9SL6vyRL8onJH81DnGi+0 -NjaAmg6cmTyp6Rwsq6h+yQgi7gcWwITsBgGRAZpiZz7RwJAKYSnCK96xt4wHTJ3P -7o3AtCffYdWO0y3HeBRzLAZ0ye2JBv8/0UiG0TXfbA6Zb095KXR3H+fKtQIDAQAB -AoGADDEbL/qjFEoXzoH8tpdf4zdu60CxhrneASTTmfrtNH0D1LlllfIYSWy0hi/Y -yDa9r+I/j2xAjF13XAQ4d66mBdjCRATLx/aL495o+e6NkIBEAgdP88hHm13F6gg+ -h8iMixs5mkwU41sghnCYeBqlziKPi8fsoTmhK0VETFUtDQECQQDT0kZ7OCEVNcz0 -LAUPO7ukeHAYnGYns+Q3F3kgonzHPGflClH5dsg0NS1HFQj6Ny2oyUupjNePOCJK -88zNehIlAkEAzoO9zrE+AoTPleVpe7TAUlZB1YMa7W1C5owjyEkv4TjIe8mpwWM/ -9vVe+SGUnc6DZy6xkk5zWmA2w18SexXJUQJBAJQbcyy1EmzCMYyJOwBrw8g8biTH -NqaMIgZjY05uTtEAa6S6kpbbdyEKDZ6mFqDd9A8QsNbco9yAY3oE/i6uLAECQHOt -a9aphZiXmEfYl3uJxejZFEtrAtxXxY+qlCiOhllcG0Drt0DyPVQyIZ7fZoX2tbhI -eYMAmrDXEBXj3VBA5eECQCLGpQKqo06QwP2qZ9mEaPB9KvVcABo97b9Lf7VUqcJx -tFWRSlpeICpDQZHqX92nwoD/2fGCH3br3o94k1oyApI= ------END RSA PRIVATE KEY----- diff --git a/router-app/src/app.ts b/router-app/src/app.ts deleted file mode 100644 index ce606b6..0000000 --- a/router-app/src/app.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { App } from '@kevisual/router'; -import { httpsConfig } from './modules/config'; -export const app = new App({ - serverOptions: { - httpType: 'https', - httpsCert: httpsConfig.cert.toString(), - httpsKey: httpsConfig.key.toString(), - }, -}); -app - .route({ - path: 'demo', - }) - .define(async (ctx) => { - ctx.body = 'hello world'; - }) - .addTo(app); -console.log('httpsConfig', `https://localhost:51015/api/router?path=demo`); -app.listen(51015, () => { - console.log('Router App is running on https://localhost:51015'); -}); diff --git a/router-app/src/modules/config.ts b/router-app/src/modules/config.ts deleted file mode 100644 index 2d9d746..0000000 --- a/router-app/src/modules/config.ts +++ /dev/null @@ -1,9 +0,0 @@ -import fs from 'fs'; -import path from 'path'; - -const pemDir = path.join(process.cwd(), 'router-app', 'pem'); - -export const httpsConfig = { - key: fs.readFileSync(path.join(pemDir, 'https-key.pem')), - cert: fs.readFileSync(path.join(pemDir, 'https-cert.pem')), -}; diff --git a/router-app/src/modules/config/index.ts b/router-app/src/modules/config/index.ts deleted file mode 100644 index 9b1a1ee..0000000 --- a/router-app/src/modules/config/index.ts +++ /dev/null @@ -1,108 +0,0 @@ -import path from 'path'; -import { homedir } from 'os'; -import fs from 'fs'; -import { checkFileExists, createDir } from '../file'; - -export const kevisualUrl = 'https://kevisual.xiongxiao.me'; -const configDir = createDir(path.join(homedir(), '.config/envision')); -export const configPath = path.join(configDir, 'assistant-config.json'); -export const appConfigPath = path.join(configDir, 'assistant-app-config.json'); -export const appDir = createDir(path.join(configDir, 'assistant-app/frontend')); -export const LocalElectronAppUrl = 'https://assistant.app/user/tiptap/'; - -type AssistantConfig = { - pageApi?: string; // https://kevisual.silkyai.cn - loadURL?: string; // https://assistant.app/user/tiptap/ - proxy?: { user: string; key: string; path: string }[]; -}; -let assistantConfig: AssistantConfig; -export const getConfig = () => { - try { - if (!checkFileExists(configPath)) { - fs.writeFileSync(configPath, JSON.stringify({ proxy: [] }, null, 2)); - return { - loadURL: LocalElectronAppUrl, - pageApi: '', - proxy: [], - }; - } - assistantConfig = JSON.parse(fs.readFileSync(configPath, 'utf8')); - return assistantConfig; - } catch (error) { - console.error(error); - return { - loadURL: LocalElectronAppUrl, - pageApi: '', - proxy: [], - }; - } -}; -export const getCacheAssistantConfig = () => { - if (assistantConfig) { - return assistantConfig; - } - return getConfig(); -}; - -export const setConfig = (config?: AssistantConfig) => { - if (!config) { - return assistantConfig; - } - assistantConfig = config; - fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); - return assistantConfig; -}; -type AppConfig = { - list: any[]; -}; -/** - * 应用配置 - * @returns - */ -export const getAppConfig = (): AppConfig => { - if (!checkFileExists(appConfigPath)) { - return { - list: [], - }; - } - return JSON.parse(fs.readFileSync(appConfigPath, 'utf8')); -}; - -export const setAppConfig = (config: AppConfig) => { - fs.writeFileSync(appConfigPath, JSON.stringify(config, null, 2)); - return config; -}; - -export const addAppConfig = (app: any) => { - const config = getAppConfig(); - const assistantConfig = getCacheAssistantConfig(); - const _apps = config.list; - const _proxy = assistantConfig.proxy || []; - const { user, key } = app; - const newProxyInfo = { - user, - key, - path: `/${user}/${key}`, - }; - const _proxyIndex = _proxy.findIndex((_proxy: any) => _proxy.path === newProxyInfo.path); - if (_proxyIndex !== -1) { - _proxy[_proxyIndex] = newProxyInfo; - } else { - _proxy.push(newProxyInfo); - } - - const _app = _apps.findIndex((_app: any) => _app.id === app.id); - if (_app !== -1) { - _apps[_app] = app; - } else { - _apps.push(app); - } - setAppConfig({ ...config, list: _apps }); - setConfig({ ...assistantConfig, proxy: _proxy }); - return config; -}; - -export const getAppList = () => { - const config = getAppConfig(); - return config.list || []; -}; diff --git a/router-app/src/modules/file/index.ts b/router-app/src/modules/file/index.ts deleted file mode 100644 index f1f45bb..0000000 --- a/router-app/src/modules/file/index.ts +++ /dev/null @@ -1,20 +0,0 @@ -import fs from 'fs'; - -export const checkFileExists = (filePath: string, checkIsFile = false) => { - try { - fs.accessSync(filePath); - if (checkIsFile) { - return fs.statSync(filePath).isFile(); - } - return true; - } catch (error) { - return false; - } -}; - -export const createDir = (dirPath: string) => { - if (!checkFileExists(dirPath)) { - fs.mkdirSync(dirPath, { recursive: true }); - } - return dirPath; -}; diff --git a/router-app/src/proxy/index.ts b/router-app/src/proxy/index.ts deleted file mode 100644 index 8875722..0000000 --- a/router-app/src/proxy/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import http from 'http'; - -export const handleRequest = async (req: http.IncomingMessage, res: http.ServerResponse) => { - -} \ No newline at end of file diff --git a/router-app/src/scripts/create-sign.ts b/router-app/src/scripts/create-sign.ts deleted file mode 100644 index 9c94a76..0000000 --- a/router-app/src/scripts/create-sign.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { createCert } from '@kevisual/router/sign'; -import { writeFileSync } from 'fs'; -import path from 'path'; -const pemDir = path.join(process.cwd(), 'router-app', 'pem'); - -const { key, cert } = createCert([ - { - name: 'commonName', - value: 'localhost', - }, - { - name: 'organizationName', - value: 'kevisual', - }, -]); - -writeFileSync(path.join(pemDir, 'https-key.pem'), key); -writeFileSync(path.join(pemDir, 'https-cert.pem'), cert); diff --git a/router-app/static/download.ts b/router-app/static/download.ts deleted file mode 100644 index 962021d..0000000 --- a/router-app/static/download.ts +++ /dev/null @@ -1,18 +0,0 @@ -import fs from 'fs'; - -const apps = [ - { user: 'root', key: 'enter', version: '1.0.0' }, // - { user: 'root', key: 'packages', version: '1.0.0' }, -]; - -const baseURL = 'https://kevisual.silkyai.cn'; - -const downloadApps = () => { - // -}; - -export const downloadLink = async (url: string, path: string) => { - const res = await fetch(url); - const blob = await res.blob(); - fs.writeFileSync(path, Buffer.from(await blob.arrayBuffer())); -}; diff --git a/router-app/static/enter/electron.js b/router-app/static/enter/electron.js deleted file mode 100644 index a101fbc..0000000 --- a/router-app/static/enter/electron.js +++ /dev/null @@ -1,23 +0,0 @@ -export const checkIsElectron = () => { - return typeof window !== 'undefined' && typeof window.electron === 'object'; -}; -export const getElectron = () => { - return window.electron; -}; -export const saveAppConfig = async (config) => { - const check = checkIsElectron(); - if (!check) { - console.log('not electron'); - return []; - } - const electron = getElectron(); - const saveResult = await electron.ipcRenderer.invoke('save-app-config', config); - return saveResult; -}; -export const relunch = async () => { - const check = checkIsElectron(); - if (!check) { - console.log('not electron'); - return []; - } -}; \ No newline at end of file diff --git a/router-app/static/enter/index.html b/router-app/static/enter/index.html deleted file mode 100644 index 09ee7a6..0000000 --- a/router-app/static/enter/index.html +++ /dev/null @@ -1,214 +0,0 @@ - - - - - - Page Enter Configuration - - - -
- -
-
- - - - -

Page Enter Configuration

-
- -
-
-
- - -
- - -
-
-
-
- - - - - \ No newline at end of file diff --git a/router-app/static/enter/main.js b/router-app/static/enter/main.js deleted file mode 100644 index 3955840..0000000 --- a/router-app/static/enter/main.js +++ /dev/null @@ -1,28 +0,0 @@ -import { saveAppConfig } from './electron.js'; - -window.onload = async () => { - const config = await saveAppConfig(); - const pageApi = document.getElementById('pageApi'); - const saveResult = document.getElementById('save-result'); - pageApi.value = config?.pageApi || 'https://kevisual.silkyai.cn'; - console.log('config', config); - const form = document.getElementById('configForm'); - - // Handle form submission - form.addEventListener('submit', async (e) => { - e.preventDefault(); - const config = { - pageApi: pageApi.value, - }; - const result = await saveAppConfig(config); - - const newPageApi = result?.pageApi || ''; - saveResult.innerHTML = `

保存成功

-

new pageApi: ${newPageApi}

- `; - const relunchButton = document.getElementById('relunch'); - relunchButton.addEventListener('click', () => { - window.electron.ipcRenderer.invoke('relunch'); - }); - }); -}; diff --git a/router-app/static/index.html b/router-app/static/index.html deleted file mode 100644 index 5acdf85..0000000 --- a/router-app/static/index.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - Config Page - - - -

配置完成后重启

- - - - - - \ No newline at end of file diff --git a/router-app/static/packages/config.js b/router-app/static/packages/config.js deleted file mode 100644 index 83d06af..0000000 --- a/router-app/static/packages/config.js +++ /dev/null @@ -1,3 +0,0 @@ -export const config = { - appListUrl: 'http://localhost:4005/api/router?path=app&key=public-list', -}; diff --git a/router-app/static/packages/electron.js b/router-app/static/packages/electron.js deleted file mode 100644 index b6b2bcf..0000000 --- a/router-app/static/packages/electron.js +++ /dev/null @@ -1,45 +0,0 @@ -export const checkIsElectron = () => { - return typeof window !== 'undefined' && typeof window.electron === 'object'; -}; -export const getElectron = () => { - return window.electron; -}; -export const getAppList = async () => { - const check = checkIsElectron(); - if (!check) { - console.log('not electron'); - return []; - } - const electron = getElectron(); - console.log('electron', electron); - const appList = await electron.ipcRenderer.invoke('get-app-list'); - - console.log('appList', appList); - return appList; -}; - -export const installApp = async (app) => { - const check = checkIsElectron(); - if (!check) { - console.log('not electron'); - return []; - } - const electron = getElectron(); - console.log('installApp', app); - const result = await electron.ipcRenderer.invoke('install-app', app); - console.log('installApp result', result); - return result; -}; - -export const uninstallApp = async (app) => { - const check = checkIsElectron(); - if (!check) { - console.log('not electron'); - return []; - } - const electron = getElectron(); - console.log('uninstallApp', app); - const result = await electron.ipcRenderer.invoke('uninstall-app', app); - console.log('uninstallApp result', result); - return result; -}; diff --git a/router-app/static/packages/index.html b/router-app/static/packages/index.html deleted file mode 100644 index cfd1f98..0000000 --- a/router-app/static/packages/index.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - Package Manager - - - - -
-

Package Manager

-
-
- - - \ No newline at end of file diff --git a/router-app/static/packages/main.js b/router-app/static/packages/main.js deleted file mode 100644 index f698fe3..0000000 --- a/router-app/static/packages/main.js +++ /dev/null @@ -1,158 +0,0 @@ -import { config } from './config.js'; -import { getAppList, installApp, uninstallApp } from './electron.js'; -let installedPackages = []; -let allPackages = []; -// Store for installed packages -// const installedPackages = [ -// { user: 'test', key: 'test-key', version: '1.0.0' }, -// { user: 'demo', key: 'demo-package', version: '1.2.0' }, -// ]; - -// Function to fetch packages from API -async function fetchPackages() { - try { - // Currently using mock data - // TODO: Uncomment the following code when API is ready - const response = await fetch(config.appListUrl); - const result = await response.json(); - if (result.code === 200) { - return result.data; - } - throw new Error('Failed to fetch packages'); - } catch (error) { - console.error('Error fetching packages:', error); - return []; - } -} - -// Mock data for testing -const mockPackages = [ - { - id: '1', - title: 'Demo Package 1', - description: 'A test package for demonstration', - version: '1.0.0', - user: 'test', - key: 'test-key', - }, - { - id: '2', - title: 'Demo Package 2', - description: 'Another test package with updates', - version: '2.0.0', - user: 'demo', - key: 'demo-package', - }, - { - id: '3', - title: 'New Package', - description: "A package that hasn't been installed yet", - version: '1.0.0', - user: 'demo', - key: 'new-package', - }, -]; - -// Function to check if a package is installed -async function getPackageStatus(pkg) { - const installed = installedPackages.find((p) => p.user === pkg.user && p.key === pkg.key); - - if (!installed) return 'not-installed'; - if (installed.version !== pkg.version) return 'update-available'; - return 'installed'; -} - -// Function to create a package card -async function createPackageCard(pkg) { - const status = await getPackageStatus(pkg); - const card = document.createElement('div'); - card.className = 'package-card'; - - card.innerHTML = ` -

${pkg.title}

-

${pkg.description}

-
- Version: ${pkg.version} - User: ${pkg.user} -
-
- ${getActionButton(status, pkg)} - ${status !== 'not-installed' ? `` : ''} -
- `; - - return card; -} - -// Function to get the appropriate action button based on status -function getActionButton(status, pkg) { - switch (status) { - case 'not-installed': - return ``; - case 'update-available': - return ``; - case 'installed': - return ``; - } -} - -// Action handlers -window.handleInstall = async (id) => { - console.log('Installing package:', id); - const pkg = allPackages.find((p) => p.id === id); - if (pkg) { - await installApp(pkg); - renderPackages(); - } -}; - -window.handleUpdate = async (id) => { - console.log('Updating package:', id); - const pkg = allPackages.find((p) => p.id === id); - if (pkg) { - await installApp(pkg); - renderPackages(); - } -}; - -window.handleReinstall = async (id) => { - console.log('Reinstalling package:', id); - const pkg = allPackages.find((p) => p.id === id); - if (pkg) { - await installApp(pkg); - renderPackages(); - } -}; - -window.handleUninstall = async (id) => { - console.log('Uninstalling package:', id); - // const pkg = mockPackages.find((p) => p.id === id); - const pkg = allPackages.find((p) => p.id === id); - if (pkg) { - // TODO: Replace with actual API call - const index = installedPackages.findIndex((p) => p.user === pkg.user && p.key === pkg.key); - await uninstallApp(pkg); - if (index !== -1) { - installedPackages.splice(index, 1); - renderPackages(); - } - } -}; - -// Render packages -async function renderPackages() { - const packageList = document.getElementById('package-list'); - packageList.innerHTML = ''; - const installed = await getAppList(); - installedPackages = installed; - for (const pkg of allPackages) { - packageList.appendChild(await createPackageCard(pkg)); - } -} - -// Initialize the application -document.addEventListener('DOMContentLoaded', async () => { - const packages = await fetchPackages(); - allPackages = packages; - renderPackages(); -}); diff --git a/router-app/static/packages/style.css b/router-app/static/packages/style.css deleted file mode 100644 index ccb9e07..0000000 --- a/router-app/static/packages/style.css +++ /dev/null @@ -1,115 +0,0 @@ -:root { - font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; - line-height: 1.5; - font-weight: 400; - color-scheme: light dark; - background-color: #fff8e1; - color: #213547; -} - -body { - margin: 0; - min-width: 320px; - min-height: 100vh; -} - -#app { - max-width: 1280px; - margin: 0 auto; - padding: 2rem; -} - -h1 { - text-align: center; - color: #ff8f00; -} - -.package-list { - display: grid; - grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); - gap: 1rem; - padding: 1rem; -} - -.package-card { - background: white; - border-radius: 8px; - padding: 1.5rem; - box-shadow: 0 2px 4px rgba(255, 143, 0, 0.1); - border: 1px solid #ffe0b2; -} - -.package-card h2 { - margin: 0 0 0.5rem 0; - color: #f57c00; -} - -.package-card .description { - color: #666; - margin-bottom: 1rem; - font-size: 0.9rem; - display: -webkit-box; - -webkit-line-clamp: 4; - -webkit-box-orient: vertical; - overflow: hidden; - text-overflow: ellipsis; - line-height: 1.5; - max-height: 6em; -} - -.package-info { - display: flex; - justify-content: space-between; - align-items: center; - margin-bottom: 1rem; - font-size: 0.9rem; - color: #666; -} - -.button { - padding: 0.5rem 1rem; - border-radius: 4px; - border: none; - cursor: pointer; - font-weight: 500; - transition: background-color 0.2s; -} - -.button-install { - background-color: #ffa000; - color: white; -} - -.button-update { - background-color: #ff8f00; - color: white; -} - -.button-reinstall { - background-color: #ffb300; - color: white; -} - -.button-uninstall { - background-color: #ff6f00; - color: white; -} - -.button:hover { - opacity: 0.9; -} - -.button:disabled { - background-color: #ffe0b2; - cursor: not-allowed; -} - -.error-message { - text-align: center; - color: #ff6f00; - padding: 2rem; - background: white; - border-radius: 8px; - box-shadow: 0 2px 4px rgba(255, 143, 0, 0.1); - grid-column: 1 / -1; -} \ No newline at end of file