Pico-Framework
A web-first embedded framework for C++
Loading...
Searching...
No Matches
FileView.h
Go to the documentation of this file.
1
6
#pragma once
7
#include "
framework/FrameworkView.h
"
8
#include "
framework/AppContext.h
"
9
#include "
storage/StorageManager.h
"
10
#include <string>
11
12
class
FileView
:
public
FrameworkView
{
13
public
:
14
explicit
FileView
(
const
std::string& path,
const
std::string& contentType =
"text/html"
)
15
:
filePath
(path),
mimeType
(contentType) {}
16
17
std::string
render
(
const
std::map<std::string, std::string>& context = {})
const
override
{
18
auto
* sm =
AppContext::get<StorageManager>
();
19
if
(!sm)
return
"<h1>Storage unavailable</h1>"
;
20
21
std::string result;
22
if
(!sm->readFileString(
filePath
, 0, UINT32_MAX, result)) {
23
return
"<h1>File not found: "
+
filePath
+
"</h1>"
;
24
}
25
return
result;
26
}
27
28
std::string
getContentType
()
const override
{
29
return
mimeType
;
30
}
31
32
private
:
33
std::string
filePath
;
34
std::string
mimeType
;
35
};
AppContext.h
FrameworkView.h
Abstract base class for all views in the PicoFramework.
StorageManager.h
Abstract interface for file and directory storage backends.
AppContext::getTypeKey
static constexpr std::uintptr_t getTypeKey()
Definition
AppContext.h:91
FileView
Definition
FileView.h:12
FileView::filePath
std::string filePath
Definition
FileView.h:33
FileView::FileView
FileView(const std::string &path, const std::string &contentType="text/html")
Definition
FileView.h:14
FileView::render
std::string render(const std::map< std::string, std::string > &context={}) const override
Render the view body.
Definition
FileView.h:17
FileView::mimeType
std::string mimeType
Definition
FileView.h:34
FileView::getContentType
std::string getContentType() const override
Return the MIME content type for this view.
Definition
FileView.h:28
FrameworkView
Definition
FrameworkView.h:21
framework
FileView.h
Generated by
1.9.8