mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-30 02:12:38 +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 Environment from "~/common/environment";
|
||||||
import * as Window from "~/common/window";
|
import * as Window from "~/common/window";
|
||||||
|
|
||||||
import { encode } from "blurhash";
|
import { encode, isBlurhashValid } from "blurhash";
|
||||||
import { v4 as uuid } from "uuid";
|
import { v4 as uuid } from "uuid";
|
||||||
|
|
||||||
const STAGING_DEAL_BUCKET = "stage-deal";
|
const STAGING_DEAL_BUCKET = "stage-deal";
|
||||||
@ -257,7 +257,9 @@ export const upload = async ({ file, context, bucketName }) => {
|
|||||||
let url = Strings.getURLfromCID(item.cid);
|
let url = Strings.getURLfromCID(item.cid);
|
||||||
try {
|
try {
|
||||||
let blurhash = await encodeImageToBlurhash(url);
|
let blurhash = await encodeImageToBlurhash(url);
|
||||||
|
if (isBlurhashValid(blurhash).result) {
|
||||||
item.data.blurhash = blurhash;
|
item.data.blurhash = blurhash;
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logging.error(e);
|
Logging.error(e);
|
||||||
}
|
}
|
||||||
|
@ -114,10 +114,10 @@ export default function Preview({
|
|||||||
const getFileBlurHash = (file) => {
|
const getFileBlurHash = (file) => {
|
||||||
const coverImage = file?.data?.coverImage;
|
const coverImage = file?.data?.coverImage;
|
||||||
const coverImageBlurHash = coverImage?.data?.blurhash;
|
const coverImageBlurHash = coverImage?.data?.blurhash;
|
||||||
if (coverImage && isBlurhashValid(coverImageBlurHash)) return coverImageBlurHash;
|
if (coverImage && isBlurhashValid(coverImageBlurHash).result) return coverImageBlurHash;
|
||||||
|
|
||||||
const blurhash = file?.data?.blurhash;
|
const blurhash = file?.data?.blurhash;
|
||||||
if (isBlurhashValid(blurhash)) return blurhash;
|
if (isBlurhashValid(blurhash).result) return blurhash;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
@ -67,9 +67,9 @@ export default function ImageObjectPreview({
|
|||||||
const imgTag = type.split("/")[1];
|
const imgTag = type.split("/")[1];
|
||||||
|
|
||||||
const blurhash = React.useMemo(() => {
|
const blurhash = React.useMemo(() => {
|
||||||
return file.data.blurhash && isBlurhashValid(file.data.blurhash)
|
return file.data.blurhash && isBlurhashValid(file.data.blurhash).result
|
||||||
? file.data.blurhash
|
? file.data.blurhash
|
||||||
: coverImage?.data.blurhash && isBlurhashValid(coverImage?.data.blurhash)
|
: coverImage?.data.blurhash && isBlurhashValid(coverImage?.data.blurhash).result
|
||||||
? coverImage?.data.blurhash
|
? coverImage?.data.blurhash
|
||||||
: null;
|
: null;
|
||||||
}, [file]);
|
}, [file]);
|
||||||
|
@ -112,9 +112,9 @@ export default class SlateMediaObjectPreview extends React.Component {
|
|||||||
|
|
||||||
if (url) {
|
if (url) {
|
||||||
const blurhash =
|
const blurhash =
|
||||||
file.data.blurhash && isBlurhashValid(file.data?.blurhash)
|
file.data.blurhash && isBlurhashValid(file.data?.blurhash).result
|
||||||
? file.data?.blurhash
|
? file.data?.blurhash
|
||||||
: coverImage?.data.blurhash && isBlurhashValid(coverImage?.data.blurhash)
|
: coverImage?.data.blurhash && isBlurhashValid(coverImage?.data.blurhash).result
|
||||||
? coverImage?.data.blurhash
|
? coverImage?.data.blurhash
|
||||||
: null;
|
: null;
|
||||||
if (this.state.error) {
|
if (this.state.error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user