Skip to content

Commit

Permalink
persist local exported canvas url
Browse files Browse the repository at this point in the history
  • Loading branch information
yosoyubik committed Jul 17, 2021
1 parent 6fadcca commit a60dd27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 5 additions & 3 deletions ui/src/components/OptionsMenu.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import store, { leaveCanvas, makePublic } from '../store';
import store, { leaveCanvas, makePublic, updateImageURL } from '../store';
import { PutObjectCommand } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import copy from 'clipboard-copy';
Expand Down Expand Up @@ -125,9 +125,11 @@
const { $metadata } = await $store.s3.client.send(params);
if ($metadata.httpStatusCode === 200) {
const signedUrl = await getSignedUrl($store.s3.client, params);
console.log(signedUrl);
fileURL = signedUrl.split('?')[0];
$store.api.save(location, name, fileURL);
$store.api.save(location, name, fileURL).then(() => {
console.log('[image file saved]', signedUrl);
updateImageURL(location, name, fileURL);
});
} else {
console.log('error');
}
Expand Down
13 changes: 10 additions & 3 deletions ui/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,19 @@ export function makePublic(name: string): void {
};
}
);
}

export function updateImageURL(
location: string,
name: string,
url: string
): void {
update(
($store): StoreState => {
const canvas = `~${$store.ship}/${name}`;
const canvas = `${location}/${name}`;
$store.canvas[canvas].metadata.file = url;
return {
...$store,
name: canvas
...$store
};
}
);
Expand Down

0 comments on commit a60dd27

Please sign in to comment.