Skip to content

Commit

Permalink
added GetFolderSize
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Feb 16, 2024
1 parent 4e2b8c6 commit 5e69b7d
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ dependencies {
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation 'com.github.functionland:fula-build-aar:v1.44.0' // From jitpack.io
implementation 'com.github.functionland:fula-build-aar:v1.45.0' // From jitpack.io
implementation 'com.github.functionland:wnfs-android:v1.8.1' // From jitpack.io
implementation 'commons-io:commons-io:20030203.000550'
implementation 'commons-codec:commons-codec:1.15'
Expand Down
16 changes: 16 additions & 0 deletions android/src/main/java/land/fx/fula/FulaModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,22 @@ public void fetchContainerLogs(String containerName, String tailCount, Promise p
});
}

@ReactMethod
public void getFolderSize(String folderPath, Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "getFolderSize");
try {
byte[] result = this.fula.getFolderSize(folderPath);
String resultString = toString(result);
Log.d("ReactNative", "result string="+resultString);
promise.resolve(resultString);
} catch (Exception e) {
Log.d("ReactNative", "an error happened="+e.getMessage());
promise.reject(e);
}
});
}

@ReactMethod
public void reboot(Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Expand Down
4 changes: 4 additions & 0 deletions ios/Fula.mm
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ @interface RCT_EXTERN_MODULE(FulaModule, NSObject)
withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(getFolderSize:(NSString *)folderPath
withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)

+ (BOOL)requiresMainQueueSetup
{
return NO;
Expand Down
12 changes: 12 additions & 0 deletions ios/Fula.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,18 @@ class FulaModule: NSObject {
}
}

@objc(getFolderSize:withResolver:withRejecter:)
func getFolderSize(folderPath: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
do {
let result = try fula!.getFolderSize(folderPath)
let resultString = result.toUTF8String()!
resolve(resultString)
} catch let error {
print("getFolderSize", error.localizedDescription)
reject("ERR_FULA", "getFolderSize", error)
}
}

}


3 changes: 3 additions & 0 deletions src/interfaces/fulaNativeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ interface FulaNativeModule {
containerName: string,
tailCount: string
) => Promise<string>;
getFolderSize: (
folderPath: string
) => Promise<string>;
bloxFreeSpace: () => Promise<string>;
wifiRemoveall: () => Promise<string>;
reboot: () => Promise<string>;
Expand Down
27 changes: 27 additions & 0 deletions src/protocols/fxblox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,30 @@ export const fetchContainerLogs = (
});
return res;
};

export const getFolderSize = (
folderPath: string
): Promise<BType.GetFolderPathResponse> => {
console.log('getFolderSize in react-native started');
let res = Fula.getFolderSize(folderPath)
.then((res1) => {
try {
console.log('res1 received');
console.log(res1);
let jsonRes: BType.GetFolderPathResponse = JSON.parse(res1);
return jsonRes;
} catch (e) {
try {
return JSON.parse(res1);
} catch (e1) {
console.error('Error parsing res in getFolderSize:', e1);
throw e1; // Rethrow the error to maintain the rejection state
}
}
})
.catch((err) => {
console.error('Error getFolderSize:', err);
throw err; // Rethrow the error to maintain the rejection state
});
return res;
};
5 changes: 5 additions & 0 deletions src/types/fxblox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ export interface FetchContainerLogsResponse {
status: boolean;
msg: string;
}

export interface GetFolderPathResponse {
folder_path: string;
size: string;
}

0 comments on commit 5e69b7d

Please sign in to comment.