diff --git a/.clang-format b/.clang-format index f3960e2..aa2f616 100644 --- a/.clang-format +++ b/.clang-format @@ -4,7 +4,7 @@ ObjCBlockIndentWidth: 4 IndentWidth: 4 TabWidth: 4 AccessModifierOffset: -4 -ColumnLimit: 120 +ColumnLimit: 130 #模板声明后换行 AlwaysBreakTemplateDeclarations: true diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index c5756b3..dc845e2 100755 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -5,6 +5,7 @@ on: paths: - '**.cpp' - '**.h' + - '**.conf' jobs: Build: runs-on: [ubuntu-latest, ubuntu-24.04] @@ -59,6 +60,24 @@ jobs: cp /tmp/HttpServer /root/Server/HttpServer nohup /root/Server/HttpServer > /dev/null 2>&1 & exit 0 + - name: Copy openresty configuration files to server + uses: appleboy/scp-action@v0.1.7 + with: + host: ${{ vars.YUYUN_SERVER }} + username: ${{ vars.YUYUN_USER }} + password: ${{ secrets.SERVER_ROOT_PASSWORD }} + overwrite: true + strip_components: 1 + source: Server/conf + target: /root/Server + - name: Restart openresty + uses: appleboy/ssh-action@v1.1.0 + with: + host: ${{ vars.YUYUN_SERVER }} + username: ${{ vars.YUYUN_USER }} + password: ${{ secrets.SERVER_ROOT_PASSWORD }} + script: | + systemctl restart openresty.service - name: Notify-End if: ${{ always() }} run: | diff --git a/Server/Application.h b/Server/Application.h index 4969ecd..d06d95e 100644 --- a/Server/Application.h +++ b/Server/Application.h @@ -27,6 +27,7 @@ public: BUILD_SETTING(std::string, Server, "0.0.0.0"); BUILD_SETTING(uint16_t, Port, 8081); + BUILD_SETTING(uint16_t, WtPort, 8082); BUILD_SETTING(uint32_t, Threads, std::thread::hardware_concurrency()); BUILD_SETTING(std::string, DocumentRoot, "."); BUILD_SETTING(std::string, Sqlte3Path, "database.sqlite"); diff --git a/Server/conf/mime.types b/Server/conf/mime.types index e20549a..1c00d70 100644 --- a/Server/conf/mime.types +++ b/Server/conf/mime.types @@ -1,97 +1,99 @@ - -types { - text/html html htm shtml; - text/css css; - text/xml xml; - image/gif gif; - image/jpeg jpeg jpg; - application/javascript js; - application/atom+xml atom; - application/rss+xml rss; - - text/mathml mml; - text/plain txt; - text/vnd.sun.j2me.app-descriptor jad; - text/vnd.wap.wml wml; - text/x-component htc; - - image/png png; - image/svg+xml svg svgz; - image/tiff tif tiff; - image/vnd.wap.wbmp wbmp; - image/webp webp; - image/x-icon ico; - image/x-jng jng; - image/x-ms-bmp bmp; - - font/woff woff; - font/woff2 woff2; - - application/java-archive jar war ear; - application/json json; - application/mac-binhex40 hqx; - application/msword doc; - application/pdf pdf; - application/postscript ps eps ai; - application/rtf rtf; - application/vnd.apple.mpegurl m3u8; - application/vnd.google-earth.kml+xml kml; - application/vnd.google-earth.kmz kmz; - application/vnd.ms-excel xls; - application/vnd.ms-fontobject eot; - application/vnd.ms-powerpoint ppt; - application/vnd.oasis.opendocument.graphics odg; - application/vnd.oasis.opendocument.presentation odp; - application/vnd.oasis.opendocument.spreadsheet ods; - application/vnd.oasis.opendocument.text odt; - application/vnd.openxmlformats-officedocument.presentationml.presentation - pptx; - application/vnd.openxmlformats-officedocument.spreadsheetml.sheet - xlsx; - application/vnd.openxmlformats-officedocument.wordprocessingml.document - docx; - application/vnd.wap.wmlc wmlc; - application/x-7z-compressed 7z; - application/x-cocoa cco; - application/x-java-archive-diff jardiff; - application/x-java-jnlp-file jnlp; - application/x-makeself run; - application/x-perl pl pm; - application/x-pilot prc pdb; - application/x-rar-compressed rar; - application/x-redhat-package-manager rpm; - application/x-sea sea; - application/x-shockwave-flash swf; - application/x-stuffit sit; - application/x-tcl tcl tk; - application/x-x509-ca-cert der pem crt; - application/x-xpinstall xpi; - application/xhtml+xml xhtml; - application/xspf+xml xspf; - application/zip zip; - - application/octet-stream bin exe dll; - application/octet-stream deb; - application/octet-stream dmg; - application/octet-stream iso img; - application/octet-stream msi msp msm; - - audio/midi mid midi kar; - audio/mpeg mp3; - audio/ogg ogg; - audio/x-m4a m4a; - audio/x-realaudio ra; - - video/3gpp 3gpp 3gp; - video/mp2t ts; - video/mp4 mp4; - video/mpeg mpeg mpg; - video/quicktime mov; - video/webm webm; - video/x-flv flv; - video/x-m4v m4v; - video/x-mng mng; - video/x-ms-asf asx asf; - video/x-ms-wmv wmv; - video/x-msvideo avi; -} + +types { + text/html html htm shtml; + text/css css; + text/xml xml; + image/gif gif; + image/jpeg jpeg jpg; + application/javascript js; + application/atom+xml atom; + application/rss+xml rss; + + text/mathml mml; + text/plain txt; + text/vnd.sun.j2me.app-descriptor jad; + text/vnd.wap.wml wml; + text/x-component htc; + + image/avif avif; + image/png png; + image/svg+xml svg svgz; + image/tiff tif tiff; + image/vnd.wap.wbmp wbmp; + image/webp webp; + image/x-icon ico; + image/x-jng jng; + image/x-ms-bmp bmp; + + font/woff woff; + font/woff2 woff2; + + application/java-archive jar war ear; + application/json json; + application/mac-binhex40 hqx; + application/msword doc; + application/pdf pdf; + application/postscript ps eps ai; + application/rtf rtf; + application/vnd.apple.mpegurl m3u8; + application/vnd.google-earth.kml+xml kml; + application/vnd.google-earth.kmz kmz; + application/vnd.ms-excel xls; + application/vnd.ms-fontobject eot; + application/vnd.ms-powerpoint ppt; + application/vnd.oasis.opendocument.graphics odg; + application/vnd.oasis.opendocument.presentation odp; + application/vnd.oasis.opendocument.spreadsheet ods; + application/vnd.oasis.opendocument.text odt; + application/vnd.openxmlformats-officedocument.presentationml.presentation + pptx; + application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + xlsx; + application/vnd.openxmlformats-officedocument.wordprocessingml.document + docx; + application/vnd.wap.wmlc wmlc; + application/wasm wasm; + application/x-7z-compressed 7z; + application/x-cocoa cco; + application/x-java-archive-diff jardiff; + application/x-java-jnlp-file jnlp; + application/x-makeself run; + application/x-perl pl pm; + application/x-pilot prc pdb; + application/x-rar-compressed rar; + application/x-redhat-package-manager rpm; + application/x-sea sea; + application/x-shockwave-flash swf; + application/x-stuffit sit; + application/x-tcl tcl tk; + application/x-x509-ca-cert der pem crt; + application/x-xpinstall xpi; + application/xhtml+xml xhtml; + application/xspf+xml xspf; + application/zip zip; + + application/octet-stream bin exe dll; + application/octet-stream deb; + application/octet-stream dmg; + application/octet-stream iso img; + application/octet-stream msi msp msm; + + audio/midi mid midi kar; + audio/mpeg mp3; + audio/ogg ogg; + audio/x-m4a m4a; + audio/x-realaudio ra; + + video/3gpp 3gpp 3gp; + video/mp2t ts; + video/mp4 mp4; + video/mpeg mpeg mpg; + video/quicktime mov; + video/webm webm; + video/x-flv flv; + video/x-m4v m4v; + video/x-mng mng; + video/x-ms-asf asx asf; + video/x-ms-wmv wmv; + video/x-msvideo avi; +} diff --git a/Server/conf/mime.types.default b/Server/conf/mime.types.default index e20549a..1c00d70 100644 --- a/Server/conf/mime.types.default +++ b/Server/conf/mime.types.default @@ -1,97 +1,99 @@ - -types { - text/html html htm shtml; - text/css css; - text/xml xml; - image/gif gif; - image/jpeg jpeg jpg; - application/javascript js; - application/atom+xml atom; - application/rss+xml rss; - - text/mathml mml; - text/plain txt; - text/vnd.sun.j2me.app-descriptor jad; - text/vnd.wap.wml wml; - text/x-component htc; - - image/png png; - image/svg+xml svg svgz; - image/tiff tif tiff; - image/vnd.wap.wbmp wbmp; - image/webp webp; - image/x-icon ico; - image/x-jng jng; - image/x-ms-bmp bmp; - - font/woff woff; - font/woff2 woff2; - - application/java-archive jar war ear; - application/json json; - application/mac-binhex40 hqx; - application/msword doc; - application/pdf pdf; - application/postscript ps eps ai; - application/rtf rtf; - application/vnd.apple.mpegurl m3u8; - application/vnd.google-earth.kml+xml kml; - application/vnd.google-earth.kmz kmz; - application/vnd.ms-excel xls; - application/vnd.ms-fontobject eot; - application/vnd.ms-powerpoint ppt; - application/vnd.oasis.opendocument.graphics odg; - application/vnd.oasis.opendocument.presentation odp; - application/vnd.oasis.opendocument.spreadsheet ods; - application/vnd.oasis.opendocument.text odt; - application/vnd.openxmlformats-officedocument.presentationml.presentation - pptx; - application/vnd.openxmlformats-officedocument.spreadsheetml.sheet - xlsx; - application/vnd.openxmlformats-officedocument.wordprocessingml.document - docx; - application/vnd.wap.wmlc wmlc; - application/x-7z-compressed 7z; - application/x-cocoa cco; - application/x-java-archive-diff jardiff; - application/x-java-jnlp-file jnlp; - application/x-makeself run; - application/x-perl pl pm; - application/x-pilot prc pdb; - application/x-rar-compressed rar; - application/x-redhat-package-manager rpm; - application/x-sea sea; - application/x-shockwave-flash swf; - application/x-stuffit sit; - application/x-tcl tcl tk; - application/x-x509-ca-cert der pem crt; - application/x-xpinstall xpi; - application/xhtml+xml xhtml; - application/xspf+xml xspf; - application/zip zip; - - application/octet-stream bin exe dll; - application/octet-stream deb; - application/octet-stream dmg; - application/octet-stream iso img; - application/octet-stream msi msp msm; - - audio/midi mid midi kar; - audio/mpeg mp3; - audio/ogg ogg; - audio/x-m4a m4a; - audio/x-realaudio ra; - - video/3gpp 3gpp 3gp; - video/mp2t ts; - video/mp4 mp4; - video/mpeg mpeg mpg; - video/quicktime mov; - video/webm webm; - video/x-flv flv; - video/x-m4v m4v; - video/x-mng mng; - video/x-ms-asf asx asf; - video/x-ms-wmv wmv; - video/x-msvideo avi; -} + +types { + text/html html htm shtml; + text/css css; + text/xml xml; + image/gif gif; + image/jpeg jpeg jpg; + application/javascript js; + application/atom+xml atom; + application/rss+xml rss; + + text/mathml mml; + text/plain txt; + text/vnd.sun.j2me.app-descriptor jad; + text/vnd.wap.wml wml; + text/x-component htc; + + image/avif avif; + image/png png; + image/svg+xml svg svgz; + image/tiff tif tiff; + image/vnd.wap.wbmp wbmp; + image/webp webp; + image/x-icon ico; + image/x-jng jng; + image/x-ms-bmp bmp; + + font/woff woff; + font/woff2 woff2; + + application/java-archive jar war ear; + application/json json; + application/mac-binhex40 hqx; + application/msword doc; + application/pdf pdf; + application/postscript ps eps ai; + application/rtf rtf; + application/vnd.apple.mpegurl m3u8; + application/vnd.google-earth.kml+xml kml; + application/vnd.google-earth.kmz kmz; + application/vnd.ms-excel xls; + application/vnd.ms-fontobject eot; + application/vnd.ms-powerpoint ppt; + application/vnd.oasis.opendocument.graphics odg; + application/vnd.oasis.opendocument.presentation odp; + application/vnd.oasis.opendocument.spreadsheet ods; + application/vnd.oasis.opendocument.text odt; + application/vnd.openxmlformats-officedocument.presentationml.presentation + pptx; + application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + xlsx; + application/vnd.openxmlformats-officedocument.wordprocessingml.document + docx; + application/vnd.wap.wmlc wmlc; + application/wasm wasm; + application/x-7z-compressed 7z; + application/x-cocoa cco; + application/x-java-archive-diff jardiff; + application/x-java-jnlp-file jnlp; + application/x-makeself run; + application/x-perl pl pm; + application/x-pilot prc pdb; + application/x-rar-compressed rar; + application/x-redhat-package-manager rpm; + application/x-sea sea; + application/x-shockwave-flash swf; + application/x-stuffit sit; + application/x-tcl tcl tk; + application/x-x509-ca-cert der pem crt; + application/x-xpinstall xpi; + application/xhtml+xml xhtml; + application/xspf+xml xspf; + application/zip zip; + + application/octet-stream bin exe dll; + application/octet-stream deb; + application/octet-stream dmg; + application/octet-stream iso img; + application/octet-stream msi msp msm; + + audio/midi mid midi kar; + audio/mpeg mp3; + audio/ogg ogg; + audio/x-m4a m4a; + audio/x-realaudio ra; + + video/3gpp 3gpp 3gp; + video/mp2t ts; + video/mp4 mp4; + video/mpeg mpeg mpg; + video/quicktime mov; + video/webm webm; + video/x-flv flv; + video/x-m4v m4v; + video/x-mng mng; + video/x-ms-asf asx asf; + video/x-ms-wmv wmv; + video/x-msvideo avi; +} diff --git a/Server/conf/nginx.conf b/Server/conf/nginx.conf index 4b3a83e..5bbf29a 100644 --- a/Server/conf/nginx.conf +++ b/Server/conf/nginx.conf @@ -26,7 +26,7 @@ http { keepalive_timeout 65; gzip on; - gzip_types application/octet-stream text/markdown text/plain application/json application/x-javascript text/css application/xml text/javascript application/javascript application/x-httpd-php image/jpeg image/gif image/png; + gzip_types application/octet-stream text/markdown text/plain application/json application/x-javascript text/css application/xml text/javascript application/javascript application/x-httpd-php application/text image/jpeg image/gif image/png; # 定义一个限流区域,名称为 one,大小为 10MB,限速为每 5 分钟 5 次请求 limit_req_zone $binary_remote_addr zone=one:10m rate=3r/m; @@ -36,10 +36,14 @@ http { server 127.0.0.1:8081; } - upstream twikoo { + upstream wt { server 127.0.0.1:8082; } + upstream twikoo { + server 127.0.0.1:8083; + } + upstream frp_http_proxy { server 127.0.0.1:8084; } @@ -56,6 +60,10 @@ http { server 127.0.0.1:8088; } + upstream meilisearch { + server 127.0.0.1:7700; + } + upstream typesense { server 127.0.0.1:8108; } diff --git a/Server/conf/server.conf b/Server/conf/server.conf index 513790d..89d3d0e 100644 --- a/Server/conf/server.conf +++ b/Server/conf/server.conf @@ -31,10 +31,18 @@ location ^~ /api/v1/login { content_by_lua_file lua/login.lua; } +location ^~ /api/v1/search/ { + proxy_pass http://meilisearch/; +} + location ~ ^/api/v1/.*$ { proxy_pass http://local; } +location ~ ^/wt/.+$ { + proxy_pass http://wt; +} + location /freedom { if ($http_upgrade != "websocket") { # WebSocket协商失败时返回404 return 404; @@ -62,6 +70,7 @@ location ~ ^/(gitea|v2)($|/) { proxy_set_header Upgrade $http_upgrade; # 这里强制修改 Host 为 gitea.amass.fun 只是为了frpc能够做url路由 proxy_set_header Host gitea.amass.fun; + # proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; diff --git a/Server/main.cpp b/Server/main.cpp index aaf9580..6bee08b 100644 --- a/Server/main.cpp +++ b/Server/main.cpp @@ -101,7 +101,7 @@ int main(int argc, char const *argv[]) { auto udpServer = std::make_shared(application->ioContext()); auto mediaServer = std::make_shared(554, false); - auto webApp = Singleton::instance(); + auto webApp = Singleton::instance(application->getWtPort()); using namespace boost::asio::ip; auto proxyAddress = make_address(application->getServer()); diff --git a/WebApplication/WebApplication.cpp b/WebApplication/WebApplication.cpp index 0144249..b61d104 100644 --- a/WebApplication/WebApplication.cpp +++ b/WebApplication/WebApplication.cpp @@ -12,14 +12,15 @@ #include #include #include +#include -WebApplication::WebApplication() { +WebApplication::WebApplication(uint16_t port) { try { std::vector args; args.push_back("--approot=./build"); args.push_back("--docroot=./build"); args.push_back("--config=resources/wt_config.xml"); - args.push_back("--http-listen=127.0.0.1:8855"); + args.push_back(std::format("--http-listen=127.0.0.1:{}", port)); // --docroot=. --no-compression --http-listen 127.0.0.1:8855 initializeAuthenticationService(); @@ -27,11 +28,9 @@ WebApplication::WebApplication() { m_sqlConnectionPool = createConnectionPool(m_server->appRoot() + "database.sqlite"); m_server->addEntryPoint(Wt::EntryPointType::Application, - std::bind(&WebApplication::createApplication, this, std::placeholders::_1, false), - "/hello"); + std::bind(&WebApplication::createApplication, this, std::placeholders::_1, false), "/hello"); m_server->addEntryPoint(Wt::EntryPointType::WidgetSet, - std::bind(&WebApplication::createApplication, this, std::placeholders::_1, true), - "/wt/app.js"); + std::bind(&WebApplication::createApplication, this, std::placeholders::_1, true), "/wt/app.js"); m_server->addResource(std::make_shared(*m_sqlConnectionPool), "/auth"); m_server->addResource(std::make_shared(), "/plaintext"); m_server->addResource(std::make_shared("database.sqlite"), "/db"); @@ -45,8 +44,7 @@ WebApplication::WebApplication() { std::unique_ptr WebApplication::createConnectionPool(const std::string &sqlite3) { auto connection = std::make_unique(sqlite3); connection->setProperty("show-queries", "true"); - connection->setDateTimeStorage(Wt::Dbo::SqlDateTimeType::DateTime, - Wt::Dbo::backend::DateTimeStorage::PseudoISO8601AsText); + connection->setDateTimeStorage(Wt::Dbo::SqlDateTimeType::DateTime, Wt::Dbo::backend::DateTimeStorage::PseudoISO8601AsText); return std::make_unique(std::move(connection), 10); } diff --git a/WebApplication/WebApplication.h b/WebApplication/WebApplication.h index 23400f1..4e9db23 100644 --- a/WebApplication/WebApplication.h +++ b/WebApplication/WebApplication.h @@ -31,7 +31,7 @@ public: const Wt::Auth::PasswordService &passwordService(); protected: - WebApplication(); + WebApplication(uint16_t port); static std::unique_ptr createConnectionPool(const std::string &sqlite3); std::unique_ptr createApplication(const Wt::WEnvironment &env, bool embedded);