Introduced new transcoding service
This commit is contained in:
@@ -12,6 +12,7 @@ add_library(lmscore STATIC
|
||||
impl/FileResourceHandler.cpp
|
||||
impl/IOContextRunner.cpp
|
||||
impl/Logger.cpp
|
||||
impl/MimeTypes.cpp
|
||||
impl/NetAddress.cpp
|
||||
impl/PartialDateTime.cpp
|
||||
impl/Path.cpp
|
||||
|
||||
@@ -22,12 +22,13 @@
|
||||
#include <fstream>
|
||||
|
||||
#include "core/ILogger.hpp"
|
||||
#include "core/MimeTypes.hpp"
|
||||
|
||||
namespace lms
|
||||
namespace lms::core
|
||||
{
|
||||
std::unique_ptr<IResourceHandler> createFileResourceHandler(const std::filesystem::path& path, std::string_view mimeType)
|
||||
{
|
||||
return std::make_unique<FileResourceHandler>(path, mimeType);
|
||||
return std::make_unique<FileResourceHandler>(path, mimeType.empty() ? getMimeType(path.extension()) : mimeType);
|
||||
}
|
||||
|
||||
FileResourceHandler::FileResourceHandler(const std::filesystem::path& path, std::string_view mimeType)
|
||||
@@ -134,4 +135,4 @@ namespace lms
|
||||
LMS_LOG(UTILS, DEBUG, "Job complete!");
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace lms
|
||||
} // namespace lms::core
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "core/IResourceHandler.hpp"
|
||||
|
||||
namespace lms
|
||||
namespace lms::core
|
||||
{
|
||||
class FileResourceHandler final : public IResourceHandler
|
||||
{
|
||||
@@ -43,4 +43,4 @@ namespace lms
|
||||
::uint64_t _beyondLastByte{};
|
||||
::uint64_t _offset{};
|
||||
};
|
||||
} // namespace lms
|
||||
} // namespace lms::core
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2025 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "core/MimeTypes.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "core/String.hpp"
|
||||
|
||||
namespace lms::core
|
||||
{
|
||||
std::string_view getMimeType(const std::filesystem::path& fileExtension)
|
||||
{
|
||||
static const std::unordered_map<std::string, std::string_view> entries{
|
||||
// audio
|
||||
{ ".aac", "audio/aac" },
|
||||
{ ".ac3", "audio/ac3" },
|
||||
{ ".aif", "audio/x-aiff" },
|
||||
{ ".aiff", "audio/x-aiff" },
|
||||
{ ".alac", "audio/mp4" },
|
||||
{ ".ape", "audio/x-monkeys-audio" },
|
||||
{ ".dff", "audio/x-dsd-dff" },
|
||||
{ ".dsdiff", "audio/x-dsd-diff" },
|
||||
{ ".dsf", "audio/x-dsd" },
|
||||
{ ".dsf", "audio/x-dsd-dsf" },
|
||||
{ ".dts", "audio/vnd.dts" },
|
||||
{ ".dtshd", "audio/vnd.dts.hd" },
|
||||
{ ".eac3", "audio/eac3" },
|
||||
{ ".flac", "audio/flac" },
|
||||
{ ".m3u", "audio/x-mpegurl" },
|
||||
{ ".m4a", "audio/mp4" },
|
||||
{ ".m4b", "audio/mp4" },
|
||||
{ ".mka", "audio/x-matroska" },
|
||||
{ ".mka", "audio/x-matroska" },
|
||||
{ ".mp3", "audio/mpeg" },
|
||||
{ ".mpc", "audio/x-musepack" },
|
||||
{ ".oga", "audio/ogg" },
|
||||
{ ".ogg", "audio/ogg" },
|
||||
{ ".opus", "audio/opus" },
|
||||
{ ".pls", "audio/x-scpls" },
|
||||
{ ".shn", "audio/x-shn" },
|
||||
{ ".wav", "audio/x-wav" },
|
||||
{ ".webm", "audio/webm" },
|
||||
{ ".wma", "audio/x-ms-wma" },
|
||||
{ ".wv", "audio/x-wavpack" },
|
||||
{ ".wvp", "audio/x-wavpack" },
|
||||
|
||||
// image
|
||||
{ ".bmp", "image/bmp" },
|
||||
{ ".gif", "image/gif" },
|
||||
{ ".jpg", "image/jpeg" },
|
||||
{ ".jpeg", "image/jpeg" },
|
||||
{ ".png", "image/png" },
|
||||
{ ".webp", "image/webp" },
|
||||
};
|
||||
|
||||
auto it{ entries.find(core::stringUtils::stringToLower(fileExtension.c_str())) };
|
||||
if (it == std::cend(entries))
|
||||
return "application/octet-stream";
|
||||
|
||||
return it->second;
|
||||
}
|
||||
} // namespace lms::core
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "core/IResourceHandler.hpp"
|
||||
|
||||
namespace lms
|
||||
namespace lms::core
|
||||
{
|
||||
std::unique_ptr<IResourceHandler> createFileResourceHandler(const std::filesystem::path& path, std::string_view mimeType);
|
||||
std::unique_ptr<IResourceHandler> createFileResourceHandler(const std::filesystem::path& path, std::string_view mimeType = "");
|
||||
}
|
||||
@@ -22,8 +22,7 @@
|
||||
#include <Wt/Http/Request.h>
|
||||
#include <Wt/Http/Response.h>
|
||||
|
||||
// TODO, move elsewhere
|
||||
namespace lms
|
||||
namespace lms::core
|
||||
{
|
||||
// Helper class to serve a resource (must be saved as continuation data if not complete)
|
||||
class IResourceHandler
|
||||
@@ -34,4 +33,4 @@ namespace lms
|
||||
[[nodiscard]] virtual Wt::Http::ResponseContinuation* processRequest(const Wt::Http::Request& request, Wt::Http::Response& response) = 0;
|
||||
virtual void abort() = 0;
|
||||
};
|
||||
} // namespace lms
|
||||
} // namespace lms::core
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2025 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <string_view>
|
||||
|
||||
namespace lms::core
|
||||
{
|
||||
std::string_view getMimeType(const std::filesystem::path& fileExtension);
|
||||
}
|
||||
Reference in New Issue
Block a user