Skip to content

Commit

Permalink
Merge pull request #140 from ardriveapp/dev
Browse files Browse the repository at this point in the history
Merge dev to master and release v1.0.2
  • Loading branch information
fedellen authored Nov 4, 2021
2 parents 67a6385 + b13e1ca commit 06f2720
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 28 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions src/ardrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 16 additions & 0 deletions src/arfs_entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
) {
Expand Down Expand Up @@ -105,6 +109,8 @@ export class ArFSPublicFileOrFolderWithPaths extends ArFSFileOrFolderEntity impl
entity.txId,
entity.unixTime,
entity.lastModifiedDate,
entity.dataTxId,
entity.dataContentType,
entity.parentFolderId,
entity.entityId
);
Expand Down Expand Up @@ -134,6 +140,8 @@ export class ArFSPrivateFileOrFolderWithPaths extends ArFSFileOrFolderEntity imp
entity.txId,
entity.unixTime,
entity.lastModifiedDate,
entity.dataTxId,
entity.dataContentType,
entity.parentFolderId,
entity.entityId
);
Expand Down Expand Up @@ -175,6 +183,8 @@ export class ArFSPublicFile extends ArFSFileOrFolderEntity {
txId,
unixTime,
lastModifiedDate,
dataTxId,
dataContentType,
parentFolderId,
fileId
);
Expand Down Expand Up @@ -213,6 +223,8 @@ export class ArFSPrivateFile extends ArFSFileOrFolderEntity {
txId,
unixTime,
lastModifiedDate,
dataTxId,
dataContentType,
parentFolderId,
fileId
);
Expand Down Expand Up @@ -245,6 +257,8 @@ export class ArFSPublicFolder extends ArFSFileOrFolderEntity {
txId,
unixTime,
0,
stubTransactionID,
JSON_CONTENT_TYPE,
parentFolderId,
entityId
);
Expand Down Expand Up @@ -278,6 +292,8 @@ export class ArFSPrivateFolder extends ArFSFileOrFolderEntity {
txId,
unixTime,
0,
stubTransactionID,
JSON_CONTENT_TYPE,
parentFolderId,
entityId
);
Expand Down
18 changes: 9 additions & 9 deletions src/arfs_prototypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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'];
Expand All @@ -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();
}
Expand Down
3 changes: 3 additions & 0 deletions src/commands/folder_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/commands/list_drive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
2 changes: 2 additions & 0 deletions src/commands/list_folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions src/utils/ardrive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('ArDrive class', () => {
);
expect(actual).to.deep.equal({
metaDataBaseReward: '147',
fileDataBaseReward: '1234576',
fileDataBaseReward: '1234583',
communityWinstonTip: '9876543210'
});
});
Expand Down
18 changes: 9 additions & 9 deletions src/utils/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -70,7 +70,7 @@ export const stubPublicFolder = ({
'Integration Test',
'1.0',
ArFS_O_11,
'application/json',
JSON_CONTENT_TYPE,
driveId,
'folder',
folderName,
Expand All @@ -90,7 +90,7 @@ export const stubPrivateFolder = ({
'Integration Test',
'1.0',
ArFS_O_11,
'application/json',
JSON_CONTENT_TYPE,
driveId,
'folder',
folderName,
Expand All @@ -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,
Expand All @@ -123,15 +123,15 @@ 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 =>
new ArFSPrivateFile(
'Integration Test',
'1.0',
ArFS_O_11,
'application/json',
JSON_CONTENT_TYPE,
driveId,
'file',
fileName,
Expand All @@ -142,7 +142,7 @@ export const stubPrivateFile = ({ driveId = stubEntityID, fileName = 'STUB NAME'
1234567890,
0,
stubTransactionID,
'application/json',
JSON_CONTENT_TYPE,
'stubCipher',
'stubIV'
);
4 changes: 2 additions & 2 deletions tests/integration/ardrive.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,15 +546,15 @@ 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 () => {
stub(arfsDao, 'getOwnerForDriveId').resolves(walletOwner);
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');
});
});

Expand Down

0 comments on commit 06f2720

Please sign in to comment.