Skip to content

Commit 70b3248

Browse files
file open
1 parent cbc9f56 commit 70b3248

File tree

9 files changed

+29
-2
lines changed

9 files changed

+29
-2
lines changed

file_controller.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,16 @@ std::string genTree(const HttpRequestPtr &req, std::function<void(const HttpResp
3333
res ->setBody(result);
3434
callback(res);
3535
return result;
36-
}
36+
}
37+
std::string catFile(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback)
38+
{
39+
char *pathvar;
40+
pathvar = getenv("PWD");
41+
std::string path = req->getParameter("path");
42+
std::string result = shell_commons(("cat "+std::string(pathvar)+"/../root/"+path).c_str()) ;
43+
auto res = HttpResponse::newHttpResponse();
44+
res->addHeader("Access-Control-Allow-Origin", "*");
45+
res ->setBody(result);
46+
callback(res);
47+
return result;
48+
}

file_controller.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
using namespace drogon;
66
std::string shell_commons(const char* cmd);
77
std::string genTree(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback);
8+
std::string catFile(const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback);
89
//std::string
9-
#endif
10+
#endif

main.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ int main() {
3333

3434
drogon::app().registerHandler("/api/file/tree", [](const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback) {
3535
genTree(req, std::move(callback));
36+
});
37+
drogon::app().registerHandler("/api/file/cat", [](const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback) {
38+
catFile(req, std::move(callback));
3639
});
3740
drogon::app().registerHandler("/api/avatar", [](const HttpRequestPtr &req, std::function<void(const HttpResponsePtr &)> &&callback) {
3841
avatar(req, std::move(callback));

root/lgy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# this is lgy file
File renamed without changes.

root/llggyy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
### this is llggyy file~
2+
3+
```c++
4+
#include <iostream>
5+
int main()
6+
{
7+
std::cout<<"Hello, world!"<<std::endl;
8+
return 0;
9+
}
10+
```

root/root文件2

Whitespace-only changes.

root/root里面的文件夹/root里面文件夹里面的文件夹/root里面的文件夹里面的文件夹里面的文件

Whitespace-only changes.

root/root里面的文件夹/root里面的文件夹里面的文件

Whitespace-only changes.

0 commit comments

Comments
 (0)