Skip to content

Commit f4251a6

Browse files
committed
feat: get rid of sdk's storage module
1 parent be1435d commit f4251a6

File tree

12 files changed

+178
-113
lines changed

12 files changed

+178
-113
lines changed

packages/apps/job-launcher/server/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"experimentalDecorators": true,
88
"allowSyntheticDefaultImports": true,
99
"allowJs": true,
10-
"target": "ES2020",
10+
"target": "ES2022",
1111
"sourceMap": true,
1212
"outDir": "./dist",
1313
"baseUrl": "./",

packages/apps/reputation-oracle/server/docker-compose.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ services:
2626
ports:
2727
- 9001:9001
2828
- 9000:9000
29-
environment:
30-
MINIO_ROOT_USER: ${S3_ACCESS_KEY}
31-
MINIO_ROOT_PASSWORD: ${S3_SECRET_KEY}
3229
entrypoint: 'sh'
3330
command:
34-
-c "mkdir -p /data/reputation && minio server /data --console-address ':9001'"
31+
-c "minio server /data --console-address ':9001'"
3532
healthcheck:
3633
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
3734
interval: 5s
@@ -45,7 +42,7 @@ services:
4542
condition: service_healthy
4643
entrypoint: >
4744
/bin/sh -c "
48-
/usr/bin/mc config host add myminio http://minio:9000 ${S3_ACCESS_KEY} ${S3_SECRET_KEY};
45+
/usr/bin/mc config host add myminio http://minio:9000 minioadmin minioadmin;
4946
/usr/bin/mc mb myminio/reputation;
5047
/usr/bin/mc anonymous set public myminio/reputation;
5148
"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export class BaseError extends Error {
2+
constructor(message: string, cause?: unknown) {
3+
const errorOptions: ErrorOptions = {};
4+
if (cause) {
5+
errorOptions.cause = cause;
6+
}
7+
8+
super(message, errorOptions);
9+
this.name = this.constructor.name;
10+
}
11+
}

