Mercurial
comparison mrjunejune/main.c @ 100:65e5a5b89a4e
[Seobeo] Migrated everything to this page.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Sat, 03 Jan 2026 07:48:07 -0800 |
| parents | 70401cf61e97 |
| children | dbf14f84d51c |
comparison
equal
deleted
inserted
replaced
| 99:684edfaf93b7 | 100:65e5a5b89a4e |
|---|---|
| 17 void Seobeo_ServerSideRender( | 17 void Seobeo_ServerSideRender( |
| 18 char *final_body, | 18 char *final_body, |
| 19 char *path, | 19 char *path, |
| 20 Dowa_Arena *arena | 20 Dowa_Arena *arena |
| 21 ) { | 21 ) { |
| 22 Seobeo_Log(SEOBEO_DEBUG, "[Curr] %s\n", path); | |
| 22 size_t html_size = 0; | 23 size_t html_size = 0; |
| 23 char *template = Seobeo_Web_LoadFile(path, &html_size); | 24 char *template = Seobeo_Web_LoadFile(path, &html_size); |
| 24 if (!template) return; | 25 if (!template) return; |
| 26 Seobeo_Log(SEOBEO_DEBUG, "[Curr] ??\n"); | |
| 25 | 27 |
| 26 size_t current_offset = 0; | 28 size_t current_offset = 0; |
| 27 char *cursor = template; | 29 char *cursor = template; |
| 28 | 30 |
| 29 int32 token_len = 2; | 31 int32 token_len = 2; |
| 45 memcpy(include_name, start_tag + token_len, name_len); | 47 memcpy(include_name, start_tag + token_len, name_len); |
| 46 include_name[name_len] = '\0'; | 48 include_name[name_len] = '\0'; |
| 47 | 49 |
| 48 size_t sub_file_size = 0; | 50 size_t sub_file_size = 0; |
| 49 char *sub_content = Seobeo_Web_LoadFile(include_name, &sub_file_size); | 51 char *sub_content = Seobeo_Web_LoadFile(include_name, &sub_file_size); |
| 52 Seobeo_Log(SEOBEO_DEBUG, "[Curr] Sub content: %s\n", sub_content); | |
| 50 if (sub_content) | 53 if (sub_content) |
| 51 { | 54 { |
| 52 memcpy(final_body + current_offset, sub_content, sub_file_size); | 55 memcpy(final_body + current_offset, sub_content, sub_file_size); |
| 53 current_offset += sub_file_size; | 56 current_offset += sub_file_size; |
| 54 free(sub_content); | 57 free(sub_content); |
| 433 Dowa_HashMap_Push_Arena(resp, "body", body, arena); | 436 Dowa_HashMap_Push_Arena(resp, "body", body, arena); |
| 434 | 437 |
| 435 return resp; | 438 return resp; |
| 436 } | 439 } |
| 437 | 440 |
| 441 Seobeo_Request_Entry *RenderBlogList(Seobeo_Request_Entry *req, Dowa_Arena *arena) | |
| 442 { | |
| 443 Seobeo_Request_Entry *resp = NULL; | |
| 444 char *final_body = Dowa_Arena_Allocate(arena, 50 * 1024); | |
| 445 Seobeo_ServerSideRender(final_body, "/blog/index.html", arena); | |
| 446 Dowa_HashMap_Push_Arena(resp, "body", final_body, arena); | |
| 447 return resp; | |
| 448 } | |
| 449 | |
| 450 | |
| 451 Seobeo_Request_Entry *RenderBlog(Seobeo_Request_Entry *req, Dowa_Arena *arena) | |
| 452 { | |
| 453 Seobeo_Log(SEOBEO_DEBUG, "[CURR], Hello\n"); | |
| 454 Seobeo_Request_Entry *resp = NULL; | |
| 455 | |
| 456 void *blog_id_kv = Dowa_HashMap_Get_Ptr(req, ":blog_id"); | |
| 457 if (!blog_id_kv) | |
| 458 { | |
| 459 char *error_msg = "No Blog Id"; | |
| 460 Dowa_HashMap_Push_Arena(resp, "status", "404", arena); | |
| 461 Dowa_HashMap_Push_Arena(resp, "content-type", "text/plain", arena); | |
| 462 Dowa_HashMap_Push_Arena(resp, "body", error_msg, arena); | |
| 463 return resp; | |
| 464 } | |
| 465 | |
| 466 const char *blog_id = ((Seobeo_Request_Entry *)blog_id_kv)->value; | |
| 467 char *html_path = Dowa_Arena_Allocate(arena, 512); | |
| 468 sprintf(html_path, "/blog/%s/index.html", blog_id); | |
| 469 | |
| 470 char *final_body = Dowa_Arena_Allocate(arena, 100 * 1024); // TODO: Think about the sizes | |
| 471 Seobeo_ServerSideRender(final_body, html_path, arena); | |
| 472 Dowa_HashMap_Push_Arena(resp, "body", final_body, arena); | |
| 473 return resp; | |
| 474 } | |
| 475 | |
| 476 | |
| 438 CREATE_REDIRECT_HANDLER(HomePage, "/") | 477 CREATE_REDIRECT_HANDLER(HomePage, "/") |
| 439 CREATE_REDIRECT_HANDLER(Resume, "/resume") | 478 CREATE_REDIRECT_HANDLER(Resume, "/resume") |
| 440 CREATE_REDIRECT_HANDLER(Tools, "/tools") | 479 CREATE_REDIRECT_HANDLER(Tools, "/tools") |
| 441 CREATE_REDIRECT_HANDLER(MarkDownToHtml, "/tools/markdown_to_html") | 480 CREATE_REDIRECT_HANDLER(MarkDownToHtml, "/tools/markdown_to_html") |
| 442 CREATE_REDIRECT_HANDLER(FileConverter, "/tools/file_converter") | 481 CREATE_REDIRECT_HANDLER(FileConverter, "/tools/file_converter") |
| 457 Seobeo_Router_Register("GET", "/tools/markdown_to_html/index.html", GetRedirectMarkDownToHtml); | 496 Seobeo_Router_Register("GET", "/tools/markdown_to_html/index.html", GetRedirectMarkDownToHtml); |
| 458 | 497 |
| 459 Seobeo_Router_Register("GET", "/tools/file_converter", GetFileConverter); | 498 Seobeo_Router_Register("GET", "/tools/file_converter", GetFileConverter); |
| 460 Seobeo_Router_Register("GET", "/tools/file_converter/index.html", GetRedirectFileConverter); | 499 Seobeo_Router_Register("GET", "/tools/file_converter/index.html", GetRedirectFileConverter); |
| 461 | 500 |
| 501 // -- File converter --/ | |
| 462 Seobeo_Router_Register("POST", "/api/convert/image-to-webp", ConvertImageToWebP); | 502 Seobeo_Router_Register("POST", "/api/convert/image-to-webp", ConvertImageToWebP); |
| 463 Seobeo_Router_Register("POST", "/api/convert/video-to-mp4", ConvertVideoToMP4); | 503 Seobeo_Router_Register("POST", "/api/convert/video-to-mp4", ConvertVideoToMP4); |
| 464 Seobeo_Router_Register("GET", "/api/download/:filename", DownloadConvertedFile); | 504 Seobeo_Router_Register("GET", "/api/download/:filename", DownloadConvertedFile); |
| 465 | 505 |
| 506 // -- Blog --/ | |
| 507 Seobeo_Router_Register("GET", "/blog", RenderBlogList); | |
| 508 Seobeo_Router_Register("GET", "/blog/:blog_id", RenderBlog); | |
| 509 | |
| 466 Seobeo_Web_Server_Start("mrjunejune/src", "6969", SEOBEO_MODE_EDGE, 3); | 510 Seobeo_Web_Server_Start("mrjunejune/src", "6969", SEOBEO_MODE_EDGE, 3); |
| 467 } | 511 } |