fixed blurhash checking

This commit is contained in:
Martina 2021-09-03 13:02:00 -07:00
parent 35e0f0481b
commit 8056862898
4 changed files with 10 additions and 8 deletions

View File

@ -8,7 +8,7 @@ import * as Logging from "~/common/logging";
import * as Environment from "~/common/environment";
import * as Window from "~/common/window";
import { encode } from "blurhash";
import { encode, isBlurhashValid } from "blurhash";
import { v4 as uuid } from "uuid";
const STAGING_DEAL_BUCKET = "stage-deal";
@ -257,7 +257,9 @@ export const upload = async ({ file, context, bucketName }) => {
let url = Strings.getURLfromCID(item.cid);
try {
let blurhash = await encodeImageToBlurhash(url);
item.data.blurhash = blurhash;
if (isBlurhashValid(blurhash).result) {
item.data.blurhash = blurhash;
}
} catch (e) {
Logging.error(e);
}

View File

@ -114,10 +114,10 @@ export default function Preview({
const getFileBlurHash = (file) => {
const coverImage = file?.data?.coverImage;
const coverImageBlurHash = coverImage?.data?.blurhash;
if (coverImage && isBlurhashValid(coverImageBlurHash)) return coverImageBlurHash;
if (coverImage && isBlurhashValid(coverImageBlurHash).result) return coverImageBlurHash;
const blurhash = file?.data?.blurhash;
if (isBlurhashValid(blurhash)) return blurhash;
if (isBlurhashValid(blurhash).result) return blurhash;
return null;
};

View File

@ -67,9 +67,9 @@ export default function ImageObjectPreview({
const imgTag = type.split("/")[1];
const blurhash = React.useMemo(() => {
return file.data.blurhash && isBlurhashValid(file.data.blurhash)
return file.data.blurhash && isBlurhashValid(file.data.blurhash).result
? file.data.blurhash
: coverImage?.data.blurhash && isBlurhashValid(coverImage?.data.blurhash)
: coverImage?.data.blurhash && isBlurhashValid(coverImage?.data.blurhash).result
? coverImage?.data.blurhash
: null;
}, [file]);

View File

@ -112,9 +112,9 @@ export default class SlateMediaObjectPreview extends React.Component {
if (url) {
const blurhash =
file.data.blurhash && isBlurhashValid(file.data?.blurhash)
file.data.blurhash && isBlurhashValid(file.data?.blurhash).result
? file.data?.blurhash
: coverImage?.data.blurhash && isBlurhashValid(coverImage?.data.blurhash)
: coverImage?.data.blurhash && isBlurhashValid(coverImage?.data.blurhash).result
? coverImage?.data.blurhash
: null;
if (this.state.error) {