Add profile uploading + cleanup
This commit is contained in:
@@ -37,7 +37,7 @@
|
||||
<div class="flex md:order-2 gap-5">
|
||||
<UserSettingsSolid class="hover:text-primary-700" on:click={openSettings} />
|
||||
<UploadSolid class="hover:text-primary-700" on:click={() => (uploadModalOpen = true)} />
|
||||
<CloudArrowUpOutline class="hover:text-primary-700" on:click={() => goto('/cloud')} />
|
||||
<!-- <CloudArrowUpOutline class="hover:text-primary-700" on:click={() => goto('/cloud')} /> -->
|
||||
</div>
|
||||
</Navbar>
|
||||
</div>
|
||||
|
||||
32
src/lib/util/cloud.ts
Normal file
32
src/lib/util/cloud.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
type FileInfo = {
|
||||
accessToken: string;
|
||||
metadata: any;
|
||||
fileId?: string;
|
||||
localStorageId: string;
|
||||
type: string;
|
||||
}
|
||||
|
||||
const FILES_API_URL = 'https://www.googleapis.com/upload/drive/v3/files';
|
||||
|
||||
export async function uploadFile({ accessToken, fileId, localStorageId, metadata, type }: FileInfo) {
|
||||
const json = localStorage.getItem(localStorageId) || '';
|
||||
const blob = new Blob([json], { type });
|
||||
|
||||
const form = new FormData();
|
||||
|
||||
form.append('resource', new Blob([JSON.stringify(metadata)], { type }));
|
||||
form.append('file', blob);
|
||||
|
||||
|
||||
const res = await fetch(
|
||||
`${FILES_API_URL}${fileId ? `/${fileId}` : ''}?uploadType=multipart`,
|
||||
{
|
||||
method: fileId ? 'PATCH' : 'POST',
|
||||
headers: new Headers({ Authorization: 'Bearer ' + accessToken }),
|
||||
body: form
|
||||
}
|
||||
);
|
||||
|
||||
return await res.json()
|
||||
}
|
||||
|
||||
@@ -2,4 +2,5 @@ export * from './snackbar';
|
||||
export * from './upload';
|
||||
export * from './misc';
|
||||
export * from './modals';
|
||||
export * from './zip'
|
||||
export * from './zip'
|
||||
export * from './cloud'
|
||||
Reference in New Issue
Block a user