Skip to content

Commit

Permalink
Merge pull request #68 from StarfilesFileSharing/alpha
Browse files Browse the repository at this point in the history
Better web support
  • Loading branch information
QuixThe2nd authored Oct 25, 2024
2 parents 20bf595 + f2c3d2f commit 4131309
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@starfiles/hydrafiles",
"version": "0.3.3",
"version": "0.3.4",
"description": "The headless storage network.",
"main": "src/hydrafiles.ts",
"exports": {
Expand Down
9 changes: 5 additions & 4 deletions src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ async function getFileHandle(directoryHandle: DirectoryHandle, path: string, tou

for (let i = 0; i < parts.length; i++) {
const part = parts[i];
console.log("zzzz", parts, i, part);

if (i === parts.length - 1) return await currentHandle.getFileHandle(part, { create: touch });
else currentHandle = await currentHandle.getDirectoryHandle(part, { create: true });
Expand All @@ -43,14 +42,15 @@ class FS {
};

mkdir = async (path: string) => {
if (await this.exists(path)) return;
console.log(`mkdir ${path}`);
if (await this.exists(path)) return;
if (!this.init) throw new Error("FS not initialized");
if (this.directoryHandle !== undefined) await this.directoryHandle.getDirectoryHandle(path, { create: true });
else await Deno.mkdir(path);
};

readDir = async (path: string): Promise<string[]> => {
console.log(`readdir ${path}`);
if (!this.init) throw new Error("FS not initialized");
const entries: string[] = [];

Expand Down Expand Up @@ -121,11 +121,12 @@ class FS {
};

getFileSize = async (path: string): Promise<number> => {
console.log(`${path} Getting file size`);
if (!this.init) throw new Error("FS not initialized");

if (this.directoryHandle !== undefined) {
try {
const fileHandle = await this.directoryHandle.getFileHandle(path);
const fileHandle = await getFileHandle(this.directoryHandle, path);
const file = await fileHandle.getFile();
return file.size; // Return file size in bytes
} catch (e) {
Expand All @@ -146,7 +147,7 @@ class FS {

if (this.directoryHandle !== undefined) {
try {
const fileHandle = await this.directoryHandle.getFileHandle(path);
const fileHandle = await getFileHandle(this.directoryHandle, path);
await fileHandle.remove(); // Remove the file
} catch (e) {
const error = e as Error;
Expand Down

0 comments on commit 4131309

Please sign in to comment.