packages/apps/reputation-oracle/server/src/modules/payout/payout.service.spec.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ describe('PayoutService', () => {
114114
job_bounty: '10',
115115
};
116116

117-
jest.spyOn(storageService, 'download').mockResolvedValue(manifest);
117+
jest
118+
.spyOn(storageService, 'downloadJsonLikeData')
119+
.mockResolvedValue(manifest);
118120

119121
const processing_results = {
120122
recipients: [MOCK_ADDRESS],
@@ -146,7 +148,9 @@ describe('PayoutService', () => {
146148
requestType: JobRequestType.FORTUNE,
147149
};
148150

149-
jest.spyOn(storageService, 'download').mockResolvedValue(manifest);
151+
jest
152+
.spyOn(storageService, 'downloadJsonLikeData')
153+
.mockResolvedValue(manifest);
150154

151155
const processing_results = {
152156
recipients: [MOCK_ADDRESS],
@@ -188,7 +192,7 @@ describe('PayoutService', () => {
188192
];
189193

190194
jest
191-
.spyOn(storageService, 'download')
195+
.spyOn(storageService, 'downloadJsonLikeData')
192196
.mockResolvedValue(intermediateResults);
193197

194198
const escrowAddress = MOCK_ADDRESS;
@@ -220,7 +224,7 @@ describe('PayoutService', () => {
220224
];
221225

222226
jest
223-
.spyOn(storageService, 'download')
227+
.spyOn(storageService, 'downloadJsonLikeData')
224228
.mockResolvedValue(intermediateResults);
225229

226230
const escrowAddress = MOCK_ADDRESS;
@@ -284,7 +288,9 @@ describe('PayoutService', () => {
284288
],
285289
};
286290

287-
jest.spyOn(storageService, 'download').mockResolvedValue(results);
291+
jest
292+
.spyOn(storageService, 'downloadJsonLikeData')
293+
.mockResolvedValue(results);
288294

289295
jest
290296
.spyOn(storageService, 'copyFileFromURLToBucket')

packages/apps/reputation-oracle/server/src/modules/payout/payout.service.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ export class PayoutService {
5555
);
5656
}
5757

58-
const manifest = await this.storageService.download(manifestUrl);
58+
const manifest =
59+
await this.storageService.downloadJsonLikeData(manifestUrl);
5960

6061
const requestType = getRequestType(manifest);
6162

@@ -141,7 +142,7 @@ export class PayoutService {
141142
const intermediateResultsUrl =
142143
await escrowClient.getIntermediateResultsUrl(escrowAddress);
143144

144-
const intermediateResults = (await this.storageService.download(
145+
const intermediateResults = (await this.storageService.downloadJsonLikeData(
145146
intermediateResultsUrl,
146147
)) as FortuneFinalResult[];
147148

@@ -206,9 +207,10 @@ export class PayoutService {
206207
chainId,
207208
`${intermediateResultsUrl}/${CVAT_RESULTS_ANNOTATIONS_FILENAME}`,
208209
);
209-
const annotations: CvatAnnotationMeta = await this.storageService.download(
210-
`${intermediateResultsUrl}/${CVAT_VALIDATION_META_FILENAME}`,
211-
);
210+
const annotations: CvatAnnotationMeta =
211+
await this.storageService.downloadJsonLikeData(
212+
`${intermediateResultsUrl}/${CVAT_VALIDATION_META_FILENAME}`,
213+
);
212214

213215
// If annotation meta does not exist
214216
if (annotations && Array.isArray(annotations) && annotations.length === 0) {

packages/apps/reputation-oracle/server/src/modules/reputation/reputation.service.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ describe('ReputationService', () => {
142142
};
143143

144144
jest
145-
.spyOn(storageService, 'download')
145+
.spyOn(storageService, 'downloadJsonLikeData')
146146
.mockResolvedValueOnce(manifest) // Mock manifest
147147
.mockResolvedValueOnce([]); // Mock final results
148148

@@ -170,7 +170,7 @@ describe('ReputationService', () => {
170170
];
171171

172172
jest
173-
.spyOn(storageService, 'download')
173+
.spyOn(storageService, 'downloadJsonLikeData')
174174
.mockResolvedValueOnce(manifest)
175175
.mockResolvedValueOnce(finalResults);
176176

@@ -243,7 +243,7 @@ describe('ReputationService', () => {
243243
}));
244244

245245
jest
246-
.spyOn(storageService, 'download')
246+
.spyOn(storageService, 'downloadJsonLikeData')
247247
.mockResolvedValueOnce(manifest) // Mock manifest
248248
.mockResolvedValueOnce([]); // Mock final results
249249

@@ -294,7 +294,7 @@ describe('ReputationService', () => {
294294
};
295295

296296
jest
297-
.spyOn(storageService, 'download')
297+
.spyOn(storageService, 'downloadJsonLikeData')
298298
.mockResolvedValueOnce(manifest)
299299
.mockResolvedValueOnce(annotationMeta);
300300

packages/apps/reputation-oracle/server/src/modules/reputation/reputation.service.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ export class ReputationService {
6565
);
6666
}
6767

68-
const manifest = await this.storageService.download(manifestUrl);
68+
const manifest =
69+
await this.storageService.downloadJsonLikeData(manifestUrl);
6970

7071
const requestType = getRequestType(manifest);
7172

@@ -160,7 +161,8 @@ export class ReputationService {
160161
const escrowClient = await EscrowClient.build(signer);
161162

162163
const finalResultsUrl = await escrowClient.getResultsUrl(escrowAddress);
163-
const finalResults = await this.storageService.download(finalResultsUrl);
164+
const finalResults =
165+
await this.storageService.downloadJsonLikeData(finalResultsUrl);
164166

165167
if (finalResults.length === 0) {
166168
throw new ControlledError(
@@ -202,9 +204,10 @@ export class ReputationService {
202204
const intermediateResultsUrl =
203205
await escrowClient.getIntermediateResultsUrl(escrowAddress);
204206

205-
const annotations: CvatAnnotationMeta = await this.storageService.download(
206-
`${intermediateResultsUrl}/${CVAT_VALIDATION_META_FILENAME}`,
207-
);
207+
const annotations: CvatAnnotationMeta =
208+
await this.storageService.downloadJsonLikeData(
209+
`${intermediateResultsUrl}/${CVAT_VALIDATION_META_FILENAME}`,
210+
);
208211

209212
// If annotation meta does not exist
210213
if (annotations && Array.isArray(annotations) && annotations.length === 0) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { BaseError } from '../../common/errors/base';
2+
3+
export class FileDownloadError extends BaseError {
4+
public readonly location: string;
5+
6+
constructor(location: string, cause?: unknown) {
7+
super('Failed to download file', cause);
8+
9+
this.location = location;
10+
}
11+
}
12+
13+
export class InvalidFileUrl extends FileDownloadError {
14+
constructor(url: string) {
15+
super(url);
16+
this.message = 'Invalid file URL';
17+
}
18+
}
19+
20+
export class FileNotFoundError extends FileDownloadError {
21+
constructor(location: string) {
22+
super(location);
23+
this.message = 'File not found';
24+
}
25+
}

0 commit comments

Comments
 (0)