|
Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
|
Serves static assets from the artifact directory for in-process dynamic-app request handling, and provides media mutation helpers for upload, delete, and path-resolution operations. More...
#include "native_dynamic_media.h"#include "native_dynamic_multipart.h"#include "native_fs.h"#include "native_http_log.h"#include "native_http_response.h"#include "native_support.h"#include "native_yyjson_helpers.h"#include <ctype.h>#include <stdio.h>#include <stdlib.h>#include <string.h>Go to the source code of this file.
Functions | |
| int | native_dynamic_media_is_static_path (const char *path) |
| Determines whether a request path targets a known static asset. | |
| char * | native_dynamic_media_resolve_path (const char *artifact_dir, const char *path) |
| Resolves a request path to a file-system path inside the artifact directory. | |
| int | native_dynamic_media_serve_asset (NativeConnection *connection, const char *artifact_dir, const char *path, const HttpRequest *request) |
| Serves a static asset from the artifact directory. | |
| char * | safe_upload_filename_dup (const char *raw_name) |
| Sanitises a raw upload filename into a safe filesystem name. | |
| char * | media_disk_path_dup (const char *artifact_dir, const char *media_url) |
| Resolves a media URL into an on-disk path inside an app artifact directory. | |
| int | ensure_media_subtree (const char *artifact_dir, const char *entity_type, const char *entity_slug) |
| Ensures a managed media subtree exists for an entity type by reading the media policy fixture at {artifact_dir}/data/framework/media-policy-v1.json. | |
| int | ensure_business_media_tree (const char *artifact_dir, const char *business_slug) |
| Ensures the managed business media subtree exists under an app artifact. | |
| int | remove_media_url_file (const char *artifact_dir, const char *media_url) |
| Removes a managed business media file from an app artifact when it exists. | |
| char * | store_uploaded_media (const char *artifact_dir, const char *content_type, const char *body_path, const char *field_name, const char *target_url_dir, const char *fallback_filename) |
| Extracts a multipart upload into the app artifact media tree and returns the resulting media URL. | |
Variables | |
| static const char * | WELL_KNOWN_JSON_PATHS [] |
| Well-known JSON endpoints served from the artifact directory. | |
| static const char * | WELL_KNOWN_HTML_FALLBACKS [] |
| Well-known HTML fallback routes that resolve to index.html. | |
Serves static assets from the artifact directory for in-process dynamic-app request handling, and provides media mutation helpers for upload, delete, and path-resolution operations.
Definition in file native_dynamic_media.c.
| int ensure_business_media_tree | ( | const char * | artifact_dir, |
| const char * | business_slug ) |
Ensures the managed business media subtree exists under an app artifact.
Creates the directory structure for a business's media by delegating to ensure_media_subtree() with the "business" entity type, reading the directory layout from the media policy fixture.
| artifact_dir | App artifact root directory. |
| business_slug | Business slug identifying the subtree. |
Definition at line 484 of file native_dynamic_media.c.
References ensure_media_subtree().
Referenced by handle_action_route(), and handle_dynamic_ensure_business_media_tree_command().
| int ensure_media_subtree | ( | const char * | artifact_dir, |
| const char * | entity_type, | ||
| const char * | entity_slug ) |
Ensures a managed media subtree exists for an entity type by reading the media policy fixture at {artifact_dir}/data/framework/media-policy-v1.json.
Loads the fixture, finds the entry matching entity_type, substitutes entity_slug into the base_path_template, and creates the base directory and all declared subdirectories.
| artifact_dir | App artifact root directory. |
| entity_type | Entity type key to look up in the fixture (e.g. "business"). |
| entity_slug | Entity slug to substitute into the path template. |
Definition at line 320 of file native_dynamic_media.c.
References ensure_directory(), native_json_doc_free(), native_json_doc_load_file(), native_json_obj_get(), native_json_obj_get_array(), native_json_obj_get_string_dup(), path_join(), streq(), yyjson_arr_get(), yyjson_arr_size(), yyjson_doc_get_root(), yyjson_get_str(), yyjson_is_obj(), and yyjson_is_str().
Referenced by ensure_business_media_tree().
| char * media_disk_path_dup | ( | const char * | artifact_dir, |
| const char * | media_url ) |
Resolves a media URL into an on-disk path inside an app artifact directory.
| artifact_dir | Artifact directory that owns the media tree. |
| media_url | Media URL beginning with /media/. |
Definition at line 313 of file native_dynamic_media.c.
References path_join(), and starts_with().
Referenced by handle_dynamic_media_disk_path_command(), and remove_media_url_file().
| int native_dynamic_media_is_static_path | ( | const char * | path | ) |
Determines whether a request path targets a known static asset.
Paths beginning with /static/, /media/, or matching a well-known JSON endpoint (e.g. /manifest.json) are considered static assets that can be served directly from the artifact directory.
| path | Normalised request path (query string stripped). |
Definition at line 69 of file native_dynamic_media.c.
References starts_with(), streq(), and WELL_KNOWN_JSON_PATHS.
Referenced by native_dynamic_runtime_handle_request().
| char * native_dynamic_media_resolve_path | ( | const char * | artifact_dir, |
| const char * | path ) |
Resolves a request path to a file-system path inside the artifact directory.
Returns NULL when the path does not map to a valid asset file.
| artifact_dir | App artifact root directory. |
| path | Normalised request path. |
Definition at line 91 of file native_dynamic_media.c.
References path_join(), starts_with(), and streq().
Referenced by native_dynamic_media_serve_asset().
| int native_dynamic_media_serve_asset | ( | NativeConnection * | connection, |
| const char * | artifact_dir, | ||
| const char * | path, | ||
| const HttpRequest * | request ) |
Serves a static asset from the artifact directory.
Resolves the file path, determines the content type, and writes the full HTTP response to connection.
| connection | Connection to write the response to. |
| artifact_dir | App artifact root directory. |
| path | Normalised request path. |
| request | Parsed request (used for conditional GET). |
Definition at line 142 of file native_dynamic_media.c.
References mime_type_for_path(), native_connection_printf(), native_connection_write(), native_dynamic_media_resolve_path(), native_send_text_response(), path_exists(), path_is_directory(), path_join(), starts_with(), and streq().
Referenced by handle_page_route(), and native_dynamic_runtime_handle_request().
| int remove_media_url_file | ( | const char * | artifact_dir, |
| const char * | media_url ) |
Removes a managed business media file from an app artifact when it exists.
Only removes files whose URL begins with /media/businesses/. Silently succeeds when the file does not exist or the URL is not a recognised business media path.
| artifact_dir | App artifact root directory. |
| media_url | Media URL of the file to remove. |
Definition at line 488 of file native_dynamic_media.c.
References media_disk_path_dup(), path_exists(), and starts_with().
Referenced by handle_action_route(), and handle_dynamic_remove_media_url_file_command().
| char * safe_upload_filename_dup | ( | const char * | raw_name | ) |
Sanitises a raw upload filename into a safe filesystem name.
Strips directory components, replaces unsafe characters with _, and removes leading/trailing dots, dashes, and underscores.
| raw_name | Raw filename from the upload (may be NULL). |
Definition at line 266 of file native_dynamic_media.c.
Referenced by handle_dynamic_safe_upload_filename_command(), and store_uploaded_media().
| char * store_uploaded_media | ( | const char * | artifact_dir, |
| const char * | content_type, | ||
| const char * | body_path, | ||
| const char * | field_name, | ||
| const char * | target_url_dir, | ||
| const char * | fallback_filename ) |
Extracts a multipart upload into the app artifact media tree and returns the resulting media URL.
Reads the request body from body_path, locates the multipart part for field_name, sanitises the filename, writes the file to target_url_dir inside artifact_dir, and returns the public media URL.
| artifact_dir | App artifact root directory. |
| content_type | Full Content-Type header of the request. |
| body_path | Path to the request body file on disk. |
| field_name | Form field name of the file input. |
| target_url_dir | Target URL directory under /media/ (e.g. /media/businesses/lotus-studio). |
| fallback_filename | Fallback filename when the upload provides none. |
Definition at line 501 of file native_dynamic_media.c.
References ensure_directory(), native_dynamic_multipart_find_part(), path_join(), read_file_bytes_dup_runtime(), safe_upload_filename_dup(), and write_binary_file_runtime().
Referenced by handle_action_route(), and handle_dynamic_store_uploaded_media_command().
|
static |
Well-known HTML fallback routes that resolve to index.html.
Definition at line 64 of file native_dynamic_media.c.
|
static |
Well-known JSON endpoints served from the artifact directory.
Definition at line 25 of file native_dynamic_media.c.
Referenced by native_dynamic_media_is_static_path().