This commit is contained in:
2025-10-20 05:45:19 +08:00
parent d3174a73f3
commit 15af405d02
37 changed files with 3570 additions and 5 deletions

View File

@@ -0,0 +1,14 @@
import { QueryRouterServer } from "@kevisual/router";
const app = new QueryRouterServer();
app.route({
path: 'main'
}).define(async (ctx) => {
ctx.body = {
message: 'this is main. filename: test/demo/main.ts',
params: ctx.query
}
}).addTo(app)
app.wait()

View File

@@ -22,6 +22,7 @@
},
"dependencies": {
"@kevisual/noco": "^0.0.1",
"@kevisual/query": "^0.0.29",
"@kevisual/router": "^0.0.29",
"fast-glob": "^3.3.3",
"pocketbase": "^0.26.2",

View File

@@ -11,13 +11,13 @@ export const storage = createStorage({
export const codeStorage = createStorage({
// @ts-ignore
driver: fsLiteDriver({
base: './code'
base: codeRoot
})
})
// storage.setItem('test-ke/test-key.json', 'test-value');
// console.log('Cache test-key:', await storage.getItem('test-key'));
storage.setItem('root/light-code-demo/main.ts', 'test-value2');
console.log('Cache test-key:', await storage.getItem('root/light-code-demo/main.ts'));
// codeStorage.setItem('root/light-code-demo/main.ts', 'test-value2');
console.log('Cache test-key:', await codeStorage.getItem('root/light-code-demo/main.ts'));
console.log('has', await codeStorage.hasItem('root/light-code-demo/main.ts'));

View File

@@ -14,4 +14,6 @@ app.listen(4005, () => {
console.log('Server is running on http://localhost:4005')
})
app.onServerRequest(proxyRoute);
app.onServerRequest(proxyRoute);
export { app }

View File

@@ -29,11 +29,40 @@ app.route({
ctx.body = files
}).addTo(app);
type UploadProps = {
user: string;
key: string;
files: {
type: 'file' | 'base64';
filepath: string;
content: string;
}[];
}
app.route({
path: 'file-code',
key: 'upload',
middleware: ['auth']
}).define(async (ctx) => {
const upload = ctx.query?.upload as UploadProps;
if (!upload || !upload.user || !upload.key || !upload.files) {
ctx.throw(400, 'Invalid upload data');
}
const user = upload.user;
const key = upload.key;
for (const file of upload.files) {
if (file.type === 'file') {
const fullPath = path.join(codeRoot, user, key, file.filepath);
const dir = path.dirname(fullPath);
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(fullPath, file.content, 'utf-8');
} else if (file.type === 'base64') {
const fullPath = path.join(codeRoot, user, key, file.filepath);
const dir = path.dirname(fullPath);
fs.mkdirSync(dir, { recursive: true });
const buffer = Buffer.from(file.content, 'base64');
fs.writeFileSync(fullPath, buffer);
}
}
ctx.body = { success: true };
}).addTo(app)

View File

@@ -0,0 +1,5 @@
import { Query } from '@kevisual/query'
export const query = new Query({
url: 'http://localhost:4005/api/router',
})

View File

@@ -0,0 +1,48 @@
import { query } from './common.ts'
export const testUpload = async () => {
const res = await query.post({
path: 'file-code',
key: 'upload',
upload: {
user: 'test',
key: 'demo',
files: [
{
type: 'file',
filepath: 'main.ts',
content: `import { QueryRouterServer } from "@kevisual/router";
const app = new QueryRouterServer();
app.route({
path: 'main'
}).define(async (ctx) => {
ctx.body = {
message: 'this is main. filename: test/demo/main.ts',
params: ctx.query
}
}).addTo(app)
app.wait()`
},
]
}
})
console.log('Upload response:', res);
}
// testUpload();
const callTestDemo = async () => {
const res = await query.post({
path: 'call',
filename: 'test/demo/main.ts',
})
console.log('Call response:', res);
}
callTestDemo();