Skip to content

Commit e14a2af

Browse files
authored
feat: integrate @autonomys/file-server package (#452)
* feat: integrate package * chore: update yarn.lock to include new version of @autonomys/file-caching and its dependencies * fix: update import path for ByteRange in files.spec.ts to use @autonomys/file-server * fix: update import path for ByteRange and DownloadMetadata to use @autonomys/file-server * chore: update yarn.lock to reflect version changes for ox and viem packages * fix(test): not expected anymore those fields * fix(test): remove unnecessary fields from metadata expectation in files.spec.ts * fix(test): convert size to string in publicUrl.spec.ts and update metadata expectation in files.spec.ts * fix: update import path for ByteRange in sync.ts and GetObject.ts to use @autonomys/file-server
1 parent 216c9ca commit e14a2af

File tree

20 files changed

+1759
-2414
lines changed

20 files changed

+1759
-2414
lines changed

backend/__tests__/e2e/objects/publicUrl.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('Public URL', () => {
5858

5959
expect(metadata).toMatchObject({
6060
type: 'file',
61-
dataCid: publishedObject.cid,
61+
size: BigInt(content.length).toString(),
6262
})
6363

6464
const pendingCredits =

backend/__tests__/unit/useCases/files.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { jest } from '@jest/globals'
22
import { ObjectUseCases } from '../../../src/core/objects/object.js'
33
import { FilesUseCases } from '../../../src/core/objects/files/index.js'
44
import { DownloadUseCase } from '../../../src/core/downloads/index.js'
5-
import { ByteRange } from '@autonomys/file-caching'
5+
import { ByteRange } from '@autonomys/file-server'
66
import { OffchainMetadata } from '@autonomys/auto-dag-data'
77
import { NotAcceptableError } from '../../../src/errors/index.js'
88
import { err, ok } from 'neverthrow'
@@ -42,7 +42,9 @@ describe('FilesUseCases', () => {
4242
}
4343

4444
// Expect not to throw
45-
expect(result.value.metadata).toEqual(metadata)
45+
expect(result.value.metadata).toMatchObject({
46+
type: metadata.type,
47+
})
4648
})
4749

4850
it('should block file upload', async () => {

backend/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
"@auto-drive/models": "workspace:*",
2222
"@auto-drive/s3": "workspace:*",
2323
"@auto-files/rpc-apis": "workspace:*",
24-
"@autonomys/asynchronous": "^1.5.12",
25-
"@autonomys/auto-dag-data": "^1.5.12",
26-
"@autonomys/auto-drive": "^1.5.12",
27-
"@autonomys/auto-files": "^1.5.12",
28-
"@autonomys/file-caching": "^1.5.12",
29-
"@autonomys/rpc": "^1.5.12",
24+
"@autonomys/asynchronous": "^1.5.14",
25+
"@autonomys/auto-dag-data": "^1.5.14",
26+
"@autonomys/auto-drive": "^1.5.14",
27+
"@autonomys/auto-files": "^1.5.14",
28+
"@autonomys/file-server": "1.5.14",
29+
"@autonomys/rpc": "^1.5.14",
3030
"@keyvhq/sqlite": "^2.1.6",
3131
"@polkadot/api": "^15.8.1",
3232
"@polkadot/types": "^15.8.1",

backend/src/app/controllers/download.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import {
99
handleAuth,
1010
handleOptionalAuth,
1111
} from '../../infrastructure/services/auth/express.js'
12-
import { handleDownloadResponseHeaders } from '../../shared/httpHandlers/download.js'
1312
import { createLogger } from '../../infrastructure/drivers/logger.js'
1413
import { downloadService } from '../../infrastructure/services/download/index.js'
15-
import { getByteRange } from '../../shared/utils/http.js'
14+
import {
15+
getByteRange,
16+
handleDownloadResponseHeaders,
17+
} from '@autonomys/file-server'
1618
import { handleError } from '../../errors/index.js'
1719
import {
1820
handleInternalError,
@@ -129,7 +131,9 @@ downloadController.get(
129131
byteRange: resultingByteRange,
130132
startDownload,
131133
} = downloadResult.value
132-
handleDownloadResponseHeaders(req, res, metadata, resultingByteRange)
134+
handleDownloadResponseHeaders(req, res, metadata, {
135+
byteRange: resultingByteRange,
136+
})
133137

134138
pipeline(await startDownload(), res, (err: Error | null) => {
135139
if (err) {

backend/src/app/controllers/object.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { handleAuth } from '../../infrastructure/services/auth/express.js'
44
import { ObjectUseCases, UploadStatusUseCases } from '../../core/index.js'
55
import { createLogger } from '../../infrastructure/drivers/logger.js'
66
import { asyncSafeHandler } from '../../shared/utils/express.js'
7-
import { handleDownloadResponseHeaders } from '../../shared/httpHandlers/download.js'
7+
import { handleDownloadResponseHeaders } from '@autonomys/file-server'
88
import {
99
handleInternalError,
1010
handleInternalErrorResult,
@@ -384,7 +384,9 @@ objectController.get(
384384
return
385385
}
386386

387-
handleDownloadResponseHeaders(req, res, metadata, resultingByteRange)
387+
handleDownloadResponseHeaders(req, res, metadata, {
388+
byteRange: resultingByteRange,
389+
})
388390

389391
pipeline(await startDownload(), res, (err) => {
390392
if (err) {

backend/src/app/controllers/s3/s3.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { S3UseCases } from '../../../core/s3/index.js'
22
import { handleError } from '../../../errors/index.js'
33
import { handleS3Auth } from '../../../infrastructure/services/auth/s3.js'
4-
import { getByteRange } from '../../../shared/utils/http.js'
54
import {
5+
getByteRange,
66
handleDownloadResponseHeaders,
77
handleS3DownloadResponseHeaders,
8-
} from '../../../shared/httpHandlers/download.js'
8+
} from '@autonomys/file-server'
99
import { pipeline } from 'stream'
1010
import { createLogger } from '../../../infrastructure/drivers/logger.js'
1111
import { Request, Response } from 'express'
@@ -60,7 +60,9 @@ export const getObjectHandler = async (req: Request, res: Response) => {
6060
byteRange: resultingByteRange,
6161
} = downloadResult.value
6262

63-
handleDownloadResponseHeaders(req, res, metadata, resultingByteRange)
63+
handleDownloadResponseHeaders(req, res, metadata, {
64+
byteRange: resultingByteRange,
65+
})
6466
handleS3DownloadResponseHeaders(req, res, metadata)
6567

6668
pipeline(await startDownload(), res, (err: Error | null) => {
@@ -93,7 +95,9 @@ export const headObjectHandler = async (req: Request, res: Response) => {
9395
}
9496
const { metadata, byteRange: resultingByteRange } = downloadResult.value
9597

96-
handleDownloadResponseHeaders(req, res, metadata, resultingByteRange)
98+
handleDownloadResponseHeaders(req, res, metadata, {
99+
byteRange: resultingByteRange,
100+
})
97101
handleS3DownloadResponseHeaders(req, res, metadata)
98102

99103
res.sendStatus(204)

backend/src/core/downloads/sync.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ByteRange } from '@autonomys/file-caching'
1+
import { ByteRange, DownloadMetadataFactory } from '@autonomys/file-server'
22
import { downloadService } from '../../infrastructure/services/download/index.js'
33
import {
44
DownloadOptions,
@@ -87,7 +87,7 @@ const downloadObjectByUser = async (
8787
).valueOf()
8888

8989
return ok({
90-
metadata,
90+
metadata: DownloadMetadataFactory.fromOffchainMetadata(metadata),
9191
byteRange: options.byteRange ? resultingByteRange : undefined,
9292
startDownload: async () => {
9393
logger.trace(
@@ -145,7 +145,7 @@ const downloadObjectByAnonymous = async (
145145
logger.info('downloadObjectByAnonymous authorized (cid=%s)', cid)
146146

147147
return ok({
148-
metadata,
148+
metadata: DownloadMetadataFactory.fromOffchainMetadata(metadata),
149149
byteRange: options.byteRange ? resultingByteRange : undefined,
150150
startDownload: async () => {
151151
logger.trace('downloadObjectByAnonymous starting stream (cid=%s)', cid)

backend/src/core/objects/files/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DownloadServiceOptions } from '@auto-drive/models'
33
import { ObjectUseCases } from '../object.js'
44
import { Readable } from 'stream'
55
import { createLogger } from '../../../infrastructure/drivers/logger.js'
6-
import { ByteRange } from '@autonomys/file-caching'
6+
import { ByteRange } from '@autonomys/file-server'
77
import { sliceReadable } from '../../../shared/utils/readable.js'
88
import { DBObjectFetcher, FileGatewayObjectFetcher } from './fetchers.js'
99
import { composeNodesDataAsFileReadable } from './nodeComposer.js'

backend/src/infrastructure/services/download/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { forkAsyncIterable, forkStream } from '@autonomys/asynchronous'
66
import {
77
createFileCache,
88
defaultMemoryAndSqliteConfig,
9-
} from '@autonomys/file-caching'
9+
} from '@autonomys/file-server'
1010
import { config } from '../../../config.js'
1111
import { Readable } from 'stream'
1212
import { DownloadServiceOptions, DownloadStatus } from '@auto-drive/models'

backend/src/shared/httpHandlers/download.ts

Lines changed: 0 additions & 114 deletions
This file was deleted.

0 commit comments

Comments
 (0)