Added uploads service stub

This commit is contained in:
Andrew Lalis 2023-03-29 17:29:19 +02:00
parent 4d396819c4
commit 7a31ab5028
6 changed files with 106 additions and 0 deletions

16
gymboard-uploads/.gitignore vendored Normal file
View File

@ -0,0 +1,16 @@
.dub
docs.json
__dummy.html
docs/
/gymboard-uploads
gymboard-uploads.so
gymboard-uploads.dylib
gymboard-uploads.dll
gymboard-uploads.a
gymboard-uploads.lib
gymboard-uploads-test-*
*.exe
*.pdb
*.o
*.obj
*.lst

View File

@ -0,0 +1,20 @@
# Gymboard Uploads
A service for handling large file uploads and processing. This service manages user-submitted video files, processing of the video files, and rapidly serving the raw file content.
## Upload Logical Flow
When a user is creating a new Gymboard submission, they need to upload their video, which must be processed to compress and prepare it for web usage. The following series of steps describe how this is done.
1. User uploads raw video to **gymboard-uploads**, receives an `upload-id`.
2. User posts the submission, including the `upload-id`, to **gymboard-api**.
3. **gymboard-api** validates the submission, then sends a request to **gymboard-uploads** to start processing the video identified by `upload-id`, and marks the submission as _processing_.
4. **gymboard-uploads** processes the video, and upon completion, sends a request to **gymboard-api** indicating that the processed video is available at `video-url`.
5. **gymboard-api** updates the user's submission to include the `video-url`, and marks the submission as no longer _processing_.
Therefore, **gymboard-uploads** is responsible for the following actions:
- Receiving raw video uploads from users and storing them temporarily until **gymboard-api** requests that we start processing, or they'll be discarded.
- Processing of raw videos to reduce file size and optimize for web. This will most likely be done using FFMPEG in the backend.
- Reporting the status of video processing for recently uploaded videos.
- Serving processed video files.

13
gymboard-uploads/dub.json Normal file
View File

@ -0,0 +1,13 @@
{
"authors": [
"Andrew Lalis"
],
"copyright": "Copyright © 2023, Andrew Lalis",
"dependencies": {
"handy-httpd": "~>5.7.0",
"slf4d": "~>2.1.1"
},
"description": "Service for handling Gymboard file uploads.",
"license": "proprietary",
"name": "gymboard-uploads"
}

View File

@ -0,0 +1,8 @@
{
"fileVersion": 1,
"versions": {
"handy-httpd": "5.7.0",
"httparsed": "1.2.1",
"slf4d": "2.1.1"
}
}

View File

@ -0,0 +1,24 @@
import std.stdio;
import handy_httpd;
import handy_httpd.handlers.path_delegating_handler;
import handlers;
void main() {
PathDelegatingHandler pathHandler = new PathDelegatingHandler();
pathHandler.addMapping("GET", "/status", (ref HttpRequestContext ctx) {
ctx.response.writeBodyString("online");
});
pathHandler.addMapping("POST", "/uploads", new VideoUploadHandler());
HttpServer server = new HttpServer(pathHandler, getServerConfig());
server.start();
}
private ServerConfig getServerConfig() {
ServerConfig serverConfig = ServerConfig.defaultValues();
serverConfig.port = 8085;
serverConfig.workerPoolSize = 10;
serverConfig.reuseAddress = true;
return serverConfig;
}

View File

@ -0,0 +1,25 @@
module handlers;
import handy_httpd;
import std.conv : to;
const ulong MAX_UPLOAD_SIZE = 1024 * 1024 * 1024;
class VideoUploadHandler : HttpRequestHandler {
public void handle(ref HttpRequestContext ctx) {
if ("Content-Length" !in ctx.request.headers) {
ctx.response.status = 411;
ctx.response.statusText = "Length Required";
return;
}
ulong contentLength = ctx.request.headers["Content-Length"].to!ulong;
if (contentLength == 0 || contentLength > MAX_UPLOAD_SIZE) {
ctx.response.status = 413;
ctx.response.statusText = "Payload Too Large";
return;
}
// TODO: Implement this!
}
}