From 257a10212780bfe12103275f46fcfddb65c2612a Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Fri, 31 Jan 2025 23:38:22 -0500 Subject: [PATCH] fix(api): return proper json objects (#3544) --- .github/workflows/CI.yml | 1 - cmake/compile_definitions/common.cmake | 1 + cmake/compile_definitions/windows.cmake | 1 - cmake/dependencies/common.cmake | 1 + cmake/dependencies/nlohmann_json.cmake | 18 + cmake/dependencies/windows.cmake | 3 - docs/api.md | 38 +- docs/app_examples.md | 9 +- docs/building.md | 1 - docs/configuration.md | 2 +- src/confighttp.cpp | 568 +++++++++--------- src/confighttp.h | 1 - src/nvhttp.cpp | 18 +- src/nvhttp.h | 8 +- src_assets/common/assets/web/apps.html | 4 +- src_assets/common/assets/web/config.html | 16 +- .../tabs/encoders/NvidiaNvencEncoder.vue | 14 +- .../assets/web/public/assets/locale/en.json | 4 +- src_assets/windows/assets/apps.json | 4 +- 19 files changed, 363 insertions(+), 349 deletions(-) create mode 100644 cmake/dependencies/nlohmann_json.cmake diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0a583c061a5..945d2d5387d 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -887,7 +887,6 @@ jobs: mingw-w64-ucrt-x86_64-graphviz mingw-w64-ucrt-x86_64-MinHook mingw-w64-ucrt-x86_64-miniupnpc - mingw-w64-ucrt-x86_64-nlohmann-json mingw-w64-ucrt-x86_64-nodejs mingw-w64-ucrt-x86_64-nsis mingw-w64-ucrt-x86_64-onevpl diff --git a/cmake/compile_definitions/common.cmake b/cmake/compile_definitions/common.cmake index 0c576426eb9..723a1a7a540 100644 --- a/cmake/compile_definitions/common.cmake +++ b/cmake/compile_definitions/common.cmake @@ -149,6 +149,7 @@ list(APPEND SUNSHINE_EXTERNAL_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} enet libdisplaydevice::display_device + nlohmann_json::nlohmann_json opus ${FFMPEG_LIBRARIES} ${Boost_LIBRARIES} diff --git a/cmake/compile_definitions/windows.cmake b/cmake/compile_definitions/windows.cmake index 3ee287e0162..b169dbb5f48 100644 --- a/cmake/compile_definitions/windows.cmake +++ b/cmake/compile_definitions/windows.cmake @@ -76,7 +76,6 @@ list(PREPEND PLATFORM_LIBRARIES libstdc++.a libwinpthread.a minhook::minhook - nlohmann_json::nlohmann_json ntdll setupapi shlwapi diff --git a/cmake/dependencies/common.cmake b/cmake/dependencies/common.cmake index 27da728b631..c92b4777b86 100644 --- a/cmake/dependencies/common.cmake +++ b/cmake/dependencies/common.cmake @@ -16,6 +16,7 @@ add_subdirectory("${CMAKE_SOURCE_DIR}/third-party/Simple-Web-Server") add_subdirectory("${CMAKE_SOURCE_DIR}/third-party/libdisplaydevice") # common dependencies +include("${CMAKE_MODULE_PATH}/dependencies/nlohmann_json.cmake") find_package(OpenSSL REQUIRED) find_package(PkgConfig REQUIRED) find_package(Threads REQUIRED) diff --git a/cmake/dependencies/nlohmann_json.cmake b/cmake/dependencies/nlohmann_json.cmake new file mode 100644 index 00000000000..c0029b42ecc --- /dev/null +++ b/cmake/dependencies/nlohmann_json.cmake @@ -0,0 +1,18 @@ +# +# Loads the nlohmann_json library giving the priority to the system package first, with a fallback to FetchContent. +# +include_guard(GLOBAL) + +find_package(nlohmann_json 3.11 QUIET GLOBAL) +if(NOT nlohmann_json_FOUND) + message(STATUS "nlohmann_json v3.11.x package not found in the system. Falling back to FetchContent.") + include(FetchContent) + + FetchContent_Declare( + json + URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz + URL_HASH MD5=c23a33f04786d85c29fda8d16b5f0efd + DOWNLOAD_EXTRACT_TIMESTAMP + ) + FetchContent_MakeAvailable(json) +endif() diff --git a/cmake/dependencies/windows.cmake b/cmake/dependencies/windows.cmake index 11a40ecf481..3faad7dfd41 100644 --- a/cmake/dependencies/windows.cmake +++ b/cmake/dependencies/windows.cmake @@ -1,8 +1,5 @@ # windows specific dependencies -# nlohmann_json -find_package(nlohmann_json CONFIG 3.11 REQUIRED) - # Make sure MinHook is installed find_library(MINHOOK_LIBRARY libMinHook.a REQUIRED) find_path(MINHOOK_INCLUDE_DIR MinHook.h PATH_SUFFIXES include REQUIRED) diff --git a/docs/api.md b/docs/api.md index e93f500c061..5313d5988f6 100644 --- a/docs/api.md +++ b/docs/api.md @@ -12,17 +12,23 @@ basic authentication with the admin username and password. ## GET /api/apps @copydoc confighttp::getApps() -## GET /api/logs -@copydoc confighttp::getLogs() - ## POST /api/apps @copydoc confighttp::saveApp() +## POST /api/apps/close +@copydoc confighttp::closeApp() + ## DELETE /api/apps/{index} @copydoc confighttp::deleteApp() -## POST /api/covers/upload -@copydoc confighttp::uploadCover() +## GET /api/clients/list +@copydoc confighttp::getClients() + +## POST /api/clients/unpair +@copydoc confighttp::unpair() + +## POST /api/clients/unpair-all +@copydoc confighttp::unpairAll() ## GET /api/config @copydoc confighttp::getConfig() @@ -33,11 +39,11 @@ basic authentication with the admin username and password. ## POST /api/config @copydoc confighttp::saveConfig() -## POST /api/restart -@copydoc confighttp::restart() +## POST /api/covers/upload +@copydoc confighttp::uploadCover() -## POST /api/reset-display-device-persistence -@copydoc confighttp::resetDisplayDevicePersistence() +## GET /api/logs +@copydoc confighttp::getLogs() ## POST /api/password @copydoc confighttp::savePassword() @@ -45,17 +51,11 @@ basic authentication with the admin username and password. ## POST /api/pin @copydoc confighttp::savePin() -## POST /api/clients/unpair-all -@copydoc confighttp::unpairAll() - -## POST /api/clients/unpair -@copydoc confighttp::unpair() - -## GET /api/clients/list -@copydoc confighttp::listClients() +## POST /api/reset-display-device-persistence +@copydoc confighttp::resetDisplayDevicePersistence() -## POST /api/apps/close -@copydoc confighttp::closeApp() +## POST /api/restart +@copydoc confighttp::restart()