mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 15:09:33 +01:00
core: replace mime-db with mime and lazy load it
This commit is contained in:
committed by
Abdullah Atta
parent
7437b29518
commit
5f1f308540
@@ -28,7 +28,6 @@
|
|||||||
"@types/event-source-polyfill": "^1.0.1",
|
"@types/event-source-polyfill": "^1.0.1",
|
||||||
"@types/html-to-text": "^9.0.0",
|
"@types/html-to-text": "^9.0.0",
|
||||||
"@types/katex": "^0.16.2",
|
"@types/katex": "^0.16.2",
|
||||||
"@types/mime-db": "^1.43.1",
|
|
||||||
"@types/prismjs": "^1.26.0",
|
"@types/prismjs": "^1.26.0",
|
||||||
"@types/spark-md5": "^3.0.2",
|
"@types/spark-md5": "^3.0.2",
|
||||||
"@types/streetwriters__showdown": "npm:@types/showdown@^2.0.6",
|
"@types/streetwriters__showdown": "npm:@types/showdown@^2.0.6",
|
||||||
@@ -82,7 +81,7 @@
|
|||||||
"katex": "0.16.2",
|
"katex": "0.16.2",
|
||||||
"linkedom": "^0.14.17",
|
"linkedom": "^0.14.17",
|
||||||
"liqe": "^1.13.0",
|
"liqe": "^1.13.0",
|
||||||
"mime-db": "1.52.0",
|
"mime": "^4.0.4",
|
||||||
"prismjs": "^1.29.0",
|
"prismjs": "^1.29.0",
|
||||||
"qclone": "^1.2.0",
|
"qclone": "^1.2.0",
|
||||||
"rfdc": "^1.3.0",
|
"rfdc": "^1.3.0",
|
||||||
|
|||||||
@@ -171,10 +171,10 @@ export class Attachments implements ICollection {
|
|||||||
|
|
||||||
filename:
|
filename:
|
||||||
filename ||
|
filename ||
|
||||||
getFileNameWithExtension(
|
(await getFileNameWithExtension(
|
||||||
filename || hash,
|
filename || hash,
|
||||||
mimeType || "application/octet-stream"
|
mimeType || "application/octet-stream"
|
||||||
),
|
)),
|
||||||
hash,
|
hash,
|
||||||
hashType,
|
hashType,
|
||||||
mimeType: mimeType || "application/octet-stream",
|
mimeType: mimeType || "application/octet-stream",
|
||||||
|
|||||||
@@ -17,21 +17,23 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import db from "mime-db";
|
export async function getFileNameWithExtension(
|
||||||
|
|
||||||
export function getFileNameWithExtension(
|
|
||||||
filename: string,
|
filename: string,
|
||||||
mime: string | undefined
|
mime: string | undefined
|
||||||
): string {
|
): Promise<string> {
|
||||||
if (!mime || mime === "application/octet-stream") return filename;
|
if (!mime || mime === "application/octet-stream") return filename;
|
||||||
const mimeData = db[mime];
|
|
||||||
if (!mimeData || !mimeData.extensions || mimeData.extensions.length === 0)
|
|
||||||
return filename;
|
|
||||||
const extension = mimeData.extensions[0];
|
|
||||||
|
|
||||||
if (mimeData.extensions.some((extension) => filename.endsWith(extension)))
|
const { default: mimeDB } = await import("mime");
|
||||||
return filename;
|
|
||||||
|
|
||||||
|
const extensions = mimeDB.getAllExtensions(mime);
|
||||||
|
|
||||||
|
if (!extensions || extensions.size === 0) return filename;
|
||||||
|
|
||||||
|
for (const ext of extensions) {
|
||||||
|
if (filename.endsWith(ext)) return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
const extension = extensions.values().next().value;
|
||||||
return `${filename}.${extension}`;
|
return `${filename}.${extension}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user