比较提交

...

2 次代码提交

共有 5 个文件被更改,包括 36 次插入4 次删除

查看文件

@ -33,7 +33,7 @@ SOFTWARE.
#include "handlerhistory.h" #include "handlerhistory.h"
#include "handlerpagedelete.h" #include "handlerpagedelete.h"
#include "handlerusersettings.h" #include "handlerusersettings.h"
#include "handlerversion.h"
std::unique_ptr<Handler> HandlerFactory::createHandler(const std::string &action, Session &userSession) std::unique_ptr<Handler> HandlerFactory::createHandler(const std::string &action, Session &userSession)
{ {
if(action == "" || action == "index") if(action == "" || action == "index")
@ -80,6 +80,10 @@ std::unique_ptr<Handler> HandlerFactory::createHandler(const std::string &action
{ {
return produce<HandlerUserSettings>(userSession); return produce<HandlerUserSettings>(userSession);
} }
if(action == "version")
{
return produce<HandlerVersion>(userSession);
}
return produce<HandlerInvalidAction>(userSession); return produce<HandlerInvalidAction>(userSession);
} }

查看文件

@ -0,0 +1,9 @@
#include "handlerversion.h"
#include "../version.h"
Response HandlerVersion::handleRequest(const Request &r)
{
Response response;
response.setContentType("text/plain");
response.setBody(get_version_string());
return response;
}

18
handlers/handlerversion.h 普通文件
查看文件

@ -0,0 +1,18 @@
#ifndef HANDLERVERSION_H
#define HANDLERVERSION_H
#include "handler.h"
class HandlerVersion : public Handler
{
public:
using Handler::Handler;
public:
Response handleRequest(const Request &r) override;
bool canAccess(const Permissions &perms) override
{
return true;
}
};
#endif // HANDLERVERSION_H

查看文件

@ -27,7 +27,7 @@ TemplatePage::TemplatePage()
TemplatePage::TemplatePage(std::string content) TemplatePage::TemplatePage(std::string content)
{ {
this->content = content; this->content = std::make_shared<std::string>(content);
} }
void TemplatePage::setVar(const std::string &key, std::string value) void TemplatePage::setVar(const std::string &key, std::string value)
@ -40,5 +40,5 @@ std::string TemplatePage::render() const
Varreplacer replacer("{qswiki:"); Varreplacer replacer("{qswiki:");
replacer.addResolver("var", replacer.addResolver("var",
[&](std::string_view key) { return utils::getKeyOrEmpty(this->varsMap, std::string(key)); }); [&](std::string_view key) { return utils::getKeyOrEmpty(this->varsMap, std::string(key)); });
return replacer.parse(this->content); return replacer.parse(*this->content);
} }

查看文件

@ -3,10 +3,11 @@
#include <string> #include <string>
#include <string_view> #include <string_view>
#include <map> #include <map>
#include <memory>
class TemplatePage class TemplatePage
{ {
private: private:
std::string content; std::shared_ptr<const std::string> content;
std::map<std::string, std::string> varsMap; std::map<std::string, std::string> varsMap;
public: public: