Skip to content
Snippets Groups Projects
Commit af80da51 authored by Jacob Benz's avatar Jacob Benz
Browse files

Handle images >1MB from GitHub

parent e2651a6b
No related branches found
No related tags found
No related merge requests found
......@@ -232,10 +232,25 @@ class ImageViewer {
path: GitUrlParse(realURL).filepath,
commit: GitUrlParse(realURL).commit
})
const content = URL.createObjectURL(new Blob([Buffer.from(result.data.content, 'base64')]))
// console.log(realURL + " " + content)
tileSources[index] = { type: 'image', url: content };
// console.log(tileSources)
if (result.data.content === "") { // content empty if file larger then 1MB
//console.log("Get via blob!")
const result_blob =
await octokit.request('GET /repos/{owner}/{repo}/git/blobs/{file_sha}',{
owner: GitUrlParse(realURL).owner,
repo: GitUrlParse(realURL).name,
file_sha: result.data.sha,
})
//console.log(result_blob)
const content = URL.createObjectURL(new Blob([Buffer.from(result_blob.data.content, 'base64')]))
//console.log(realURL + " " + content)
tileSources[index] = { type: 'image', url: content };
//console.log(tileSources)
} else {
const content = URL.createObjectURL(new Blob([Buffer.from(result.data.content, 'base64')]))
// console.log(realURL + " " + content)
tileSources[index] = { type: 'image', url: content };
// console.log(tileSources)
}
} catch(error) {
tileSources[index] = { type: 'image', url: "non-existent" };
return
......@@ -274,11 +289,27 @@ class ImageViewer {
path: realURL
})
// console.log(result)
const content = URL.createObjectURL(new Blob([Buffer.from(result.data.content, 'base64')]))
//console.log(realURL + " " + content)
tileSources[index] = { type: 'image', url: content };
// console.log(tileSources)
if (result.data.content === "") { // content empty if file larger then 1MB
//console.log("Get via blob!")
const result_blob =
await octokit.request('GET /repos/{owner}/{repo}/git/blobs/{file_sha}',{
owner: this.writer.overmindState.document.GitHubOwner,
repo: this.writer.overmindState.document.GitHubRepo,
file_sha: result.data.sha,
})
//console.log(result_blob)
const content = URL.createObjectURL(new Blob([Buffer.from(result_blob.data.content, 'base64')]))
//console.log(realURL + " " + content)
tileSources[index] = { type: 'image', url: content };
//console.log(tileSources)
} else {
const content = URL.createObjectURL(new Blob([Buffer.from(result.data.content, 'base64')]))
//console.log(realURL + " " + content)
tileSources[index] = { type: 'image', url: content };
// console.log(tileSources)
}
} catch (error) {
// console.log(error)
tileSources[index] = { type: 'image', url: "non-existent" };
return
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment