| 1 | -- resty-gitweb@pages/raw.lua |
| 2 | -- Raw file page builder |
| 3 |
|
| 4 | -- Copyright (c) 2020 Joshua 'joshuas3' Stockin |
| 5 | -- <https://git.joshstock.in/resty-gitweb> |
| 6 | -- This software is licensed under the MIT License. |
| 7 |
|
| 8 | local utils = require("utils/utils") |
| 9 | local git = require("git/git") |
| 10 |
|
| 11 | local builder = require("utils/builder") |
| 12 |
|
| 13 | local _M = function(repo, repo_dir, branch, file_path) |
| 14 | -- Pre checks |
| 15 | if file_path ~= "" then -- make sure path exists |
| 16 | local path_tree = git.list_tree(repo_dir, branch.name, file_path) |
| 17 | if #path_tree.files == 0 then -- no path found |
| 18 | error("file "..file_path.." is nonexistent") |
| 19 | end |
| 20 | else |
| 21 | error("file path is empty") |
| 22 | end |
| 23 |
|
| 24 | local build = builder:new() |
| 25 |
|
| 26 | -- File |
| 27 | local repo_obj = git.repo.open(repo_dir) |
| 28 | local content, is_binary = git.read_blob(repo_obj, branch.name, file_path) |
| 29 | git.repo.free(repo_obj) |
| 30 |
|
| 31 | build{content} |
| 32 |
|
| 33 | return build, is_binary |
| 34 | end |
| 35 |
|
| 36 | return _M |
| 37 |
|