Use a more meaningful client name for scan reports
This commit is contained in:
@@ -19,9 +19,8 @@
|
|||||||
|
|
||||||
#include "ScannerController.hpp"
|
#include "ScannerController.hpp"
|
||||||
|
|
||||||
#include <iomanip>
|
|
||||||
|
|
||||||
#include <Wt/Http/Response.h>
|
#include <Wt/Http/Response.h>
|
||||||
|
#include <Wt/Utils.h>
|
||||||
#include <Wt/WCheckBox.h>
|
#include <Wt/WCheckBox.h>
|
||||||
#include <Wt/WDateTime.h>
|
#include <Wt/WDateTime.h>
|
||||||
#include <Wt/WLocale.h>
|
#include <Wt/WLocale.h>
|
||||||
@@ -29,6 +28,7 @@
|
|||||||
#include <Wt/WResource.h>
|
#include <Wt/WResource.h>
|
||||||
|
|
||||||
#include "core/Service.hpp"
|
#include "core/Service.hpp"
|
||||||
|
#include "core/String.hpp"
|
||||||
#include "database/Session.hpp"
|
#include "database/Session.hpp"
|
||||||
#include "database/Track.hpp"
|
#include "database/Track.hpp"
|
||||||
#include "services/scanner/IScannerService.hpp"
|
#include "services/scanner/IScannerService.hpp"
|
||||||
@@ -48,15 +48,13 @@ namespace lms::ui
|
|||||||
class ReportResource : public Wt::WResource
|
class ReportResource : public Wt::WResource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ReportResource()
|
ReportResource() = default;
|
||||||
{
|
~ReportResource() override
|
||||||
suggestFileName("report.txt");
|
|
||||||
}
|
|
||||||
|
|
||||||
~ReportResource()
|
|
||||||
{
|
{
|
||||||
beingDeleted();
|
beingDeleted();
|
||||||
}
|
}
|
||||||
|
ReportResource(const ReportResource&) = delete;
|
||||||
|
ReportResource& operator=(const ReportResource&) = delete;
|
||||||
|
|
||||||
void setScanStats(const scanner::ScanStats& stats)
|
void setScanStats(const scanner::ScanStats& stats)
|
||||||
{
|
{
|
||||||
@@ -66,11 +64,19 @@ namespace lms::ui
|
|||||||
*_stats = stats;
|
*_stats = stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleRequest(const Wt::Http::Request&, Wt::Http::Response& response)
|
void handleRequest(const Wt::Http::Request&, Wt::Http::Response& response) override
|
||||||
{
|
{
|
||||||
if (!_stats)
|
if (!_stats)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
auto encodeHttpHeaderField = [](const std::string& fieldName, const std::string& fieldValue) {
|
||||||
|
// This implements RFC 5987
|
||||||
|
return fieldName + "*=UTF-8''" + Wt::Utils::urlEncode(fieldValue);
|
||||||
|
};
|
||||||
|
|
||||||
|
const std::string cdp{ encodeHttpHeaderField("filename", "LMS_scan_report_" + core::stringUtils::toISO8601String(_stats->startTime) + ".txt") };
|
||||||
|
response.addHeader("Content-Disposition", "attachment; " + cdp);
|
||||||
|
|
||||||
response.out() << Wt::WString::tr("Lms.Admin.ScannerController.errors-header").arg(_stats->errors.size()).toUTF8() << std::endl;
|
response.out() << Wt::WString::tr("Lms.Admin.ScannerController.errors-header").arg(_stats->errors.size()).toUTF8() << std::endl;
|
||||||
|
|
||||||
for (const auto& error : _stats->errors)
|
for (const auto& error : _stats->errors)
|
||||||
|
|||||||
Reference in New Issue
Block a user