From 8c0128c4e767508b55b4a786be5e41e112e34264 Mon Sep 17 00:00:00 2001 From: luocai Date: Thu, 7 Nov 2024 18:21:04 +0800 Subject: [PATCH] update docker images. --- Dockerfiles/ubuntu2204.dockerfile | 13 ++++---- Dockerfiles/ubuntu2404.dockerfile | 13 ++++---- WebApplication/WebApplication.cpp | 9 +++--- WebApplication/WebApplication.h | 7 +++- WebApplication/model/BlogSession.cpp | 48 ++++++++++++++++++++++++++++ WebApplication/model/Post.h | 2 +- 6 files changed, 73 insertions(+), 19 deletions(-) diff --git a/Dockerfiles/ubuntu2204.dockerfile b/Dockerfiles/ubuntu2204.dockerfile index 2d3a637..7bcf035 100644 --- a/Dockerfiles/ubuntu2204.dockerfile +++ b/Dockerfiles/ubuntu2204.dockerfile @@ -2,7 +2,8 @@ FROM ubuntu:22.04 LABEL maintainer="amass <168062547@qq.com>" ENV DEBIAN_FRONTEND=noninteractive -ENV CODE_VERSION=4.93.1 +ENV CODE_VERSION=4.95.1 +ENV WT_VERSION=4.11.1 RUN sed -i "s@http://.*archive.ubuntu.com@http://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list \ && sed -i "s@http://.*security.ubuntu.com@http://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list \ @@ -92,13 +93,13 @@ RUN cd /root \ && rm -fr /root/nng-1.9.0* RUN cd /root \ - && wget https://github.com/emweb/wt/archive/4.11.0.tar.gz -O wt-4.11.0.tar.gz \ - && tar xvf wt-4.11.0.tar.gz \ - && cd /root/wt-4.11.0 \ - && cmake -G Ninja -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/Libraries/wt-4.11.0 -DENABLE_QT4=OFF -DENABLE_QT5=OFF -DENABLE_QT6=OFF -DBOOST_ROOT=/opt/Libraries/boost_1_86_0 \ + && wget https://github.com/emweb/wt/archive/${WT_VERSION}.tar.gz -O wt-${WT_VERSION}.tar.gz \ + && tar xvf wt-${WT_VERSION}.tar.gz \ + && cd /root/wt-${WT_VERSION} \ + && cmake -G Ninja -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/Libraries/wt-${WT_VERSION} -DENABLE_QT4=OFF -DENABLE_QT5=OFF -DENABLE_QT6=OFF -DBOOST_ROOT=/opt/Libraries/boost_1_86_0 \ && cmake --build build --target all \ && cmake --install build \ - && rm -fr /root/wt-4.11.0* + && rm -fr /root/wt-${WT_VERSION}* RUN cd /root \ && git clone --depth=1 --recursive https://github.com/ZLMediaKit/ZLMediaKit.git \ diff --git a/Dockerfiles/ubuntu2404.dockerfile b/Dockerfiles/ubuntu2404.dockerfile index a3bdd4d..42c3d7d 100644 --- a/Dockerfiles/ubuntu2404.dockerfile +++ b/Dockerfiles/ubuntu2404.dockerfile @@ -2,7 +2,8 @@ FROM ubuntu:24.04 LABEL maintainer="amass <168062547@qq.com>" ENV DEBIAN_FRONTEND=noninteractive -ENV CODE_VERSION=4.93.1 +ENV CODE_VERSION=4.95.1 +ENV WT_VERSION=4.11.1 RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' /etc/apt/sources.list.d/ubuntu.sources \ && apt update \ @@ -92,13 +93,13 @@ RUN cd /root \ && rm -fr /root/nng-1.9.0* RUN cd /root \ - && wget https://github.com/emweb/wt/archive/4.11.0.tar.gz -O wt-4.11.0.tar.gz \ - && tar xvf wt-4.11.0.tar.gz \ - && cd /root/wt-4.11.0 \ - && cmake -G Ninja -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/Libraries/wt-4.11.0 -DENABLE_QT4=OFF -DENABLE_QT5=OFF -DENABLE_QT6=OFF -DBOOST_ROOT=/opt/Libraries/boost_1_86_0 \ + && wget https://github.com/emweb/wt/archive/${WT_VERSION}.tar.gz -O wt-${WT_VERSION}.tar.gz \ + && tar xvf wt-${WT_VERSION}.tar.gz \ + && cd /root/wt-${WT_VERSION} \ + && cmake -G Ninja -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/Libraries/wt-${WT_VERSION} -DENABLE_QT4=OFF -DENABLE_QT5=OFF -DENABLE_QT6=OFF -DBOOST_ROOT=/opt/Libraries/boost_1_86_0 \ && cmake --build build --target all \ && cmake --install build \ - && rm -fr /root/wt-4.11.0* + && rm -fr /root/wt-${WT_VERSION}* RUN cd /root \ && git clone --depth=1 --recursive https://github.com/ZLMediaKit/ZLMediaKit.git \ diff --git a/WebApplication/WebApplication.cpp b/WebApplication/WebApplication.cpp index 6e1f3a4..1f4d73a 100644 --- a/WebApplication/WebApplication.cpp +++ b/WebApplication/WebApplication.cpp @@ -12,8 +12,7 @@ static std::unique_ptr createApplication(const Wt::WEnvironmen return std::make_unique(env, false); } -std::unique_ptr createBlogApplication(const Wt::WEnvironment &env, - Wt::Dbo::SqlConnectionPool *blogDb) { +std::unique_ptr createBlogApplication(const Wt::WEnvironment &env, Wt::Dbo::SqlConnectionPool *blogDb) { return std::make_unique(env, *blogDb); } @@ -32,9 +31,9 @@ WebApplication::WebApplication() { m_server->addEntryPoint(Wt::EntryPointType::Application, createApplication, "/hello"); BlogSession::configureAuth(); - auto blogDb = BlogSession::createConnectionPool(m_server->appRoot() + "database.sqlite"); - m_server->addEntryPoint(Wt::EntryPointType::Application, - std::bind(&createBlogApplication, std::placeholders::_1, blogDb.get()), "/blog"); + m_blogSqlConnectionPool = BlogSession::createConnectionPool(m_server->appRoot() + "database.sqlite"); + m_server->addEntryPoint(Wt::EntryPointType::Application, std::bind(&createBlogApplication, std::placeholders::_1, m_blogSqlConnectionPool.get()), + "/blog"); m_server->addEntryPoint(Wt::EntryPointType::WidgetSet, createWidgetSet, "/gui/hello.js"); Session::configureAuth(); m_server->addResource(std::make_shared(), "/json"); diff --git a/WebApplication/WebApplication.h b/WebApplication/WebApplication.h index bcce197..97ca962 100644 --- a/WebApplication/WebApplication.h +++ b/WebApplication/WebApplication.h @@ -6,7 +6,11 @@ namespace Wt { class WServer; -}; + +namespace Dbo { +class SqlConnectionPool; +} +}; // namespace Wt class WebApplication { public: @@ -19,6 +23,7 @@ protected: private: std::unique_ptr m_server; std::thread m_thread; + std::unique_ptr m_blogSqlConnectionPool; }; #endif // __WEBAPPLICATION_H__ \ No newline at end of file diff --git a/WebApplication/model/BlogSession.cpp b/WebApplication/model/BlogSession.cpp index 6803468..54eddc2 100644 --- a/WebApplication/model/BlogSession.cpp +++ b/WebApplication/model/BlogSession.cpp @@ -1,4 +1,9 @@ #include "BlogSession.h" +#include "BoostLog.h" +#include "Post.h" +#include "Token.h" +#include "User.h" +#include "asciidoc.h" #include #include #include @@ -7,6 +12,9 @@ #include #include +const std::string ADMIN_USERNAME = "admin"; +const std::string ADMIN_PASSWORD = "admin"; + class BlogOAuth : public std::vector { public: ~BlogOAuth() { @@ -20,6 +28,46 @@ BlogOAuth blogOAuth; BlogSession::BlogSession(Wt::Dbo::SqlConnectionPool &connectionPool) : m_connectionPool(connectionPool), m_users(*this) { + setConnectionPool(m_connectionPool); + mapClass("comment"); + mapClass("post"); + mapClass("tag"); + mapClass("token"); + mapClass("user"); + + try { + Wt::Dbo::Transaction t(*this); + createTables(); + Wt::Dbo::ptr admin = add(std::make_unique()); + User *a = admin.modify(); + a->name = ADMIN_USERNAME; + a->role = User::Admin; + + Wt::Auth::User authAdmin = m_users.findWithIdentity(Wt::Auth::Identity::LoginName, a->name); + blogPasswords.updatePassword(authAdmin, ADMIN_PASSWORD); + + Wt::Dbo::ptr post = add(std::make_unique()); + Post *p = post.modify(); + + p->state = Post::Published; + p->author = admin; + p->title = "Welcome!"; + p->briefSrc = "Welcome to your own blog."; + p->bodySrc = "We have created for you an " + ADMIN_USERNAME + " user with password " + ADMIN_PASSWORD; + p->briefHtml = asciidoc(p->briefSrc); + p->bodyHtml = asciidoc(p->bodySrc); + p->date = Wt::WDateTime::currentDateTime(); + + Wt::Dbo::ptr rootComment = add(std::make_unique()); + rootComment.modify()->post = post; + + t.commit(); + + LOG(info) << "Created database, and user " << ADMIN_USERNAME << " / " << ADMIN_PASSWORD << std::endl; + } catch (std::exception &e) { + LOG(error) << e.what() << std::endl; + LOG(info) << "Using existing database"; + } } void BlogSession::configureAuth() { diff --git a/WebApplication/model/Post.h b/WebApplication/model/Post.h index 7d9a668..c381718 100644 --- a/WebApplication/model/Post.h +++ b/WebApplication/model/Post.h @@ -22,7 +22,7 @@ public: std::string permaLink() const; std::string commentCount() const; std::string titleToUrl() const; - Wt::Dbo::ptr rootComment() const; + Wt::Dbo::ptr rootComment() const; template void persist(Action &a) {