diff options
author | Freya Murphy <freya@freyacat.org> | 2025-08-29 17:15:20 +0000 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-08-29 17:15:20 +0000 |
commit | 1bc5733741f84bef8cf0e35e54f069420670c20d (patch) | |
tree | 4657717890d63fcf692c103d421de9921d3c197d | |
parent | update VERSION (diff) | |
download | cgit-1bc5733741f84bef8cf0e35e54f069420670c20d.tar.gz cgit-1bc5733741f84bef8cf0e35e54f069420670c20d.tar.bz2 cgit-1bc5733741f84bef8cf0e35e54f069420670c20d.zip |
-rw-r--r-- | ui-tree.c | 60 |
1 files changed, 51 insertions, 9 deletions
@@ -86,10 +86,44 @@ static void print_binary_buffer(char *buf, unsigned long size) html("</table>\n"); } +static void print_object_mime(const char *path, const char *rev, const char *mime) +{ + char *fileurl, *pre, *post; + + fileurl = cgit_fileurl(ctx.repo->url, "plain", path, NULL); + + if (!strncmp(mime, "image/", 6)) { + pre = "<img src='"; + post = "' />"; + } else if (!strncmp(mime, "audio/", 6)) { + pre = "<audio controls src='"; + post = "'></audio>"; + } else if (!strncmp(mime, "video/", 6)) { + pre = "<video controls><source src='"; + post = "' type='%s' /></video>"; + } else { + pre = "<object data='"; + post = "' type='%s'></object>"; + } + + html("<table><td id='content'>"); + html(pre); + html_url_path(fileurl); + if (rev && ctx.qry.head != NULL && strcmp(rev, ctx.qry.head)) { + html(ctx.cfg.virtual_root ? "?" : "&"); + html("id="); + html_url_arg(rev); + } + htmlf(post, mime); + html("</table>"); + + free(fileurl); +} + static void print_object(const struct object_id *oid, const char *path, const char *basename, const char *rev) { enum object_type type; - char *buf; + char *buf, *mime; unsigned long size; bool is_binary; @@ -100,13 +134,18 @@ static void print_object(const struct object_id *oid, const char *path, const ch return; } - buf = repo_read_object_file(the_repository, oid, &type, &size); - if (!buf) { - cgit_print_error_page(500, "Internal server error", - "Error reading object %s", oid_to_hex(oid)); - return; + mime = get_mimetype_for_filename(path); + if (mime) { + is_binary = false; + } else { + buf = repo_read_object_file(the_repository, oid, &type, &size); + if (!buf) { + cgit_print_error_page(500, "Internal server error", + "Error reading object %s", oid_to_hex(oid)); + return; + } + is_binary = buffer_is_binary(buf, size); } - is_binary = buffer_is_binary(buf, size); cgit_set_title_from_path(path); @@ -127,12 +166,15 @@ static void print_object(const struct object_id *oid, const char *path, const ch return; } - if (is_binary) + if (mime) + print_object_mime(path, rev, mime); + else if (is_binary) print_binary_buffer(buf, size); else print_text_buffer(basename, buf, size); - free(buf); + if (!mime) + free(buf); } struct single_tree_ctx { |