Public Access
`w` in the Storage App starts a small HTTP server and shows its address, as a QR code and in letters, with a six-digit code. A browser on the same network that has typed the code can list, download, upload, make folders and delete, under the Storage App's rules. The server runs only while that screen is open. Nothing is encrypted, and the screen says so. Uploads are streamed to the card under a temporary name and renamed when whole. Every access to the card is handed to the storage task, 8 KB at a time, from the server's own task. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
57 lines
1.9 KiB
C++
57 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <atomic>
|
|
#include <string>
|
|
|
|
#include "services/file_ops.h"
|
|
#include "services/storage_service.h"
|
|
#include "services/wifi_service.h"
|
|
#include "share_rules.h"
|
|
|
|
namespace roro {
|
|
|
|
// Sharing the SD card with a browser on the same network (issue #88): a small HTTP server with
|
|
// one page and a few requests behind it: list, download, upload, new folder, delete. It runs only
|
|
// between start() and stop(), which the Storage App's "Share" screen calls on opening and
|
|
// closing. Whoever has typed the code that screen shows may use it; nothing is encrypted.
|
|
//
|
|
// The server has its own task. Every access to the card is handed to the storage task, a piece
|
|
// at a time, as everywhere else.
|
|
class WebShare {
|
|
public:
|
|
WebShare(StorageService& storage, FileOps& ops, WifiService& wifi) : storage_(storage), ops_(ops), wifi_(wifi) {}
|
|
|
|
std::string start(); // "" or why it can't
|
|
void stop();
|
|
bool running() const { return server_ != nullptr; }
|
|
std::string url() const; // http://<address>/
|
|
const std::string& code() const { return auth_.code(); }
|
|
|
|
// For the screen.
|
|
uint32_t requests() const { return requests_; }
|
|
uint32_t bytesIn() const { return bytesIn_; }
|
|
uint32_t bytesOut() const { return bytesOut_; }
|
|
std::string last() const; // the last thing asked for
|
|
|
|
// Used by the request handlers (web_share.cpp).
|
|
StorageService& storage() { return storage_; }
|
|
FileOps& ops() { return ops_; }
|
|
files::ShareAuth& auth() { return auth_; }
|
|
void note(const char* what, const std::string& path);
|
|
void counted(uint32_t in, uint32_t out) {
|
|
bytesIn_ += in;
|
|
bytesOut_ += out;
|
|
}
|
|
|
|
private:
|
|
StorageService& storage_;
|
|
FileOps& ops_;
|
|
WifiService& wifi_;
|
|
files::ShareAuth auth_;
|
|
void* server_ = nullptr; // httpd_handle_t
|
|
std::atomic<uint32_t> requests_{0}, bytesIn_{0}, bytesOut_{0};
|
|
char last_[56] = "";
|
|
};
|
|
|
|
} // namespace roro
|