Logo 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
10#include <string>
11
12class FileView : public FrameworkView {
13public:
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 {
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
32private:
33 std::string filePath;
34 std::string mimeType;
35};
Abstract base class for all views in the PicoFramework.
Abstract interface for file and directory storage backends.
static constexpr std::uintptr_t getTypeKey()
Definition AppContext.h:91
std::string filePath
Definition FileView.h:33
FileView(const std::string &path, const std::string &contentType="text/html")
Definition FileView.h:14
std::string render(const std::map< std::string, std::string > &context={}) const override
Render the view body.
Definition FileView.h:17
std::string mimeType
Definition FileView.h:34
std::string getContentType() const override
Return the MIME content type for this view.
Definition FileView.h:28