Skip to content

[Feature] Download code as file #2

Description

@kom50

Summary

Allow users to download the current editor content as a file with appropriate extension.

Requirements

  • Add "Download" button in header
  • Auto-detect file extension from language mode
  • Generate filename: collabpad-{roomId}.{ext}
  • Support custom filename input (optional)
  • Trigger browser download

File Extension Mapping

Language Extension
JavaScript .js
TypeScript .ts
Python .py
HTML .html
CSS .css
Markdown .md
JSON .json
SQL .sql

Technical Notes

function downloadFile(content, filename) {
  const blob = new Blob([content], { type: 'text/plain' });
  const url = URL.createObjectURL(blob);
  const a = document.createElement('a');
  a.href = url;
  a.download = filename;
  a.click();
  URL.revokeObjectURL(url);
}

Acceptance Criteria

  • Clicking download saves file to user's device
  • File extension matches current language
  • File content matches editor content exactly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions