Chore: move initializeFilesystem back to the register function (#70)

This commit is contained in:
Andrew Vivash 2022-10-12 09:10:11 -07:00 committed by GitHub
parent 4051179646
commit 43fda68523
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 47 deletions

View File

@ -99,6 +99,7 @@ The app template is designed to be easy for you to _make it your own._ Here's ho
If you're not building an image gallery, you don't need the gallery demo code, except perhaps to learn from. To get rid of it, delete:
- `/src/routes/gallery`
- the `initializeFilesystem` function in `/src/lib/auth/account.ts` creates directories used by WNFS. Change those to what you need for your app or delete them if you're not using WNFS.
👏 You're ready to start adding custom functionality! 🚀

View File

@ -1,8 +1,11 @@
import * as webnative from 'webnative'
import type FileSystem from 'webnative/fs/index'
import { asyncDebounce } from '$lib/utils'
import { filesystemStore, sessionStore } from '../../stores'
import { getBackupStatus } from '$lib/auth/backup'
import { AREAS } from '$routes/gallery/stores'
import { GALLERY_DIRS } from '$routes/gallery/lib/gallery'
export const isUsernameValid = async (username: string): Promise<boolean> => {
return webnative.account.isUsernameValid(username)
@ -27,6 +30,9 @@ export const register = async (username: string): Promise<boolean> => {
const fs = await webnative.bootstrapRootFileSystem()
filesystemStore.set(fs)
// TODO Remove if only public and private directories are needed
await initializeFilesystem(fs)
sessionStore.update(session => ({
...session,
username,
@ -36,6 +42,16 @@ export const register = async (username: string): Promise<boolean> => {
return success
}
/**
* Create additional directories and files needed by the app
*
* @param fs FileSystem
*/
const initializeFilesystem = async (fs: FileSystem): Promise<void> => {
await fs.mkdir(webnative.path.directory(...GALLERY_DIRS[AREAS.PUBLIC]))
await fs.mkdir(webnative.path.directory(...GALLERY_DIRS[AREAS.PRIVATE]))
}
export const loadAccount = async (username: string): Promise<void> => {
await checkDataRoot(username)

View File

@ -1,47 +0,0 @@
<script lang="ts">
import { onDestroy } from 'svelte'
import * as wn from 'webnative'
import type FileSystem from 'webnative/fs/index'
import { filesystemStore } from '$src/stores'
import { AREAS } from '$routes/gallery/stores'
import { GALLERY_DIRS } from '$routes/gallery/lib/gallery'
let fsCheckCompleted = false
/**
* Create additional directories and files needed by the gallery if they don't exist
*
* @param fs FileSystem
*/
const initializeFilesystem = async (fs: FileSystem): Promise<void> => {
const publicPathExists = await fs.exists(
wn.path.file(...GALLERY_DIRS[AREAS.PUBLIC])
)
const privatePathExists = await fs.exists(
wn.path.file(...GALLERY_DIRS[AREAS.PRIVATE])
)
if (!publicPathExists) {
await fs.mkdir(wn.path.directory(...GALLERY_DIRS[AREAS.PUBLIC]))
}
if (!privatePathExists) {
await fs.mkdir(wn.path.directory(...GALLERY_DIRS[AREAS.PRIVATE]))
}
fsCheckCompleted = true
}
const unsubscribe = filesystemStore.subscribe(async fs => {
if (!fsCheckCompleted && !!fs) {
await initializeFilesystem(fs)
}
})
onDestroy(unsubscribe)
</script>
{#if fsCheckCompleted}
<slot />
{/if}