mirror of
https://github.com/purocean/yn.git
synced 2026-10-13 07:38:54 +08:00
文件打开支持仓库
This commit is contained in:
+2
-2
@@ -91,8 +91,8 @@ const travels = (location, repo, basePath = null) => {
|
||||
}))
|
||||
}
|
||||
|
||||
exports.read = p => {
|
||||
return fs.readFileSync(resolvePath(p))
|
||||
exports.read = (repo, p) => {
|
||||
return fs.readFileSync(resolvePath(p, repo))
|
||||
}
|
||||
|
||||
exports.write = (p, content) => {
|
||||
|
||||
+19
-19
@@ -17,7 +17,7 @@ const result = (status = 'ok', message = '操作成功', data = null) => {
|
||||
const fileContent = async (ctx, next) => {
|
||||
if (ctx.path === '/api/file') {
|
||||
if (ctx.method === 'GET') {
|
||||
ctx.body = result('ok', '获取成功', file.read(ctx.query.path).toString())
|
||||
ctx.body = result('ok', '获取成功', file.read(ctx.query.repo, ctx.query.path).toString())
|
||||
} else if (ctx.method === 'POST') {
|
||||
if (ctx.request.body.is_new && file.exists(ctx.request.body.path)) {
|
||||
throw new Error('文件已经存在')
|
||||
@@ -85,6 +85,24 @@ const plantumlGen = async (ctx, next) => {
|
||||
}
|
||||
}
|
||||
|
||||
const searchFile = async (ctx, next) => {
|
||||
if (ctx.path.startsWith('/api/search')) {
|
||||
const search = ctx.query.str
|
||||
|
||||
ctx.body = result('ok', '操作成功', file.search(search))
|
||||
} else {
|
||||
await next()
|
||||
}
|
||||
}
|
||||
|
||||
const repository = async (ctx, next) => {
|
||||
if (ctx.path.startsWith('/api/repositories')) {
|
||||
ctx.body = result('ok', '获取成功', dataRepository.list())
|
||||
} else {
|
||||
await next()
|
||||
}
|
||||
}
|
||||
|
||||
const runCode = async (ctx, next) => {
|
||||
if (ctx.path.startsWith('/api/run')) {
|
||||
const rst = run.runCode(ctx.request.body.language, ctx.request.body.code)
|
||||
@@ -106,24 +124,6 @@ const convertFile = async (ctx, next) => {
|
||||
}
|
||||
}
|
||||
|
||||
const searchFile = async (ctx, next) => {
|
||||
if (ctx.path.startsWith('/api/search')) {
|
||||
const search = ctx.query.str
|
||||
|
||||
ctx.body = result('ok', '操作成功', file.search(search))
|
||||
} else {
|
||||
await next()
|
||||
}
|
||||
}
|
||||
|
||||
const repository = async (ctx, next) => {
|
||||
if (ctx.path.startsWith('/api/repositories')) {
|
||||
ctx.body = result('ok', '获取成功', dataRepository.list())
|
||||
} else {
|
||||
await next()
|
||||
}
|
||||
}
|
||||
|
||||
const app = new Koa()
|
||||
|
||||
app.use(static(
|
||||
|
||||
@@ -48,8 +48,8 @@ const decrypt = content => {
|
||||
}
|
||||
|
||||
export default {
|
||||
read: (path, call, ecall) => {
|
||||
fetch(`/api/file?path=${encodeURIComponent(path)}`).then(response => {
|
||||
read: (repo, path, call, ecall) => {
|
||||
fetch(`/api/file?path=${encodeURIComponent(path)}&repo=${repo}`).then(response => {
|
||||
response.json().then(result => {
|
||||
if (result.status === 'ok') {
|
||||
try {
|
||||
|
||||
@@ -144,7 +144,7 @@ export default {
|
||||
}
|
||||
|
||||
if (f) {
|
||||
File.read(f.path, data => {
|
||||
File.read(f.repo, f.path, data => {
|
||||
this.lastSaveContent = data
|
||||
this.$refs.editor.setValue(data)
|
||||
this.status = '加载完毕'
|
||||
|
||||
Reference in New Issue
Block a user