Skip to content

Commit 5e69b7d

Browse files
committed
added GetFolderSize
1 parent 4e2b8c6 commit 5e69b7d

File tree

7 files changed

+68
-1
lines changed

7 files changed

+68
-1
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ dependencies {
9494
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
9595
//noinspection GradleDynamicVersion
9696
implementation "com.facebook.react:react-native:+"
97-
implementation 'com.github.functionland:fula-build-aar:v1.44.0' // From jitpack.io
97+
implementation 'com.github.functionland:fula-build-aar:v1.45.0' // From jitpack.io
9898
implementation 'com.github.functionland:wnfs-android:v1.8.1' // From jitpack.io
9999
implementation 'commons-io:commons-io:20030203.000550'
100100
implementation 'commons-codec:commons-codec:1.15'

android/src/main/java/land/fx/fula/FulaModule.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,22 @@ public void fetchContainerLogs(String containerName, String tailCount, Promise p
15061506
});
15071507
}
15081508

1509+
@ReactMethod
1510+
public void getFolderSize(String folderPath, Promise promise) {
1511+
ThreadUtils.runOnExecutor(() -> {
1512+
Log.d("ReactNative", "getFolderSize");
1513+
try {
1514+
byte[] result = this.fula.getFolderSize(folderPath);
1515+
String resultString = toString(result);
1516+
Log.d("ReactNative", "result string="+resultString);
1517+
promise.resolve(resultString);
1518+
} catch (Exception e) {
1519+
Log.d("ReactNative", "an error happened="+e.getMessage());
1520+
promise.reject(e);
1521+
}
1522+
});
1523+
}
1524+
15091525
@ReactMethod
15101526
public void reboot(Promise promise) {
15111527
ThreadUtils.runOnExecutor(() -> {

ios/Fula.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ @interface RCT_EXTERN_MODULE(FulaModule, NSObject)
169169
withResolver:(RCTPromiseResolveBlock)resolve
170170
withRejecter:(RCTPromiseRejectBlock)reject)
171171

172+
RCT_EXTERN_METHOD(getFolderSize:(NSString *)folderPath
173+
withResolver:(RCTPromiseResolveBlock)resolve
174+
withRejecter:(RCTPromiseRejectBlock)reject)
175+
172176
+ (BOOL)requiresMainQueueSetup
173177
{
174178
return NO;

ios/Fula.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,18 @@ class FulaModule: NSObject {
13221322
}
13231323
}
13241324

1325+
@objc(getFolderSize:withResolver:withRejecter:)
1326+
func getFolderSize(folderPath: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
1327+
do {
1328+
let result = try fula!.getFolderSize(folderPath)
1329+
let resultString = result.toUTF8String()!
1330+
resolve(resultString)
1331+
} catch let error {
1332+
print("getFolderSize", error.localizedDescription)
1333+
reject("ERR_FULA", "getFolderSize", error)
1334+
}
1335+
}
1336+
13251337
}
13261338

13271339

src/interfaces/fulaNativeModule.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ interface FulaNativeModule {
120120
containerName: string,
121121
tailCount: string
122122
) => Promise<string>;
123+
getFolderSize: (
124+
folderPath: string
125+
) => Promise<string>;
123126
bloxFreeSpace: () => Promise<string>;
124127
wifiRemoveall: () => Promise<string>;
125128
reboot: () => Promise<string>;

src/protocols/fxblox.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,30 @@ export const fetchContainerLogs = (
117117
});
118118
return res;
119119
};
120+
121+
export const getFolderSize = (
122+
folderPath: string
123+
): Promise<BType.GetFolderPathResponse> => {
124+
console.log('getFolderSize in react-native started');
125+
let res = Fula.getFolderSize(folderPath)
126+
.then((res1) => {
127+
try {
128+
console.log('res1 received');
129+
console.log(res1);
130+
let jsonRes: BType.GetFolderPathResponse = JSON.parse(res1);
131+
return jsonRes;
132+
} catch (e) {
133+
try {
134+
return JSON.parse(res1);
135+
} catch (e1) {
136+
console.error('Error parsing res in getFolderSize:', e1);
137+
throw e1; // Rethrow the error to maintain the rejection state
138+
}
139+
}
140+
})
141+
.catch((err) => {
142+
console.error('Error getFolderSize:', err);
143+
throw err; // Rethrow the error to maintain the rejection state
144+
});
145+
return res;
146+
};

src/types/fxblox.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ export interface FetchContainerLogsResponse {
2020
status: boolean;
2121
msg: string;
2222
}
23+
24+
export interface GetFolderPathResponse {
25+
folder_path: string;
26+
size: string;
27+
}

0 commit comments

Comments
 (0)