Merge pull request #741 from filecoin-project/@aminejv/font-validations

This commit is contained in:
martinalong 2021-05-04 11:20:36 -07:00 committed by GitHub
commit 45b5e4b224
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import * as Strings from "~/common/strings";
import * as Utilities from "~/common/utilities";
import JSZip from "jszip";
@ -177,6 +178,14 @@ export const isEpubType = (type) => {
}
};
export const isFontFile = (fileName) => {
return Utilities.endsWithAny([".ttf", ".otf", ".woff", ".woff2"], fileName.toLowerCase());
};
export const isMarkdown = (filename, type) => {
return filename.toLowerCase().endsWith(".md") || type.startsWith("text/plain");
};
export const isUnityFile = async (file) => {
try {
const zip = new JSZip();

View File

@ -155,7 +155,7 @@ export default class SlateMediaObject extends React.Component {
return <iframe src={url} css={STYLES_IFRAME} />;
}
if (endsWithAny([".ttf", ".otf", ".woff", ".woff2"], file.filename)) {
if (Validations.isFontFile(file.filename)) {
return (
<FontFrame
name={file.data.name || file.filename}
@ -168,7 +168,7 @@ export default class SlateMediaObject extends React.Component {
);
}
if (file.filename.endsWith(".md") || type.startsWith("text/plain")) {
if (Validations.isMarkdown(file.filename, type)) {
return <MarkdownFrame date={file.createdAt} url={url} />;
}

View File

@ -8,7 +8,6 @@ import { css } from "@emotion/react";
import { FileTypeIcon } from "~/components/core/FileTypeIcon";
import { Blurhash } from "react-blurhash";
import { isBlurhashValid } from "blurhash";
import { endsWithAny } from "~/common/utilities";
import FontObjectPreview from "~/components/core/FontFrame/Views/FontObjectPreview";
@ -201,7 +200,7 @@ export default class SlateMediaObjectPreview extends React.Component {
if (!file.filename) {
console.log(file);
}
if (endsWithAny([".ttf", ".otf", ".woff", ".woff2"], file.filename)) {
if (Validations.isFontFile(file.filename)) {
return (
<article
css={STYLES_ENTITY}