| Server IP : 170.10.161.225 / Your IP : 216.73.217.54 Web Server : Apache System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64 User : calvet ( 273824) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : ON Directory : /home/www/calvetrealty.com/wp-content/plugins/code-snippets/js/utils/ |
Upload File : |
import { Snippet } from '../types/Snippet'
import { getSnippetType } from './snippets'
const SECOND_IN_MS = 1000
const TIMEOUT_SECONDS = 40
const MIME_INFO = <const> {
php: ['php', 'text/php'],
html: ['php', 'text/php'],
css: ['css', 'text/css'],
js: ['js', 'text/javascript'],
json: ['json', 'application/json']
}
export const downloadAsFile = (content: BlobPart, filename: string, type: string) => {
const link = document.createElement('a')
link.download = filename
link.href = URL.createObjectURL(new Blob([content], { type }))
setTimeout(() => URL.revokeObjectURL(link.href), TIMEOUT_SECONDS * SECOND_IN_MS)
setTimeout(() => link.click(), 0)
}
export const downloadSnippetExportFile = (
content: BlobPart,
{ id, name, scope }: Snippet,
type?: keyof typeof MIME_INFO
) => {
const [ext, mimeType] = MIME_INFO[type ?? getSnippetType(scope)]
const title = name.toLowerCase().replace(/[^\w-]+/g, '-') ?? `snippet-${id}`
const filename = `${title}.code-snippets.${ext}`
downloadAsFile(content, filename, mimeType)
}