mirror of
https://github.com/KingDuckZ/kamokan.git
synced 2025-10-02 15:00:02 +00:00
Allow retrieval of pasties
This commit is contained in:
parent
091746e9b6
commit
31890ba5e4
4 changed files with 50 additions and 2 deletions
|
@ -18,6 +18,7 @@ add_executable(${PROJECT_NAME}
|
||||||
cgi_post.cpp
|
cgi_post.cpp
|
||||||
curl_wrapper.cpp
|
curl_wrapper.cpp
|
||||||
index_response.cpp
|
index_response.cpp
|
||||||
|
pastie_response.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} SYSTEM
|
target_include_directories(${PROJECT_NAME} SYSTEM
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "incredis/incredis.hpp"
|
#include "incredis/incredis.hpp"
|
||||||
#include "submit_paste_response.hpp"
|
#include "submit_paste_response.hpp"
|
||||||
|
#include "pastie_response.hpp"
|
||||||
#include "index_response.hpp"
|
#include "index_response.hpp"
|
||||||
#include "cgi_env.hpp"
|
#include "cgi_env.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -26,8 +27,8 @@ int main() {
|
||||||
resp.send();
|
resp.send();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::cout << "Content-type:text/plain\n\n";
|
tawashi::PastieResponse resp(incredis);
|
||||||
std::cout << "you shouldn't be here\n";
|
resp.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
26
src/pastie_response.cpp
Normal file
26
src/pastie_response.cpp
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#include "pastie_response.hpp"
|
||||||
|
#include "incredis/incredis.hpp"
|
||||||
|
#include <ciso646>
|
||||||
|
|
||||||
|
namespace tawashi {
|
||||||
|
PastieResponse::PastieResponse (redis::IncRedis& parRedis) :
|
||||||
|
Response("text/plain"),
|
||||||
|
m_redis(parRedis)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void PastieResponse::on_send (std::ostream& parStream) {
|
||||||
|
using opt_string = redis::IncRedis::opt_string;
|
||||||
|
|
||||||
|
if (cgi_env().path_info().empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto token = boost::string_ref(cgi_env().path_info()).substr(1);
|
||||||
|
opt_string pastie = m_redis.get(token);
|
||||||
|
if (not pastie) {
|
||||||
|
}
|
||||||
|
|
||||||
|
parStream << *pastie;
|
||||||
|
}
|
||||||
|
} //namespace tawashi
|
20
src/pastie_response.hpp
Normal file
20
src/pastie_response.hpp
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "response.hpp"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace redis {
|
||||||
|
class IncRedis;
|
||||||
|
} //namespace redis
|
||||||
|
|
||||||
|
namespace tawashi {
|
||||||
|
class PastieResponse : public Response {
|
||||||
|
public:
|
||||||
|
PastieResponse (redis::IncRedis& parRedis);
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual void on_send (std::ostream& parStream) override;
|
||||||
|
|
||||||
|
redis::IncRedis& m_redis;
|
||||||
|
};
|
||||||
|
} //namespace tawashi
|
Loading…
Add table
Add a link
Reference in a new issue