Initial Commit

master
Kirigaya Kazuto 2017-11-21 15:38:03 +08:00
commit 53bbe2d65a
4 changed files with 13120 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "HTTPWrapper"]
path = HTTPWrapper
url = http://kiritow.com:3000/HCTECH/HTTPWrapper.git

1
HTTPWrapper Submodule

@ -0,0 +1 @@
Subproject commit 190e17c074f64eb4ef322ea529e80fc94073adbc

113
doPaste.cpp Normal file
View File

@ -0,0 +1,113 @@
#include "Request.h"
#include "Response.h"
#include "Util.h"
#include "json.hpp"
#include <fstream>
#include <cstdio>
#include "windows.h"
using namespace std;
using json = nlohmann::json;
const string docroot = "D:\\Bitnami\\wampstack-5.6.31-0\\apache2\\htdocs\\";
int main()
{
Request req;
Response res;
json j;
auto jsonfail=[&](int errcode,const std::string& errmsg)
{
j["success"]=0;
j["errcode"]=errcode;
j["errmsg"]=errmsg;
};
do
{
if(req.requestMethod!="POST")
{
jsonfail(1,"Request Method Not Supported");
break;
}
if(req.post.find("code")==req.post.end() ||
req.post.find("title")==req.post.end() )
{
jsonfail(2,"Missing Parameters");
break;
}
string code=req.post["code"];
string title=req.post["title"];
string html;
ifstream ifs("paste_template.txt");
if(!ifs)
{
jsonfail(3,"Failed to read template.");
break;
}
string temp;
while(getline(ifs,temp))
{
html.append(temp);
}
int len=code.size();
ostringstream ostr;
for(int i=0;i<len;i++)
{
if(code[i]=='<')
{
ostr<<"&lt";
}
else if(code[i]=='>')
{
ostr<<"&gt";
}
else
{
ostr<<code[i];
}
}
string purecode=ostr.str();
string tag="{{Title}}";
html.replace(html.find(tag),tag.size(),title);
tag="{{Codetag}}";
html.replace(html.find(tag),tag.size(),"cpp");
tag="{{Code}}";
html.replace(html.find(tag),tag.size(),purecode);
int id,rd;
srand(time(NULL));
while(true)
{
id=time(NULL);
rd=rand()%100;
ifstream ifsx(make_str(docroot,"paste\\",id,"_",rd,".html"));
if(ifsx) continue;
else break;
}
string fname=make_str(docroot,"paste\\",id,"_",rd,".html");
ofstream ofs(fname);
if(!ofs)
{
jsonfail(4,"File cannot be created.");
break;
}
ofs<<html<<endl;
j["success"]=1;
j["next_url"]=make_str("/paste/",id,"_",rd,".html");
}while(0);
res.content.append(j.dump());
res.show();
return 0;
}

13003
json.hpp Normal file

File diff suppressed because it is too large Load Diff