mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-22 21:45:56 +03:00
fixed blurhash checking
This commit is contained in:
parent
35e0f0481b
commit
8056862898
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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]);
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user