mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-23 11:37:02 -04:00
Add common download helper (#628)
* Refactor download functions into a common helper function * Removed unused import
This commit is contained in:
parent
c0d05904b2
commit
9b6fca29e8
4 changed files with 13 additions and 20 deletions
|
@ -1,18 +1,13 @@
|
|||
import { Revision } from '../../../../api/revisions/types'
|
||||
import { getUserById } from '../../../../api/users'
|
||||
import { UserResponse } from '../../../../api/users/types'
|
||||
import { download } from '../../../common/download/download'
|
||||
|
||||
export const downloadRevision = (noteId: string, revision: Revision | null): void => {
|
||||
if (!revision) {
|
||||
return
|
||||
}
|
||||
const encoded = Buffer.from(revision.content).toString('base64')
|
||||
const wrapper = document.createElement('a')
|
||||
wrapper.download = `${noteId}-${revision.timestamp}.md`
|
||||
wrapper.href = `data:text/markdown;charset=utf-8;base64,${encoded}`
|
||||
document.body.appendChild(wrapper)
|
||||
wrapper.click()
|
||||
document.body.removeChild(wrapper)
|
||||
download(revision.content, `${noteId}-${revision.timestamp}.md`, 'text/markdown')
|
||||
}
|
||||
|
||||
export const getUserDataForRevision = (authors: string[]): UserResponse[] => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue