website

#astro#js#html#css

git clone https://git.pyrossh.dev/website

木 Personal website of pyrossh. Built with astrojs, shiki, vite.


cebf5e1pyrossh 2026-07-08T20:01:09+05:30
fix: toBase64 loop for large files, SVG MIME type, unused import
Files changed (1) hide show
  1. src/index.ts +9 -4
src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Hono } from 'hono'
2
2
  import { html, raw } from 'hono/html'
3
3
  import { getS3 } from './s3'
4
- import { getPosts, getPost, getRepos, getRepo } from './lib/content'
4
+ import { getPosts, getPost, getRepo } from './lib/content'
5
5
  import { getRepoReadme } from './lib/repoContent'
6
6
  import { renderMarkdown } from './lib/markdown'
7
7
  import { getCommits, getFiles, getFileHistory, getFileContentData, generateHTMLDiff } from './lib/gitReader'
@@ -515,7 +515,11 @@ const BINARY_EXTS = ['apk', 'dex', 'ap_', 'jar', 'fnt']
515
515
  const IMAGE_EXTS = ['png', 'jpg', 'jpeg', 'gif', 'svg', 'webp', 'ico', 'icns', 'curve', 'atlas']
516
516
  const LARGE_SIZE = 1024 * 512
517
517
 
518
- const toBase64 = (data: Uint8Array) => btoa(String.fromCharCode(...data))
518
+ const toBase64 = (data: Uint8Array) => {
519
+ let binary = ''
520
+ for (let i = 0; i < data.length; i++) binary += String.fromCharCode(data[i])
521
+ return btoa(binary)
522
+ }
519
523
 
520
524
  app.get('/repos/:id/files/:path{.+}/history', async (c) => {
521
525
  const repoId = c.req.param('id')
@@ -591,9 +595,10 @@ app.get('/repos/:id/files/:path{.+}', async (c) => {
591
595
 
592
596
  let content: any
593
597
  if (isBinary || isLarge) {
594
- content = html`<p>The file is too large to be displayed (${file.size} bytes).</p>`
598
+ content = html`<p>Binary file (${file.size} bytes).</p>`
595
599
  } else if (isImage && contentBuffer) {
600
+ const mime = file.ext === 'svg' ? 'image/svg+xml' : `image/${file.ext}`
596
- content = html`<img src="data:image/${file.ext};base64,${toBase64(contentBuffer)}" alt="${file.path}" />`
601
+ content = html`<img src="data:${mime};base64,${toBase64(contentBuffer)}" alt="${file.path}" />`
597
602
  } else if (contentBuffer) {
598
603
  const text = new TextDecoder('utf-8').decode(contentBuffer).trim() || 'No content to display.'
599
604
  content = html`<pre><code class="language-${file.ext}">${text}</code></pre>`