Skip to content
This repository has been archived by the owner on Jan 1, 2022. It is now read-only.

Disable Turbolinks on links that which do not need to be previewed to prevent binary files being opened as html #178

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/folderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getClassNameForMimeType, getClassNameForFilename } from 'font-awesome-f
import { renderHTML } from './render/htmlWrapper'
import { renderPath } from './render/pathUtil'
import { renderMarkdown } from './render/mdRenderer'
import { extensions } from './render/fileExtension'

/**
* Convert bytes to human readable file size
Expand Down Expand Up @@ -48,6 +49,15 @@ export async function renderFolderView(items, path, request) {
el('div', ['style="flex-grow: 1;"'], '') +
(fileName === '..' ? '' : el('span', ['class="size"'], readableFileSize(size)))
)
const item_no_trobulink = (icon, fileName, fileAbsoluteUrl, size, emojiIcon) =>
el(
'a',
[`href="${fileAbsoluteUrl}"`, 'data-turbolinks="false"', 'class="item"', size ? `size="${size}"` : ''],
(emojiIcon ? el('i', ['style="font-style: normal"'], emojiIcon) : el('i', [`class="${icon}"`], '')) +
fileName +
el('div', ['style="flex-grow: 1;"'], '') +
(fileName === '..' ? '' : el('span', ['class="size"'], readableFileSize(size)))
)

const intro = `<div class="intro markdown-body" style="text-align: left; margin-top: 2rem;">
<h2>Yoo, I'm Spencer Woo 👋</h2>
Expand Down Expand Up @@ -105,7 +115,17 @@ export async function renderFolderView(items, path, request) {
} else {
fileIcon = `far ${fileIcon}`
}
return item(fileIcon, i.name, `${path}${i.name}`, i.size)

const fileExt = i.name
.split('.')
.pop()
.toLowerCase()

if (!(fileExt in extensions)) {
return item_no_trobulink(fileIcon, i.name, `${path}${i.name}`, i.size)
} else {
return item(fileIcon, i.name, `${path}${i.name}`, i.size)
}
} else {
console.log(`unknown item type ${i}`)
}
Expand Down