mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: improve file download naming by using syntax extension conditionally
This commit is contained in:
@@ -587,16 +587,22 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
const syntax = syntaxes[data.paste?.syntax ?? 'plaintext'];
|
const syntax = syntaxes[data.paste?.syntax ?? 'plaintext'];
|
||||||
|
let extension = '.txt';
|
||||||
|
|
||||||
console.log(syntax);
|
if (syntax && syntax.extension) {
|
||||||
console.log(data.paste?.syntax);
|
if (data.paste?.title?.endsWith(syntax.extension)) {
|
||||||
|
extension = '';
|
||||||
|
} else {
|
||||||
|
extension = syntax.extension;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
const a = document.createElement('a');
|
const a = document.createElement('a');
|
||||||
a.href = url;
|
a.href = url;
|
||||||
a.download = data.paste?.title
|
a.download = data.paste?.title
|
||||||
? data.paste.title.replace(/[^a-z0-9_\-.]/gi, '_').slice(0, 100) + (syntax?.extension ? `.${syntax.extension}` : '.txt')
|
? data.paste.title.slice(0, 100) + extension
|
||||||
: `paste_${data.paste?.id}.${syntax?.extension ?? 'txt'}`;
|
: `paste_${data.paste?.id}${extension}`;
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
|
|||||||
Reference in New Issue
Block a user