yum-slop/TaSTT
Free self-hosted STT for VRChat.
git clone https://git.yummers.dev/yum-slop/TaSTT
fa59ca6
master
This is the API design of the webserver supporting the browser source.
I tried oatpp but it had a nasty habit of randomly crashing. I looked at crowCPP but it depends on boost, which I have a personal grudge against. So I'm making Yet Another Web Framework.
This one supports only the minimum feature set required to implement the browser source.
The browser source requires two APIs:
- GET /: return index.html (html)
- GET /api/transcript: return transcript (json)
enum ContentType {
HTTP,
JSON,
};
class WebServer:
public:
WebServer(u16 port)
// method and path are in-params
// payload and type are out-params
typedef handler_t std::function<void(const string method, const string path,
string& payload, ContentType& type);
void RegisterPathHandler(string method, string path, handler_t handler);
Run(volatile bool* run)
We need a way to generate HTML from responses:
class HTTPMapper:
HTTPMapper()
void Map(const string method, const string path, const string payload, const
ContentType type) = 0;
class HTTPMapperHTML : public HTTPMapper:
HTTPMapperHTML()
...
class HTTPMapperJSON : public HTTPMapper:
HTTPMapperJSON()
...
We also need a way to parse client-sent HTML:
class HTTPParser: HTTPParser() bool Parse(const string payload) string GetMethod(); string GetPath(); bool GetHeader(const string header, string value) bool GetPayload()
WebServer hides HTTPMapper. WebServer and HTTPMapper share ContentType.
So we have
WebCommon.h: shared types HTTPParser.h: supporting API for WebServer HTTPMapper.h: supporting API for WebServer WebServer.h: user-visible API
1This is the API design of the webserver supporting the browser source. 2 3I tried oatpp but it had a nasty habit of randomly crashing. I looked at 4crowCPP but it depends on boost, which I have a personal grudge against. 5So I'm making Yet Another Web Framework. 6 7This one supports only the minimum feature set required to implement the 8browser source. 9 10The browser source requires two APIs: 111. GET /: return index.html (html) 122. GET /api/transcript: return transcript (json) 13 14``` 15enum ContentType { 16HTTP, 17JSON, 18}; 19 20class WebServer: 21public: 22WebServer(u16 port) 23 24// method and path are in-params 25// payload and type are out-params 26typedef handler_t std::function<void(const string method, const string path, 27string& payload, ContentType& type); 28 29void RegisterPathHandler(string method, string path, handler_t handler); 30 31Run(volatile bool* run) 32``` 33 34We need a way to generate HTML from responses: 35``` 36class HTTPMapper: 37HTTPMapper() 38 39void Map(const string method, const string path, const string payload, const 40ContentType type) = 0; 41 42class HTTPMapperHTML : public HTTPMapper: 43HTTPMapperHTML() 44 45... 46 47class HTTPMapperJSON : public HTTPMapper: 48HTTPMapperJSON() 49 50... 51``` 52 53We also need a way to parse client-sent HTML: 54``` 55class HTTPParser: 56HTTPParser() 57 58bool Parse(const string payload) 59 60string GetMethod(); 61string GetPath(); 62bool GetHeader(const string header, string value) 63 64bool GetPayload() 65``` 66 67WebServer hides HTTPMapper. 68WebServer and HTTPMapper share ContentType. 69 70So we have 71 72 WebCommon.h: shared types 73 HTTPParser.h: supporting API for WebServer 74 HTTPMapper.h: supporting API for WebServer 75 WebServer.h: user-visible API 76