diff --git a/README.md b/README.md index aab4ad88..840d8c9f 100644 --- a/README.md +++ b/README.md @@ -606,6 +606,8 @@ Example output: "unixTime": 1631722234, "size": 47, "lastModifiedDate": 1631722217028, + "dataTxId": "vA-BxAS7I6n90cH4Fzsk4cWS3EOPb1KOhj8yeI88dj0", + "dataContentType": "text/plain", "parentFolderId": "29850ab7-56d4-4e1f-a5be-cb86d5513940", "entityId": "e5948327-d6de-4acf-a6fe-e091ecf78d71", "path": "/My Public Folder/test-number-twelve.txt", @@ -624,6 +626,8 @@ Example output: "unixTime": 1631671275, "size": 23, "lastModifiedDate": 1631283389232, + "dataTxId": "UP8THwA_1gvyRqNRqYmTpWvU4-UzNWBN7SiX_AIihg4", + "dataContentType": "text/plain", "parentFolderId": "29850ab7-56d4-4e1f-a5be-cb86d5513940", "entityId": "3274dae9-3487-41eb-94d5-8d5d3d8bc343", "path": "/My Public Folder/wonderful-test-file.txt", diff --git a/package.json b/package.json index 1fe1f91c..9481ab6f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ardrive-cli", - "version": "1.0.1", + "version": "1.0.2", "description": "The ArDrive Command Line Interface (CLI is a Node.js application for terminal-based ArDrive workflows. It also offers utility operations for securely interacting with Arweave wallets and inspecting various Arweave blockchain conditions.", "main": "./lib/index.js", "bin": { diff --git a/src/ardrive.ts b/src/ardrive.ts index a18cfe72..a5a5476a 100644 --- a/src/ardrive.ts +++ b/src/ardrive.ts @@ -727,8 +727,8 @@ export class ArDrive extends ArDriveAnonymous { if (dataSize > Number.MAX_SAFE_INTEGER - 16) { throw new Error(`Max un-encrypted dataSize allowed is ${Number.MAX_SAFE_INTEGER - 16}!`); } - const modulo16 = dataSize % 16; - return dataSize - modulo16 + 16; + + return (dataSize / 16 + 1) * 16; } async uploadPrivateFile( diff --git a/src/arfs_entities.ts b/src/arfs_entities.ts index 2368397b..85c9e430 100644 --- a/src/arfs_entities.ts +++ b/src/arfs_entities.ts @@ -16,9 +16,11 @@ import { EntityID, FileID, FolderID, + JSON_CONTENT_TYPE, TransactionID, UnixTime } from './types'; +import { stubTransactionID } from './utils/stubs'; export class ArFSPublicDrive extends ArFSEntity implements ArFSDriveEntity { constructor( @@ -74,6 +76,8 @@ export class ArFSFileOrFolderEntity extends ArFSEntity implements ArFSFileFolder txId: TransactionID, unixTime: UnixTime, public lastModifiedDate: UnixTime, + public dataTxId: TransactionID, + public dataContentType: DataContentType, readonly parentFolderId: FolderID, readonly entityId: EntityID ) { @@ -105,6 +109,8 @@ export class ArFSPublicFileOrFolderWithPaths extends ArFSFileOrFolderEntity impl entity.txId, entity.unixTime, entity.lastModifiedDate, + entity.dataTxId, + entity.dataContentType, entity.parentFolderId, entity.entityId ); @@ -134,6 +140,8 @@ export class ArFSPrivateFileOrFolderWithPaths extends ArFSFileOrFolderEntity imp entity.txId, entity.unixTime, entity.lastModifiedDate, + entity.dataTxId, + entity.dataContentType, entity.parentFolderId, entity.entityId ); @@ -175,6 +183,8 @@ export class ArFSPublicFile extends ArFSFileOrFolderEntity { txId, unixTime, lastModifiedDate, + dataTxId, + dataContentType, parentFolderId, fileId ); @@ -213,6 +223,8 @@ export class ArFSPrivateFile extends ArFSFileOrFolderEntity { txId, unixTime, lastModifiedDate, + dataTxId, + dataContentType, parentFolderId, fileId ); @@ -245,6 +257,8 @@ export class ArFSPublicFolder extends ArFSFileOrFolderEntity { txId, unixTime, 0, + stubTransactionID, + JSON_CONTENT_TYPE, parentFolderId, entityId ); @@ -278,6 +292,8 @@ export class ArFSPrivateFolder extends ArFSFileOrFolderEntity { txId, unixTime, 0, + stubTransactionID, + JSON_CONTENT_TYPE, parentFolderId, entityId ); diff --git a/src/arfs_prototypes.ts b/src/arfs_prototypes.ts index 98020d38..acb59431 100644 --- a/src/arfs_prototypes.ts +++ b/src/arfs_prototypes.ts @@ -15,7 +15,7 @@ import { } from './arfs_trx_data_types'; import Transaction from 'arweave/node/lib/transaction'; import { ContentType, DrivePrivacy, GQLTagInterface } from 'ardrive-core-js'; -import { DataContentType, DriveID, FileID, FolderID, UnixTime } from './types'; +import { DataContentType, DriveID, FileID, FolderID, JSON_CONTENT_TYPE, PRIVATE_CONTENT_TYPE, UnixTime } from './types'; export abstract class ArFSObjectMetadataPrototype { abstract protectedTags: string[]; @@ -64,7 +64,7 @@ export abstract class ArFSDriveMetaDataPrototype extends ArFSEntityMetaDataProto export class ArFSPublicDriveMetaDataPrototype extends ArFSDriveMetaDataPrototype { readonly privacy: DrivePrivacy = 'public'; - readonly contentType: ContentType = 'application/json'; + readonly contentType: ContentType = JSON_CONTENT_TYPE; constructor(readonly objectData: ArFSPublicDriveTransactionData, readonly driveId: DriveID) { super(); @@ -73,7 +73,7 @@ export class ArFSPublicDriveMetaDataPrototype extends ArFSDriveMetaDataPrototype export class ArFSPrivateDriveMetaDataPrototype extends ArFSDriveMetaDataPrototype { readonly privacy: DrivePrivacy = 'private'; - readonly contentType: ContentType = 'application/octet-stream'; + readonly contentType: ContentType = PRIVATE_CONTENT_TYPE; constructor(readonly driveId: DriveID, readonly objectData: ArFSPrivateDriveTransactionData) { super(); @@ -116,7 +116,7 @@ export abstract class ArFSFolderMetaDataPrototype extends ArFSEntityMetaDataProt } export class ArFSPublicFolderMetaDataPrototype extends ArFSFolderMetaDataPrototype { - readonly contentType: ContentType = 'application/json'; + readonly contentType: ContentType = JSON_CONTENT_TYPE; constructor( readonly objectData: ArFSPublicFolderTransactionData, @@ -130,7 +130,7 @@ export class ArFSPublicFolderMetaDataPrototype extends ArFSFolderMetaDataPrototy export class ArFSPrivateFolderMetaDataPrototype extends ArFSFolderMetaDataPrototype { readonly privacy: DrivePrivacy = 'private'; - readonly contentType: ContentType = 'application/octet-stream'; + readonly contentType: ContentType = PRIVATE_CONTENT_TYPE; constructor( readonly driveId: DriveID, @@ -173,7 +173,7 @@ export abstract class ArFSFileMetaDataPrototype extends ArFSEntityMetaDataProtot } } export class ArFSPublicFileMetaDataPrototype extends ArFSFileMetaDataPrototype { - readonly contentType: ContentType = 'application/json'; + readonly contentType: ContentType = JSON_CONTENT_TYPE; constructor( readonly objectData: ArFSPublicFileMetadataTransactionData, @@ -186,7 +186,7 @@ export class ArFSPublicFileMetaDataPrototype extends ArFSFileMetaDataPrototype { } export class ArFSPrivateFileMetaDataPrototype extends ArFSFileMetaDataPrototype { - readonly contentType: ContentType = 'application/octet-stream'; + readonly contentType: ContentType = PRIVATE_CONTENT_TYPE; constructor( readonly objectData: ArFSPrivateFileMetadataTransactionData, @@ -210,7 +210,7 @@ export class ArFSPrivateFileMetaDataPrototype extends ArFSFileMetaDataPrototype export abstract class ArFSFileDataPrototype extends ArFSObjectMetadataPrototype { abstract readonly objectData: ArFSFileDataTransactionData; - abstract readonly contentType: DataContentType | 'application/octet-stream'; + abstract readonly contentType: DataContentType | typeof PRIVATE_CONTENT_TYPE; get protectedTags(): string[] { return ['Content-Type']; @@ -228,7 +228,7 @@ export class ArFSPublicFileDataPrototype extends ArFSFileDataPrototype { } export class ArFSPrivateFileDataPrototype extends ArFSFileDataPrototype { - readonly contentType = 'application/octet-stream'; + readonly contentType = PRIVATE_CONTENT_TYPE; constructor(readonly objectData: ArFSPrivateFileDataTransactionData) { super(); } diff --git a/src/commands/folder_info.ts b/src/commands/folder_info.ts index 4b76a25f..759646da 100644 --- a/src/commands/folder_info.ts +++ b/src/commands/folder_info.ts @@ -34,6 +34,9 @@ new CLICommand({ })(); // TODO: Fix base types so deleting un-used values is not necessary; Tickets: PE-525 + PE-556 + delete result.size; + delete result.dataTxId; + delete result.dataContentType; delete result.lastModifiedDate; delete result.syncStatus; diff --git a/src/commands/list_drive.ts b/src/commands/list_drive.ts index 0358698a..036231b3 100644 --- a/src/commands/list_drive.ts +++ b/src/commands/list_drive.ts @@ -50,6 +50,8 @@ new CLICommand({ if (fileOrFolderMetaData.entityType === 'folder') { delete fileOrFolderMetaData.lastModifiedDate; delete fileOrFolderMetaData.size; + delete fileOrFolderMetaData.dataTxId; + delete fileOrFolderMetaData.dataContentType; } delete fileOrFolderMetaData.syncStatus; }); diff --git a/src/commands/list_folder.ts b/src/commands/list_folder.ts index 0625650b..8fb6f821 100644 --- a/src/commands/list_folder.ts +++ b/src/commands/list_folder.ts @@ -40,6 +40,8 @@ new CLICommand({ if (fileOrFolderMetaData.entityType === 'folder') { delete fileOrFolderMetaData.lastModifiedDate; delete fileOrFolderMetaData.size; + delete fileOrFolderMetaData.dataTxId; + delete fileOrFolderMetaData.dataContentType; } delete fileOrFolderMetaData.syncStatus; }); diff --git a/src/types.ts b/src/types.ts index 9a89f01e..e5b66be7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,6 +3,9 @@ export const CURRENT_ARFS_VERSION = ArFS_O_11; export const DEFAULT_APP_NAME = 'ArDrive-Core'; export const DEFAULT_APP_VERSION = '1.0.0'; +export const JSON_CONTENT_TYPE = 'application/json'; +export const PRIVATE_CONTENT_TYPE = 'application/octet-stream'; + export type PublicKey = string; export type SeedPhrase = string; diff --git a/src/utils/ardrive.test.ts b/src/utils/ardrive.test.ts index 7a18af7a..864dcd11 100644 --- a/src/utils/ardrive.test.ts +++ b/src/utils/ardrive.test.ts @@ -78,11 +78,11 @@ describe('ArDrive class', () => { it('returns the expected values for valid inputs', () => { const inputsAndExpectedOutputs = [ [0, 16], - [1, 16], - [15, 16], + [1, 17], + [15, 31], [16, 32], - [17, 32], - [Number.MAX_SAFE_INTEGER - 16, Number.MAX_SAFE_INTEGER - 15] + [17, 33], + [Number.MAX_SAFE_INTEGER - 16, Number.MAX_SAFE_INTEGER] ]; inputsAndExpectedOutputs.forEach(([input, expectedOutput]) => { expect(arDrive.encryptedDataSize(input)).to.equal(expectedOutput); @@ -146,7 +146,7 @@ describe('ArDrive class', () => { ); expect(actual).to.deep.equal({ metaDataBaseReward: '147', - fileDataBaseReward: '1234576', + fileDataBaseReward: '1234583', communityWinstonTip: '9876543210' }); }); diff --git a/src/utils/stubs.ts b/src/utils/stubs.ts index 382bd894..d8a4c9b4 100644 --- a/src/utils/stubs.ts +++ b/src/utils/stubs.ts @@ -7,7 +7,7 @@ import { ArFSPrivateFile } from '../arfs_entities'; import { ArweaveAddress } from '../arweave_address'; -import { ArFS_O_11, DriveID, FolderID } from '../types'; +import { ArFS_O_11, DriveID, FolderID, JSON_CONTENT_TYPE, PRIVATE_CONTENT_TYPE } from '../types'; export const stubArweaveAddress = (address = 'abcdefghijklmnopqrxtuvwxyz123456789ABCDEFGH'): ArweaveAddress => new ArweaveAddress(address); @@ -26,7 +26,7 @@ export const stubPublicDrive = new ArFSPublicDrive( 'Integration Test', '1.0', ArFS_O_11, - 'application/json', + JSON_CONTENT_TYPE, stubEntityID, 'drive', 'STUB DRIVE', @@ -40,7 +40,7 @@ export const stubPrivateDrive = new ArFSPrivateDrive( 'Integration Test', '1.0', ArFS_O_11, - 'application/octet-stream', + PRIVATE_CONTENT_TYPE, stubEntityID, 'drive', 'STUB DRIVE', @@ -70,7 +70,7 @@ export const stubPublicFolder = ({ 'Integration Test', '1.0', ArFS_O_11, - 'application/json', + JSON_CONTENT_TYPE, driveId, 'folder', folderName, @@ -90,7 +90,7 @@ export const stubPrivateFolder = ({ 'Integration Test', '1.0', ArFS_O_11, - 'application/json', + JSON_CONTENT_TYPE, driveId, 'folder', folderName, @@ -112,7 +112,7 @@ export const stubPublicFile = ({ driveId = stubEntityID, fileName = 'STUB NAME' 'Integration Test', '1.0', ArFS_O_11, - 'application/json', + JSON_CONTENT_TYPE, driveId, 'file', fileName, @@ -123,7 +123,7 @@ export const stubPublicFile = ({ driveId = stubEntityID, fileName = 'STUB NAME' 1234567890, 0, stubTransactionID, - 'application/json' + JSON_CONTENT_TYPE ); export const stubPrivateFile = ({ driveId = stubEntityID, fileName = 'STUB NAME' }: StubFileParams): ArFSPrivateFile => @@ -131,7 +131,7 @@ export const stubPrivateFile = ({ driveId = stubEntityID, fileName = 'STUB NAME' 'Integration Test', '1.0', ArFS_O_11, - 'application/json', + JSON_CONTENT_TYPE, driveId, 'file', fileName, @@ -142,7 +142,7 @@ export const stubPrivateFile = ({ driveId = stubEntityID, fileName = 'STUB NAME' 1234567890, 0, stubTransactionID, - 'application/json', + JSON_CONTENT_TYPE, 'stubCipher', 'stubIV' ); diff --git a/tests/integration/ardrive.int.test.ts b/tests/integration/ardrive.int.test.ts index 7e5360a7..c28adca5 100644 --- a/tests/integration/ardrive.int.test.ts +++ b/tests/integration/ardrive.int.test.ts @@ -546,7 +546,7 @@ describe('ArDrive class - integrated', () => { ); // Pass expected existing file id, so that the file would be considered a revision - assertUploadFileExpectations(result, 3216, 187, 0, '1', 'private', existingFileId); + assertUploadFileExpectations(result, 3220, 187, 0, '1', 'private', existingFileId); }); it('returns the correct ArFSResult', async () => { @@ -554,7 +554,7 @@ describe('ArDrive class - integrated', () => { const stubDriveKey = await getStubDriveKey(); const result = await arDrive.uploadPrivateFile(stubEntityID, wrappedFile, stubDriveKey); - assertUploadFileExpectations(result, 3216, 182, 0, '1', 'private'); + assertUploadFileExpectations(result, 3220, 182, 0, '1', 'private'); }); });