Skip to content

Commit

Permalink
fix: text file web paste
Browse files Browse the repository at this point in the history
  • Loading branch information
ozwaldorf committed Oct 14, 2024
1 parent 6a2331a commit c24439b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,20 @@
<script nonce="{nonce}">
document.addEventListener('paste', async (event) => {{
const preElement = document.querySelector('pre');
// Handle text data
const text = event.clipboardData.getData("text");
if (text) {
preElement.innerHTML = `<a href=${{text}}>${{text}}</a>`;
return;
}
// Or handle files
const responses = await Promise.all([...event.clipboardData.items]
.filter(item => item.kind === 'file' || item.kind === 'string')
.map(async item => {{
const file = item.getAsFile();
const uploadUrl = `/${{file.name}}`;
const file = item.getAsFile() || item.getAsString();
if (!file)
return `Error reading from clipboard`;
const uploadUrl = `/${{typeof file === "object" ? file.name : "" }}`;
try {{
const response = await fetch(uploadUrl, {{
method: 'PUT',
Expand Down

0 comments on commit c24439b

Please sign in to comment.