22#include " cstdio"
33#include " random"
44#include " string"
5+ #include < algorithm>
6+ #include < drogon/HttpResponse.h>
57#include < iostream>
68#include < ostream>
7- #include < algorithm>
89
910namespace nitro_utils {
1011inline std::string generate_random_string (std::size_t length) {
@@ -23,39 +24,78 @@ inline std::string generate_random_string(std::size_t length) {
2324 return random_string;
2425}
2526
26- inline void nitro_logo (){
27- std::string rainbowColors[] = {
28- " \033 [93m" , // Yellow
29- " \033 [94m" , // Blue
30- };
31-
32- std::string resetColor = " \033 [0m" ;
33- std::string asciiArt =
34- " ___ ___ ___ \n "
35- " /__/\ ___ ___ / /\\ / /\\ \n "
36- " \\ \\ :\\ / /\\ / /\\ / /::\\ / /::\\ \n "
37- " \\ \\ :\\ / /:/ / /:/ / /:/\\ :\\ / /:/\\ :\\ \n "
38- " _____\\ __\\ :\\ /__/::\\ / /:/ / /:/ \\ :\\ / /:/ \\ :\\ \n "
39- " /__/::::::::\\ \\ __\\ /\\ :\\ __ / /::\\ /__/:/ /:/___ /__/:/ \\ __\\ :\\\n "
40- " \\ \\ :\\ ~~\\ ~~\\ / \\ \\ :\\ /\\ /__/:/\\ :\\ \\ \\ :\\ /:::::/ \\ \\ :\\ / /:/\n "
41- " \\ \\ :\\ ~~~ \\ __\\ ::/ \\ __\\ / \\ :\\ \\ \\ ::/~~~~ \\ \\ :\\ /:/ \n "
42- " \\ \\ :\\ /__/:/ \\ \\ :\\ \\ \\ :\\ \\ \\ :\\ /:/ \n "
43- " \\ \\ :\\ \\ __\\ / \\ __\\ / \\ \\ :\\ \\ \\ ::/ \n "
44- " \\ __\\ / \\ __\\ / \\ __\\ / \n " ;
45-
46- int colorIndex = 0 ;
47-
48- for (char c : asciiArt) {
49- if (c == ' \n ' ) {
50- std::cout << resetColor << c;
51- colorIndex = 0 ;
52- } else {
53- std::cout << rainbowColors[colorIndex % 2 ] << c;
54- colorIndex++;
55- }
27+ inline void nitro_logo () {
28+ std::string rainbowColors[] = {
29+ " \033 [93m" , // Yellow
30+ " \033 [94m" , // Blue
31+ };
32+
33+ std::string resetColor = " \033 [0m" ;
34+ std::string asciiArt =
35+ " ___ ___ ___ \n "
36+ " /__/\ ___ ___ / /\\ / /\\ \n "
37+ " \\ \\ :\\ / /\\ / /\\ / /::\\ / /::\\ "
38+ " \n "
39+ " \\ \\ :\\ / /:/ / /:/ / /:/\\ :\\ / /:/\\ :\\ "
40+ " \n "
41+ " _____\\ __\\ :\\ /__/::\\ / /:/ / /:/ \\ :\\ / /:/ "
42+ " \\ :\\ \n "
43+ " /__/::::::::\\ \\ __\\ /\\ :\\ __ / /::\\ /__/:/ /:/___ /__/:/ "
44+ " \\ __\\ :\\\n "
45+ " \\ \\ :\\ ~~\\ ~~\\ / \\ \\ :\\ /\\ /__/:/\\ :\\ \\ \\ :\\ /:::::/ \\ "
46+ " \\ :\\ / /:/\n "
47+ " \\ \\ :\\ ~~~ \\ __\\ ::/ \\ __\\ / \\ :\\ \\ \\ ::/~~~~ \\ "
48+ " \\ :\\ /:/ \n "
49+ " \\ \\ :\\ /__/:/ \\ \\ :\\ \\ \\ :\\ \\ "
50+ " \\ :\\ /:/ \n "
51+ " \\ \\ :\\ \\ __\\ / \\ __\\ / \\ \\ :\\ \\ "
52+ " \\ ::/ \n "
53+ " \\ __\\ / \\ __\\ / \\ __\\ / "
54+ " \n " ;
55+
56+ int colorIndex = 0 ;
57+
58+ for (char c : asciiArt) {
59+ if (c == ' \n ' ) {
60+ std::cout << resetColor << c;
61+ colorIndex = 0 ;
62+ } else {
63+ std::cout << rainbowColors[colorIndex % 2 ] << c;
64+ colorIndex++;
5665 }
66+ }
67+
68+ std::cout << resetColor; // Reset color at the endreturn;
69+ }
70+
71+ inline drogon::HttpResponsePtr nitroHttpResponse () {
72+ auto resp = drogon::HttpResponse::newHttpResponse ();
73+ #ifdef ALLOW_ALL_CORS
74+ LOG_INFO << " Respond for all cors!" ;
75+ resp->addHeader (" Access-Control-Allow-Origin" , " *" );
76+ #endif
77+ return resp;
78+ }
79+
80+ inline drogon::HttpResponsePtr nitroHttpJsonResponse (const Json::Value &data) {
81+ auto resp = drogon::HttpResponse::newHttpJsonResponse (data);
82+ #ifdef ALLOW_ALL_CORS
83+ LOG_INFO << " Respond for all cors!" ;
84+ resp->addHeader (" Access-Control-Allow-Origin" , " *" );
85+ #endif
86+ return resp;
87+ };
5788
58- std::cout << resetColor; // Reset color at the endreturn;
89+ inline drogon::HttpResponsePtr nitroStreamResponse (
90+ const std::function<std::size_t (char *, std::size_t )> &callback,
91+ const std::string &attachmentFileName = "") {
92+ auto resp =
93+ drogon::HttpResponse::newStreamResponse (callback, attachmentFileName);
94+ #ifdef ALLOW_ALL_CORS
95+ LOG_INFO << " Respond for all cors!" ;
96+ resp->addHeader (" Access-Control-Allow-Origin" , " *" );
97+ #endif
98+ return resp;
5999}
60100
61101} // namespace nitro_utils
0 commit comments