Commit 08d3c006 authored by svilayphiou's avatar svilayphiou
Browse files

read image blob

parent 42605541
......@@ -24,8 +24,8 @@
<h2>Tree</h2>
<ul id="tree"></ul>
<h2>README</h2>
<div id="readme"></div>
<h2>BLOB</h2>
<div id="blob"></div>
<h2>ICEBERG</h2>
<div id="iceberg"></div>
......@@ -35,6 +35,8 @@
<script type="text/javascript" charset="utf-8">
var this_url = new URL(window.location.href);
// BEGIN DIFF
const file_elt = document.querySelector('#file_history');
const file_path = 'communication%2Fbanners%2Fbanner-eflux.png';
......@@ -55,17 +57,35 @@
});
});
// BLOB
var blob = this_url.searchParams.get("blob");
if (blob){
var blob_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/blobs/" + blob + "/raw";
console.log(blob_url);
//README = file.id;
const blob_elt = document.querySelector('#blob');
fetch(blob_url)
.then((resp) => resp.blob())
.then(function(data){
var mime = data["type"];
if(mime == "image/png" | mime == "image/jpg" | mime == "image/gif") {
let img = document.createElement('img');
img.src = blob_url;
blob_elt.appendChild(img);
} else {
blob_elt.innerHTML = 'data';
}
})
}
// BEGIN TREE
var this_url = new URL(window.location.href);
var path = this_url.searchParams.get("path");
const tree_elt = document.querySelector('#tree');
if(path == null) {
var tree_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/tree";
} else {
if(path) {
var tree_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/tree?path=" + path;
} else {
var tree_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/tree";
}
var README = "";
fetch(tree_url)
.then((resp) => resp.json())
......@@ -73,24 +93,18 @@
return data.map(function(file) {
let li = document.createElement('li');
li.classList.add(file.type);
li.innerHTML = "<a href='?path=" + file.path + "' >" + file.name + "</a>";
if (file.type == 'tree') {
li.innerHTML = "<a href='?path=" + file.path + "' >" + file.name + "</a>";
} else {
console.log(file.path);
li.innerHTML = "<a href='?blob=" + file.id + "' >" + file.name + "</a>";
}
tree_elt.appendChild(li);
// README
if (file.name == "README.md"){
README = file.id;
const readme_elt = document.querySelector('#readme');
const readme_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/blobs/" + README + "/raw";
fetch(readme_url)
.then((resp) => resp.text())
.then(function(data){
readme_elt.innerHTML = data;
})
}
// ICEBERG
if (file.name == "iceberg"){
iceberg = file.id;
iceberg = fil4.id;
const iceberg_elt = document.querySelector('#iceberg');
const iceberg_url = "https://gitlab.constantvzw.org/api/v4/projects/456/repository/tree/?path=iceberg";
fetch(iceberg_url)
......
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