Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
tianyazhichiC
algorithm-visualizer
提交
f6431e7a
A
algorithm-visualizer
项目概览
tianyazhichiC
/
algorithm-visualizer
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
algorithm-visualizer
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f6431e7a
编写于
7月 13, 2018
作者:
J
Jason Park
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve controller
上级
9818eeff
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
77 addition
and
42 deletion
+77
-42
.gitmodules
.gitmodules
+3
-0
src/backend/controllers/categories.js
src/backend/controllers/categories.js
+0
-0
src/backend/controllers/compilers.js
src/backend/controllers/compilers.js
+0
-0
src/backend/controllers/docs.js
src/backend/controllers/docs.js
+41
-0
src/backend/controllers/index.js
src/backend/controllers/index.js
+4
-31
src/backend/index.js
src/backend/index.js
+19
-2
src/backend/public/docs
src/backend/public/docs
+1
-0
src/frontend/apis/index.js
src/frontend/apis/index.js
+7
-7
src/frontend/components/WikiViewer/index.jsx
src/frontend/components/WikiViewer/index.jsx
+2
-2
未找到文件。
.gitmodules
浏览文件 @
f6431e7a
[submodule "src/backend/public/algorithms"]
path = src/backend/public/algorithms
url = git@github.com:algorithm-visualizer/algorithms.git
[submodule "src/backend/public/docs"]
path = src/backend/public/docs
url = git@github.com:algorithm-visualizer/tracers.wiki.git
src/backend/controllers/categor
y
.js
→
src/backend/controllers/categor
ies
.js
浏览文件 @
f6431e7a
文件已移动
src/backend/controllers/compiler.js
→
src/backend/controllers/compiler
s
.js
浏览文件 @
f6431e7a
文件已移动
src/backend/controllers/
wiki
.js
→
src/backend/controllers/
docs
.js
浏览文件 @
f6431e7a
...
...
@@ -5,37 +5,37 @@ import { NotFoundError } from '/common/error';
const
router
=
express
.
Router
();
const
getPath
=
(...
args
)
=>
path
.
resolve
(
__dirname
,
'
..
'
,
'
public
'
,
'
algorithm-visualizer.wiki
'
,
...
args
);
const
getPath
=
(...
args
)
=>
path
.
resolve
(
__dirname
,
'
..
'
,
'
public
'
,
'
docs
'
,
...
args
);
const
read
Wiki
s
=
()
=>
{
const
read
Doc
s
=
()
=>
{
const
createKey
=
name
=>
name
.
slice
(
0
,
-
3
);
const
list
=
dirPath
=>
fs
.
readdirSync
(
dirPath
).
filter
(
filename
=>
/
(\.
md
)
$/
.
test
(
filename
));
return
list
(
getPath
()).
map
(
wiki
Name
=>
({
key
:
createKey
(
wiki
Name
),
name
:
wiki
Name
,
return
list
(
getPath
()).
map
(
doc
Name
=>
({
key
:
createKey
(
doc
Name
),
name
:
doc
Name
,
}));
};
const
wikis
=
readWiki
s
();
const
docs
=
readDoc
s
();
const
get
Wiki
s
=
(
req
,
res
,
next
)
=>
{
res
.
json
({
wiki
s
});
const
get
Doc
s
=
(
req
,
res
,
next
)
=>
{
res
.
json
({
docs
:
doc
s
});
};
const
get
Wiki
=
(
req
,
res
,
next
)
=>
{
const
{
wiki
Key
}
=
req
.
params
;
const
get
Doc
=
(
req
,
res
,
next
)
=>
{
const
{
doc
Key
}
=
req
.
params
;
const
wiki
=
wikis
.
find
(
wiki
=>
wiki
.
key
===
wiki
Key
);
if
(
!
wiki
)
return
next
(
new
NotFoundError
());
const
doc
=
docs
.
find
(
doc
=>
doc
.
key
===
doc
Key
);
if
(
!
doc
)
return
next
(
new
NotFoundError
());
const
wikiPath
=
getPath
(
wiki
.
name
);
res
.
sendFile
(
wiki
Path
);
const
docPath
=
getPath
(
doc
.
name
);
res
.
sendFile
(
doc
Path
);
};
router
.
route
(
'
/
'
)
.
get
(
get
Wiki
s
);
.
get
(
get
Doc
s
);
router
.
route
(
'
/:
wiki
Key
'
)
.
get
(
get
Wiki
);
router
.
route
(
'
/:
doc
Key
'
)
.
get
(
get
Doc
);
export
default
router
;
\ No newline at end of file
src/backend/controllers/index.js
浏览文件 @
f6431e7a
import
express
from
'
express
'
;
import
{
AuthorizationError
,
NotFoundError
,
PermissionError
}
from
'
/common/error
'
;
import
auth
from
'
./auth
'
;
import
category
from
'
./category
'
;
import
compiler
from
'
./compiler
'
;
import
wiki
from
'
./wiki
'
;
const
router
=
new
express
.
Router
();
router
.
use
(
'
/auth
'
,
auth
);
router
.
use
(
'
/category
'
,
category
);
router
.
use
(
'
/compiler
'
,
compiler
);
router
.
use
(
'
/wiki
'
,
wiki
);
router
.
use
((
req
,
res
,
next
)
=>
next
(
new
NotFoundError
()));
router
.
use
((
err
,
req
,
res
,
next
)
=>
{
const
statusMap
=
[
[
AuthorizationError
,
401
],
[
PermissionError
,
403
],
[
NotFoundError
,
404
],
[
Error
,
500
],
];
const
[,
status
]
=
statusMap
.
find
(([
Error
])
=>
err
instanceof
Error
);
res
.
status
(
status
);
res
.
json
({
status
,
err
,
});
console
.
error
(
err
);
});
export
default
router
;
\ No newline at end of file
export
{
default
as
auth
}
from
'
./auth
'
;
export
{
default
as
categories
}
from
'
./categories
'
;
export
{
default
as
compilers
}
from
'
./compilers
'
;
export
{
default
as
docs
}
from
'
./docs
'
;
src/backend/index.js
浏览文件 @
f6431e7a
...
...
@@ -2,13 +2,30 @@ import express from 'express';
import
morgan
from
'
morgan
'
;
import
cookieParser
from
'
cookie-parser
'
;
import
bodyParser
from
'
body-parser
'
;
import
controllers
from
'
/controllers
'
;
import
*
as
controllers
from
'
/controllers
'
;
import
{
AuthorizationError
,
NotFoundError
,
PermissionError
}
from
'
/common/error
'
;
const
app
=
express
();
app
.
use
(
morgan
(
'
tiny
'
));
app
.
use
(
cookieParser
());
app
.
use
(
bodyParser
.
json
());
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
true
}));
app
.
use
(
controllers
);
Object
.
keys
(
controllers
).
forEach
(
key
=>
app
.
use
(
`/
${
key
}
`
,
controllers
[
key
]));
app
.
use
((
req
,
res
,
next
)
=>
next
(
new
NotFoundError
()));
app
.
use
((
err
,
req
,
res
,
next
)
=>
{
const
statusMap
=
[
[
AuthorizationError
,
401
],
[
PermissionError
,
403
],
[
NotFoundError
,
404
],
[
Error
,
500
],
];
const
[,
status
]
=
statusMap
.
find
(([
Error
])
=>
err
instanceof
Error
);
res
.
status
(
status
);
res
.
json
({
status
,
err
,
});
console
.
error
(
err
);
});
export
default
app
;
\ No newline at end of file
docs
@
08dc9b23
Subproject commit 08dc9b2369dd65a69fa5e3d9eb0e2c268fdb94fd
src/frontend/apis/index.js
浏览文件 @
f6431e7a
...
...
@@ -54,13 +54,13 @@ const PATCH = URL => {
};
const
CategoryApi
=
{
getCategories
:
GET
(
'
/categor
y
'
),
getAlgorithm
:
GET
(
'
/categor
y
/:categoryKey/:algorithmKey
'
),
getCategories
:
GET
(
'
/categor
ies
'
),
getAlgorithm
:
GET
(
'
/categor
ies
/:categoryKey/:algorithmKey
'
),
};
const
Wiki
Api
=
{
get
Wikis
:
GET
(
'
/wiki
'
),
get
Wiki
:
GET
(
'
/wiki/:wiki
'
),
const
Doc
Api
=
{
get
Docs
:
GET
(
'
/docs
'
),
get
Doc
:
GET
(
'
/docs/:docKey
'
),
};
const
GitHubApi
=
{
...
...
@@ -77,7 +77,7 @@ let jsWorker = null;
const
CompilerApi
=
{
js
:
code
=>
new
Promise
((
resolve
,
reject
)
=>
{
if
(
jsWorker
)
jsWorker
.
terminate
();
jsWorker
=
new
Worker
(
'
/api/compiler/js
'
);
jsWorker
=
new
Worker
(
'
/api/compiler
s
/js
'
);
jsWorker
.
onmessage
=
e
=>
resolve
(
e
.
data
);
jsWorker
.
onerror
=
reject
;
jsWorker
.
postMessage
(
code
);
...
...
@@ -86,7 +86,7 @@ const CompilerApi = {
export
{
CategoryApi
,
Wiki
Api
,
Doc
Api
,
GitHubApi
,
CompilerApi
,
};
\ No newline at end of file
src/frontend/components/WikiViewer/index.jsx
浏览文件 @
f6431e7a
import
React
from
'
react
'
;
import
{
Wiki
Api
}
from
'
/apis
'
;
import
{
Doc
Api
}
from
'
/apis
'
;
import
{
MarkdownViewer
}
from
'
/components
'
;
import
{
classes
}
from
'
/common/util
'
;
import
styles
from
'
./stylesheet.scss
'
;
...
...
@@ -18,7 +18,7 @@ class WikiViewer extends React.Component {
}
loadMarkdown
(
href
)
{
WikiApi
.
getWiki
(
href
)
DocApi
.
getDoc
(
href
)
.
then
(
source
=>
this
.
setState
({
source
}));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录