changeset 228:62f9cb40d10d

[Merge] Merging conflicts
author MrJuneJune <me@mrjunejune.com>
date Sun, 02 Aug 2026 16:44:06 -0700
parents 8bb0ac8f4587 (current diff) e82b80b24012 (diff)
children 7795e3149540
files MODULE.bazel.lock
diffstat 4 files changed, 49 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/.bazelrc	Sun Aug 02 16:31:44 2026 -0700
+++ b/.bazelrc	Sun Aug 02 16:44:06 2026 -0700
@@ -2,7 +2,8 @@
 common --enable_platform_specific_config
 
 # Suppress duplicate library warnings from openssl BCR module on macOS
-build:macos --linkopt=-Wl,-no_warn_duplicate_libraries
+# Use host_linkopt to avoid passing this to cross-compilation targets (e.g., WASM)
+build:macos --host_linkopt=-Wl,-no_warn_duplicate_libraries
 
 # esmdk
 build --incompatible_enable_cc_toolchain_resolution
--- a/load_test/README.md	Sun Aug 02 16:31:44 2026 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-# load_test
-
-Load testing and performance measurement scripts.
-
-## Files
-
-- `main.py` - Python load testing script
--- a/load_test/main.py	Sun Aug 02 16:31:44 2026 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-from locust import HttpUser, task, between
-
-class WebsiteUser(HttpUser):
-    wait_time = between(1, 5)
-
-    @task(3)
-    def index_page(self):
-        self.client.get("/")
--- a/mrjunejune/main.c	Sun Aug 02 16:31:44 2026 -0700
+++ b/mrjunejune/main.c	Sun Aug 02 16:44:06 2026 -0700
@@ -25,6 +25,11 @@
   S3_Config s3_config;
 } Media_Processing_Context;
 
+typedef struct {
+  char *input_path;
+  char *output_path;
+} File_Converter_Config;
+
 // Server configuration (loaded from .config)
 static char g_upload_auth_token[256] = {0};
 static char g_s3_region[64] = "us-west-2";
@@ -290,6 +295,27 @@
   return resp;
 }
 
+// Background thread function for media processing
+void *Simple_WebpConverter_Background(void *arg)
+{
+  File_Converter_Config *configuration = (File_Converter_Config *)arg;
+
+  char cmd[1024];
+  snprintf(cmd, sizeof(cmd), "ffmpeg -y -i %s -quality 80 %s 2>/tmp/error_log",
+           configuration->input_path, configuration->output_path);
+  Seobeo_Log(SEOBEO_INFO, "[MEDIA] Running FFmpeg: %s\n", cmd);
+  int ffmpeg_result = system(cmd);
+
+  Seobeo_Log(SEOBEO_INFO, "[MEDIA] FFmpeg result: %d\n", ffmpeg_result);
+  if (ffmpeg_result != 0)
+  {
+    Seobeo_Log(SEOBEO_ERROR, "[MEDIA] ERROR: FFmpeg conversion failed\n");
+    return NULL;
+  }
+  Seobeo_Log(SEOBEO_INFO, "[MEDIA] Successfully converted to webp: %s\n");
+  return NULL;
+}
+
 Seobeo_Request_Entry *ConvertImageToWebP(Seobeo_Request_Entry *req, Dowa_Arena *arena)
 {
   Seobeo_Request_Entry *resp = NULL;
@@ -338,7 +364,7 @@
   const char *content_length_str = ((Seobeo_Request_Entry*)cl_kv)->value;
   size_t file_size = atoi(content_length_str);
 
-  printf("DEBUG: Converting image, file_size=%zu bytes\n", file_size);
+  Seobeo_Log(SEOBEO_DEBUG, "Converting image, file_size=%zu bytes\n", file_size);
 
   int open_flags = O_RDWR | O_CREAT | O_EXCL;
 
@@ -365,15 +391,15 @@
   Dowa_String_UUID(seed, uuid4);
   char *output_path = (char *)Dowa_Arena_Allocate(arena, TMP_FILE_LENGTH);;
   snprintf(output_path, TMP_FILE_LENGTH, "/tmp/%s.webp", uuid4);
-  printf("[DEBUG] output_path %s\n", output_path);
-  printf("[DEBUG] open_flags: 0x%x\n", open_flags);
-  printf("[DEBUG] input_path: %s\n", input_path);
+  Seobeo_Log(SEOBEO_DEBUG, "output_path %s\n", output_path);
+  Seobeo_Log(SEOBEO_DEBUG, "open_flags: 0x%x\n", open_flags);
+  Seobeo_Log(SEOBEO_DEBUG, "input_path: %s\n", input_path);
   int output_fd = open(output_path, open_flags, 0600);
-  printf("[DEBUG] output_fd: %d\n", output_fd);
+  Seobeo_Log(SEOBEO_DEBUG, "output_fd: %d\n", output_fd);
   if (output_fd == -1)
   {
     unlink(input_path);
-    printf("[DEBUG] errno: %d (%s)\n", errno, strerror(errno));
+    Seobeo_Log(SEOBEO_DEBUG, "errno: %d (%s)\n", errno, strerror(errno));
     char *error_msg = "Failed to create output file";
     Dowa_HashMap_Push_Arena(resp, "status", "500", arena);
     Dowa_HashMap_Push_Arena(resp, "content-type", "text/plain", arena);
@@ -382,11 +408,14 @@
   }
   close(output_fd);
 
-  char cmd[1024];
-  snprintf(cmd, sizeof(cmd), "ffmpeg -y -i %s -quality 80 %s 2>/tmp/error_log",
-           input_path, output_path);
-  int result = system(cmd);
-  if (result != 0)
+  File_Converter_Config *configuration = Dowa_Arena_Allocate(arena, sizeof(File_Converter_Config));
+  configuration->input_path = input_path;
+  configuration->output_path = output_path;
+
+  pthread_t thread_id;
+  int thread_result = pthread_create(&thread_id, NULL, Simple_WebpConverter_Background, (void *)configuration);
+
+  if (thread_result != 0)
   {
     unlink(input_path);
     unlink(output_path);
@@ -396,6 +425,12 @@
     Dowa_HashMap_Push_Arena(resp, "body", error_msg, arena);
     return resp;
   }
+  else
+  {
+    // Detach thread so it cleans up automatically when done
+    pthread_detach(thread_id);
+    Seobeo_Log(SEOBEO_INFO, "[MEDIA] Successfully spawned and detached thread\n");
+  }
 
   size_t converted_size = 0;
   FILE *out_file = fopen(output_path, "rb");
@@ -412,7 +447,6 @@
   fclose(out_file);
 
   unlink(input_path);
-
   char *filename = strrchr(output_path, '/') + 1;
   char *response_body = Dowa_Arena_Allocate(arena, 512);
   snprintf(response_body, 512,
@@ -422,7 +456,7 @@
   Dowa_HashMap_Push_Arena(resp, "content-type", "application/json", arena);
   Dowa_HashMap_Push_Arena(resp, "body", response_body, arena);
 
-  printf("DEBUG: Image converted, available at /api/download/%s\n", filename);
+  Seobeo_Log(SEOBEO_DEBUG, "Image converted, available at /api/download/%s\n", filename);
 
   return resp;
 }