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

Download raw file.

parent 27370198
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
</a> </a>
</li> </li>
</ul> </ul>
<div id="blob" v-html="bloup"> <div id="blob" v-html="blobItem">
</div> </div>
</section> </section>
<section id="commits" class="repo-views"> <section id="commits" class="repo-views">
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
{% block script %} {% block script %}
<script type="text/javascript" charset="utf-8"> <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 user_name = "osp";
var repoID = {{ project.id }}; var repoID = {{ project.id }};
...@@ -114,7 +114,7 @@ ...@@ -114,7 +114,7 @@
data: { data: {
fileList, fileList,
upPath: "/", upPath: "/",
bloup: "?", blobItem: "",
}, },
delimiters: ['[[',']]'], delimiters: ['[[',']]'],
methods: { methods: {
...@@ -147,19 +147,30 @@ ...@@ -147,19 +147,30 @@
let blobURL = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/blobs/" + blobID + "/raw"; let blobURL = "https://gitlab.constantvzw.org/api/v4/projects/" + repoID + "/repository/blobs/" + blobID + "/raw";
fetch(blobURL).then((resp) => resp.blob()) fetch(blobURL).then((resp) => resp.blob())
.then(function(data){ .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"]; var mime = data["type"];
// if PNG, JPG, or GIF // if PNG, JPG, or GIF
if(mime == "image/png" | mime == "image/jpeg" | mime == "image/jpg" | mime == "image/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... // if TXT, SVG, code...
else if (mime == "text/plain" | mime == "image/svg+xml") { else if (mime == "text/plain" | mime == "image/svg+xml") {
var reader = new FileReader(); var reader = new FileReader();
reader.readAsText(data); reader.readAsText(data);
reader.onloadend=function(){ reader.onloadend=function(){
vm.bloup = reader.result; vm.blobItem = h4 + a + reader.result;
}; };
} }
else {
vm.blobItem = h4 + a;
}
}) })
} }
}, },
...@@ -194,7 +205,7 @@ ...@@ -194,7 +205,7 @@
return data.map(function(image) { return data.map(function(image) {
item = {}; item = {};
item.name = image.name; 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; item.src = project_path + "/raw/{{ project.default_branch }}/" + image.path;
imageList.push(item); 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