Skip to content

Commit

Permalink
refactor: syncfs
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Feb 21, 2025
1 parent ea540f9 commit 1884ffa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/components/ProjectTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,11 @@ async function executeExport(entry: TreeEntry | null) {
try {
const proj = await getProject();
const fsPath = await proj.syncFs(path);
if (isFolder) {
const fsPath = await proj.syncFs(path);
const handle = await opfs.getDirectoryHandle(fsPath);
await opfs.download(handle);
} else {
const fsPath = await proj.syncFsFile(path);
const handle = await opfs.getFileHandle(fsPath);
await opfs.download(handle);
}
Expand Down
8 changes: 6 additions & 2 deletions src/services/workspace-proj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,12 @@ export class WorkspaceProj {
* @returns The path to the project in the OPFS + prefix.
*/
public async syncFs(prefix: string = '/'): Promise<string> {
if (prefix[prefix.length - 1] !== '/') throw new Error('Prefix must end with /');
if (prefix[prefix.length - 1] !== '/') {
return this.syncFsFile(prefix);
}

// Get the folder in the FS
prefix = utils.normalizePath(prefix);
const basedir = `${this.manager.group}/${this.name}`;
const folder = await opfs.getDirectoryHandle(basedir + prefix, { create: true });

Expand Down Expand Up @@ -391,7 +395,7 @@ export class WorkspaceProj {
*
* @param path Path to the file in the project.
*/
public async syncFsFile(path: string): Promise<string> {
private async syncFsFile(path: string): Promise<string> {
if (path.endsWith('/')) throw new Error('Cannot sync folder as file');

// Get metadata for the file
Expand Down

0 comments on commit 1884ffa

Please sign in to comment.