文件打开支持仓库

This commit is contained in:
purocean
2018-08-06 19:02:18 +08:00
parent 798c9be638
commit a1fc0131b4
4 changed files with 24 additions and 24 deletions
+2 -2
View File
@@ -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
View File
@@ -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(
+2 -2
View File
@@ -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 {
+1 -1
View File
@@ -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 = '加载完毕'