Commit 4764bbd3 authored by svilayphiou's avatar svilayphiou
Browse files

Download raw file.

parent 27370198
......@@ -47,7 +47,7 @@
</a>
</li>
</ul>
<div id="blob" v-html="bloup">
<div id="blob" v-html="blobItem">
</div>
</section>
<section id="commits" class="repo-views">
......@@ -75,7 +75,7 @@
{% block script %}
<script type="text/javascript" charset="utf-8">
var gitlab_url = "http://gitlab.constantvzw.org";
var gitlabURL = "http://gitlab.constantvzw.org";
var user_name = "osp";
var repoID = {{ project.id }};
......@@ -114,7 +114,7 @@
data: {
fileList,
upPath: "/",
bloup: "?",
blobItem: "",
},
delimiters: ['[[',']]'],
methods: {
......@@ -147,19 +147,30 @@
let blobURL = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/blobs/" + blobID + "/raw";
fetch(blobURL).then((resp) => resp.blob())
.then(function(data){
// FILENAME
h4 = "<h4>" + path + "</h4>"
// DOWNLOAD RAW FILE
project_path = [gitlabURL, user_name, '{{ project.name }}'].join('/');
href = project_path + "/raw/master/" + path;
a = '<p><a download href="' + href + '">Download file</a></p>';
var mime = data["type"];
// if PNG, JPG, or GIF
if(mime == "image/png" | mime == "image/jpeg" | mime == "image/jpg" | mime == "image/gif") {
vm.bloup = "<img src='" + blobURL+ "'>"
vm.blobItem = h4 + a + "<img src='" + blobURL+ "'>";
}
// if TXT, SVG, code...
else if (mime == "text/plain" | mime == "image/svg+xml") {
var reader = new FileReader();
reader.readAsText(data);
reader.onloadend=function(){
vm.bloup = reader.result;
vm.blobItem = h4 + a + reader.result;
};
}
else {
vm.blobItem = h4 + a;
}
})
}
},
......@@ -194,7 +205,7 @@
return data.map(function(image) {
item = {};
item.name = image.name;
project_path = [gitlab_url, user_name, "{{ project.name }}"].join('/');
project_path = [gitlabURL, user_name, "{{ project.name }}"].join('/');
item.src = project_path + "/raw/{{ project.default_branch }}/" + image.path;
imageList.push(item);
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment