Skip to content

Commit

Permalink
Use base64 strings instead of blobs and URLs for image sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shang Zhe Lee committed Sep 6, 2021
1 parent 0818694 commit 0ecdea0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 23 deletions.
24 changes: 2 additions & 22 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,10 @@ function implementCardOverride(
...overrides,
};
if (image !== undefined) {
cardData.image = image === null ? undefined : image[1];
cardData.image = image === null ? undefined : image;
}
const cardMethods: CardMethods = {
update(updates) {
if (image != null && updates.image !== undefined) {
URL.revokeObjectURL(image[1]);
}
const newOverrides: Partial<ICardProperties> = {
...data.overrides,
...updates,
Expand Down Expand Up @@ -207,12 +204,7 @@ function implementCardOverride(
.concat([['id', base.id]]));
}
if (image !== undefined) {
if (image === null) {
bodyObj.image = null;
} else {
const [blob] = image;
bodyObj.image = Buffer.from(await blob.arrayBuffer()).toString('base64');
}
bodyObj.image = image;
}
const body = JSON.stringify(bodyObj);
const res = await fetch('/api/card', {
Expand Down Expand Up @@ -271,16 +263,6 @@ const AppComponent: React.VoidFunctionComponent = () => {
const [searchQuery, setSearchQuery] = useState<string>('');
const history = useHistory();

function freeDetail() {
if (detail == null) return;

const { overrides: { image } } = detail;
if (image != null) {
const [, url] = image;
URL.revokeObjectURL(url);
}
}

const setUser: Dispatch<SetStateAction<IUserStatic | null | undefined>> = (value) => {
let newState: IUserStatic | null | undefined;
if (typeof value === 'function') newState = value(userState);
Expand All @@ -290,7 +272,6 @@ const AppComponent: React.VoidFunctionComponent = () => {
if (detail?.base?.id != null && newState != null) {
newBase = newState.cards.find((card) => card.id === detail?.base?.id);
}
freeDetail();
setDetail(newBase == null
? null
: {
Expand Down Expand Up @@ -332,7 +313,6 @@ const AppComponent: React.VoidFunctionComponent = () => {
},
showCardDetail(card) {
if (userState == null) throw new Error('userState is nullish');
freeDetail();
if (card == null) {
setDetail(null);
} else {
Expand Down
2 changes: 1 addition & 1 deletion web/src/controllers/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface ICardPropertiesCommon {
}

export interface ICardProperties extends ICardPropertiesCommon {
image: [Blob, string] | null;
image: string | null;
fields: readonly ICardFieldProperties[];
}

Expand Down

0 comments on commit 0ecdea0

Please sign in to comment.