Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement auto-drive SDK #91

Merged
merged 11 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/backend-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"

- name: Install Yarn
run: npm install --global yarn
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frontend-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"

- name: Install Yarn
run: npm install --global yarn
Expand Down
Binary file modified backend/.yarn/install-state.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion backend/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.8'

services:
app:
image: node:18
image: node:20
container_name: node_app
working_dir: /usr/src/app
volumes:
Expand Down
3 changes: 2 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"lint": "eslint . "
},
"dependencies": {
"@autonomys/auto-drive": "^0.7.4",
"@autonomys/auto-dag-data": "^1.0.5",
"@autonomys/auto-drive": "^1.0.5",
"@polkadot/api": "^12.3.1",
"@polkadot/types": "^13.0.1",
"@polkadot/util-crypto": "^13.0.2",
Expand Down
16 changes: 2 additions & 14 deletions backend/src/controllers/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ uploadController.post('/file', async (req, res) => {
})
}

if (typeof mimeType !== 'string') {
return res.status(400).json({
error: 'Missing or invalid field: mimeType',
})
}

const safeUploadOptions = z
.union([uploadOptionsSchema, z.null()])
.safeParse(uploadOptions)
Expand All @@ -41,7 +35,7 @@ uploadController.post('/file', async (req, res) => {
const upload = await UploadsUseCases.createFileUpload(
user,
filename,
mimeType,
mimeType ?? null,
safeUploadOptions.data,
)

Expand Down Expand Up @@ -109,12 +103,6 @@ uploadController.post('/folder/:uploadId/file', async (req, res) => {
})
}

if (typeof mimeType !== 'string') {
return res.status(400).json({
error: 'Missing or invalid field: mimeType',
})
}

if (typeof relativeId !== 'string') {
return res.status(400).json({
error: 'Missing or invalid field: relativeId',
Expand All @@ -136,7 +124,7 @@ uploadController.post('/folder/:uploadId/file', async (req, res) => {
uploadId,
relativeId,
name,
mimeType,
mimeType ?? null,
safeUploadOptions.data,
)

Expand Down
2 changes: 1 addition & 1 deletion backend/src/models/objects/chunkInfo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cidOfNode, cidToString } from '@autonomys/auto-drive'
import { cidOfNode, cidToString } from '@autonomys/auto-dag-data'
import { encode, PBNode } from '@ipld/dag-pb'

export interface ChunkInfo {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/models/objects/nodeWithMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IPLDNodeData } from '@autonomys/auto-drive'
import { IPLDNodeData } from '@autonomys/auto-dag-data'

export interface NodeWithMetadata {
cid: string
Expand Down
2 changes: 1 addition & 1 deletion backend/src/models/objects/object.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OffchainMetadata } from '@autonomys/auto-drive'
import { OffchainMetadata } from '@autonomys/auto-dag-data'

export interface ObjectInformation {
cid: string
Expand Down
2 changes: 1 addition & 1 deletion backend/src/models/uploads/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
FileUploadOptions,
OffchainFileMetadata,
OffchainFolderMetadata,
} from '@autonomys/auto-drive'
} from '@autonomys/auto-dag-data'

export enum UploadType {
FILE = 'file',
Expand Down
2 changes: 1 addition & 1 deletion backend/src/repositories/objects/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OffchainMetadata } from '@autonomys/auto-drive'
import { OffchainMetadata } from '@autonomys/auto-dag-data'
import { getDatabase } from '../../drivers/pg.js'
import { PaginatedResult } from '../../useCases/objects/common.js'

Expand Down
2 changes: 1 addition & 1 deletion backend/src/repositories/objects/nodes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MetadataType } from '@autonomys/auto-drive'
import { MetadataType } from '@autonomys/auto-dag-data'
import { getDatabase } from '../../drivers/pg.js'
import pgFormat from 'pg-format'

Expand Down
2 changes: 1 addition & 1 deletion backend/src/repositories/uploads/blockstore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MetadataType } from '@autonomys/auto-drive'
import { MetadataType } from '@autonomys/auto-dag-data'
import { getDatabase } from '../../drivers/pg.js'

interface BlockstoreEntry {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/repositories/uploads/uploads.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FileUploadOptions } from '@autonomys/auto-drive'
import { FileUploadOptions } from '@autonomys/auto-dag-data'
import { getDatabase } from '../../drivers/pg.js'
import { FolderTreeFolder } from '../../models/objects/folderTree.js'
import { UploadStatus, UploadType } from '../../models/uploads/upload.js'
Expand Down
2 changes: 1 addition & 1 deletion backend/src/services/uploadProcessorCache/blockstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
decodeIPLDNodeData,
MetadataType,
stringToCid,
} from '@autonomys/auto-drive'
} from '@autonomys/auto-dag-data'
import { Pair } from 'interface-blockstore'
import { AwaitIterable } from 'interface-store'
import { CID } from 'multiformats/cid'
Expand Down
2 changes: 1 addition & 1 deletion backend/src/useCases/objects/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
folderMetadata,
MetadataType,
OffchainFileMetadata,
} from '@autonomys/auto-drive'
} from '@autonomys/auto-dag-data'
import PizZip from 'pizzip'
import { User } from '../../models/users/index.js'
import {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/useCases/objects/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
encodeNode,
IPLDNodeData,
MetadataType,
} from '@autonomys/auto-drive'
} from '@autonomys/auto-dag-data'
import { PBNode } from '@ipld/dag-pb'
import { CID } from 'multiformats'
import { nodesRepository } from '../../repositories/index.js'
Expand Down
2 changes: 1 addition & 1 deletion backend/src/useCases/objects/object.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OffchainMetadata } from '@autonomys/auto-drive'
import { OffchainMetadata } from '@autonomys/auto-dag-data'
import { User } from '../../models/users/index.js'
import {
getObjectSummary,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/useCases/objects/transactionResults.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cidToString } from '@autonomys/auto-drive'
import { cidToString } from '@autonomys/auto-dag-data'
import { CID } from 'multiformats'
import { transactionResultsRepository } from '../../repositories/index.js'
import { TransactionResult } from '../../models/objects/index.js'
Expand Down
12 changes: 5 additions & 7 deletions backend/src/useCases/uploads/blockstore.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {
ChunkInfo,
cidToString,
DEFAULT_MAX_LINK_PER_NODE,
MetadataType,
processFolderToIPLDFormat,
stringToCid,
} from '@autonomys/auto-drive'
} from '@autonomys/auto-dag-data'
import { blockstoreRepository } from '../../repositories/uploads/index.js'
import { CID } from 'multiformats'
import {
FolderUpload,
Upload,
UploadOptions,
UploadStatus,
UploadType,
} from '../../models/uploads/upload.js'
Expand Down Expand Up @@ -123,16 +123,14 @@ const processFileTree = async (

const totalSize = childrenNodesLengths.reduce((acc, curr) => acc + curr, 0)

const uploadOptions: Partial<UploadOptions> = {
...currentUpload.uploadOptions,
}

return processFolderToIPLDFormat(
blockstore,
childrenCids,
fileTree.name,
totalSize,
uploadOptions,
{
maxLinkPerNode: DEFAULT_MAX_LINK_PER_NODE,
},
)
}

