mirror of
https://github.com/filecoin-project/slate.git
synced 2024-09-20 02:37:09 +03:00
Merge pull request #741 from filecoin-project/@aminejv/font-validations
This commit is contained in:
commit
45b5e4b224
@ -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();
|
||||
|
@ -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} />;
|
||||
}
|
||||
|
||||
|
@ -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}
|
||||
|
Loading…
Reference in New Issue
Block a user