Zionetrix::Git
Repositories
Help
Report an Issue
viewgit-directdownload-plugin
Code
Commits
Branches
Tags
Search
Tree:
14aad03
Branches
Tags
master
viewgit-directdownload-plugin
directdownload
main.php
Initial commit
Benjamin Renard
commited
14aad03
at 2013-08-22 09:57:43
main.php
Blame
History
Raw
<?php /** * Direct Download plugin for ViewGit. * * This plugin permit direct download of project file using URL like * * http://my.viewgit.com/?a=directdownload&p=myproject&h=HEAD&f=path/to/my/poject/file * * @author Benjamin Renard <brenard@zionetrix.net> */ class DirectDownloadPlugin extends VGPlugin { function __construct() { global $conf; $this->register_action('directdownload'); } function action($action) { if ($action === 'directdownload') { $project = validate_project($_REQUEST['p']); $hash = validate_hash($_REQUEST['h']); if (isset($_REQUEST['f'])) { $path = $_REQUEST['f']; $infos=git_get_path_info($project,$hash,$path); if (count($infos)!=1) { die('Invalid path'); } $hash=$infos[0]['hash']; $name=$infos[0]['name']; } else { $name = $_REQUEST['n']; } header('Content-type: application/octet-stream'); header("Content-Disposition: attachment; filename=$name"); run_git_passthru($project, "cat-file blob $hash"); die(); } } }