Expand Down
13 changes: 9 additions & 4 deletions backend/src/useCases/uploads/uploadProcessing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import {
cidOfNode,
createFileChunkIpldNode,
DEFAULT_MAX_CHUNK_SIZE,
DEFAULT_MAX_LINK_PER_NODE,
fileBuilders,
MetadataType,
processBufferToIPLDFormatFromChunks,
processChunksToIPLDFormat,
} from '@autonomys/auto-drive'
} from '@autonomys/auto-dag-data'
import { FolderUpload, UploadType } from '../../models/uploads/upload.js'
import { BlockstoreUseCases } from './blockstore.js'
import { mapTableToModel } from './uploads.js'
Expand Down Expand Up @@ -93,15 +94,19 @@ const completeFileProcessing = async (uploadId: string): Promise<CID> => {
const uploadedSize =
(await filePartsRepository.getUploadFilePartsSize(uploadId)) ?? 0

const uploadOptions = {
maxLinkPerNode: DEFAULT_MAX_LINK_PER_NODE,
maxChunkSize: DEFAULT_MAX_CHUNK_SIZE,
...(upload?.upload_options ?? {}),
}

return processBufferToIPLDFormatFromChunks(
blockstore,
blockstore.getFilteredMany(MetadataType.FileChunk),
upload?.name,
uploadedSize,
fileBuilders,
{
...(upload?.upload_options ?? {}),
},
uploadOptions,
)
}

Expand Down
6 changes: 3 additions & 3 deletions backend/src/useCases/uploads/uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { FileProcessingUseCase as UploadingProcessingUseCase } from './uploadPro
import { fileProcessingInfoRepository } from '../../repositories/uploads/fileProcessingInfo.js'
import { FilesUseCases } from '../objects/files.js'
import { NodesUseCases } from '../objects/index.js'
import { cidToString, FileUploadOptions } from '@autonomys/auto-drive'
import { cidToString, FileUploadOptions } from '@autonomys/auto-dag-data'

export const mapTableToModel = (upload: UploadEntry): Upload => {
return {
Expand Down Expand Up @@ -57,7 +57,7 @@ const initFileProcessing = async (upload: UploadEntry): Promise<void> => {
const createFileUpload = async (
user: User,
name: string,
mimeType: string,
mimeType: string | null,
uploadOptions: FileUploadOptions | null,
rootId?: string | null,
relativeId?: string | null,
Expand Down Expand Up @@ -114,7 +114,7 @@ const createFileInFolder = async (
uploadId: string,
relativeId: string,
name: string,
mimeType: string,
mimeType: string | null,
uploadOptions: FileUploadOptions | null,
): Promise<FileUpload> => {
const upload = await uploadsRepository.getUploadEntryById(uploadId)
Expand Down
15 changes: 0 additions & 15 deletions backend/src/utils/dataHasher.ts

This file was deleted.

2 changes: 0 additions & 2 deletions backend/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export { hashData } from './dataHasher.js'
export { isJson } from './misc.js'
export { safeCallback } from './safe.js'
8 changes: 0 additions & 8 deletions backend/src/utils/misc.ts

This file was deleted.

2 changes: 0 additions & 2 deletions backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"allowImportingTsExtensions": true,
"outDir": "./dist",
"rootDir": "./src",
"baseUrl": "src",
Expand Down
Loading
Loading