Skip to content

Commit

Permalink
fix: typos
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrvis committed Sep 21, 2023
1 parent a9260ee commit d47a6f3
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 140 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export async function initInstance(email: string, password: string): Promise<Ako
return new Akord(wallet, { debug: true, env: process.env.ENV as any });
}

export const vaultCreate = async (akord: Akord) => {
export const vaultCreate = async (akord: Akord, cacheOnly = true) => {
const name = faker.random.words();
const termsOfAccess = faker.lorem.sentences();
const { vaultId, membershipId } = await akord.vault.create(name, { termsOfAccess, cacheOnly: true });
const { vaultId, membershipId } = await akord.vault.create(name, { termsOfAccess, cacheOnly: cacheOnly });

const membership = await akord.membership.get(membershipId);
expect(membership.status).toEqual("ACCEPTED");
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/manifest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe("Testing manifest functions", () => {

beforeAll(async () => {
akord = await initInstance(email, password);
vaultId = (await vaultCreate(akord)).vaultId;
vaultId = (await vaultCreate(akord, false)).vaultId;

// upload html file
const htmlSrc = "<html><body><h1>Hello World</h1></body></html>";
Expand Down
4 changes: 1 addition & 3 deletions src/api/akord-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,10 @@ export default class AkordApi extends Api {
};

public async getNodeState(stateId: string): Promise<any> {
const { response } = await new ApiClient()
return await new ApiClient()
.env(this.config)
.resourceId(stateId)
.downloadState()

return response.data
};

public async getNotifications(): Promise<Paginated<any>> {
Expand Down
2 changes: 1 addition & 1 deletion src/core/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class BatchService extends Service {
service.setObjectId(item.id);
service.setObjectType(item.type);
service.arweaveTags = await service.getTxTags();
const { id, object } = await this.api.postContractTransaction<T>(this.vaultId, item.input, service.arweaveTags);
const { id, object } = await this.api.postContractTransaction<T>(service.vaultId, item.input, service.arweaveTags);
const processedObject = item.type === objectType.MEMBERSHIP
? await (<MembershipService>service).processMembership(object as Membership, !batchService.isPublic, batchService.keys)
: await (<NodeService<T>>service).processNode(object as any, !batchService.isPublic, batchService.keys) as any;
Expand Down
133 changes: 0 additions & 133 deletions src/core/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,99 +15,12 @@ import { InternalError } from "../errors/internal-error";
const DEFAULT_FILE_TYPE = "text/plain";
const DEFAULT_CHUNK_SIZE_IN_BYTES = 10000000; //10MB
export const IV_LENGTH_IN_BYTES = 16;
const DEFAULT_CHUNK_SIZE_WITH_IV_IN_BYTES = DEFAULT_CHUNK_SIZE_IN_BYTES + IV_LENGTH_IN_BYTES;

class FileService extends Service {
//asyncUploadTreshold = 209715200;
asyncUploadTreshold = 20000000;
contentType = null as string;

/**
* Returns file as ArrayBuffer. Puts the whole file into memory.
* For downloading without putting whole file to memory use FileService#download()
* @param {string} id file resource url
* @param {string} vaultId
* @param {DownloadOptions} [options]
* @returns Promise with file buffer
*/
// public async get(id: string, vaultId: string, options: DownloadOptions = {}): Promise<ArrayBuffer> {
// const service = new FileService(this.wallet, this.api);
// await service.setVaultContext(vaultId);
// const downloadOptions = options as FileDownloadOptions;
// downloadOptions.public = service.isPublic;
// let fileBinary: ArrayBuffer;
// if (options.isChunked) {
// const chunkSize: number = options.chunkSize || (downloadOptions.public ? DEFAULT_CHUNK_SIZE_IN_BYTES : DEFAULT_CHUNK_SIZE_WITH_IV_IN_BYTES);
// let currentChunk = 0;
// while (currentChunk < options.numberOfChunks) {
// const url = `${id}_${currentChunk}`;
// downloadOptions.loadedSize = currentChunk * chunkSize
// const chunkBinary = await service.getBinary(url, downloadOptions);
// fileBinary = service.appendBuffer(fileBinary, chunkBinary);
// currentChunk++;
// }
// } else {
// const { fileData, metadata } = await this.api.downloadFile(id, downloadOptions);
// fileBinary = await service.processReadRaw(fileData, metadata)
// }
// return fileBinary;
// }

/**
* Downloads the file keeping memory consumed (RAM) under defiend level: this#chunkSize.
* In browser, streaming of the binary requires self hosting of mitm.html and sw.js
* See: https://github.com/jimmywarting/StreamSaver.js#configuration
* @param {string} id file resource url
* @param {string} vaultId
* @param {DownloadOptions} [options]
* @returns Promise with file buffer
*/
// public async download(id: string, vaultId: string, options: DownloadOptions = {}): Promise<void> {
// const service = new FileService(this.wallet, this.api);
// await service.setVaultContext(vaultId);
// const downloadOptions = options as FileDownloadOptions;
// downloadOptions.public = service.isPublic;

// if (typeof window !== 'undefined') {
// if (!service.isPublic) {
// if (!navigator.serviceWorker?.controller) {
// throw new InternalError("Decryption service worker is not running")
// }
// navigator.serviceWorker.controller.postMessage({
// keys: [],
// id: 'test'
// });
// }
// }

// const writer = await service.stream(options.name, options.resourceSize);
// if (options.isChunked) {
// let currentChunk = 0;
// try {
// while (currentChunk < options.numberOfChunks) {
// const url = `${id}_${currentChunk}`;
// // downloadOptions.loadedSize = currentChunk * service.chunkSize;
// const fileBinary = await service.getBinary(url, downloadOptions);
// if (writer instanceof WritableStreamDefaultWriter) {
// await writer.ready
// }
// await writer.write(new Uint8Array(fileBinary));
// currentChunk++;
// }
// } catch (err) {
// throw new Error(err);
// } finally {
// if (writer instanceof WritableStreamDefaultWriter) {
// await writer.ready
// }
// await writer.close();
// }
// } else {
// const fileBinary = await service.getBinary(id, downloadOptions);
// await writer.write(new Uint8Array(fileBinary));
// await writer.close();
// }
//}

public async create(
file: FileLike,
Expand Down Expand Up @@ -146,28 +59,6 @@ class FileService extends Service {
return { file, resourceUri };
}

// public async stream(path: string, size?: number): Promise<any | WritableStreamDefaultWriter> {
// if (typeof window === 'undefined') {
// const fs = (await import("fs")).default;
// return fs.createWriteStream(path);
// }
// else {
// const streamSaver = (await import('streamsaver')).default;
// if (!streamSaver.WritableStream) {
// const pony = await import('web-streams-polyfill/ponyfill');
// streamSaver.WritableStream = pony.WritableStream as unknown as typeof streamSaver.WritableStream;
// }
// if (window.location.protocol === 'https:'
// || window.location.protocol === 'chrome-extension:'
// || window.location.hostname === 'localhost') {
// streamSaver.mitm = '/streamsaver/mitm.html';
// }

// const fileStream = streamSaver.createWriteStream(path, { size: size, writableStrategy: new ByteLengthQueuingStrategy({ highWaterMark: 3 * this.chunkSize }) });
// return fileStream.getWriter();
// }
// }

public async newVersion(file: FileLike, uploadResult: FileUploadResult): Promise<FileVersion> {
const version = new FileVersion({
owner: await this.wallet.getAddress(),
Expand Down Expand Up @@ -304,30 +195,6 @@ class FileService extends Service {
};
}

private appendBuffer(buffer1: ArrayBuffer, buffer2: ArrayBuffer): ArrayBufferLike {
if (!buffer1 && !buffer2) return;
if (!buffer1) return buffer2;
if (!buffer2) return buffer1;
var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
tmp.set(new Uint8Array(buffer1), 0);
tmp.set(new Uint8Array(buffer2), buffer1.byteLength);
return tmp.buffer;
}

// private async getBinary(id: string, options: FileDownloadOptions) {
// try {
// options.public = this.isPublic;
// const { fileData, metadata } = await this.api.downloadFile(id, options);
// return await this.processReadRaw(fileData, metadata);
// } catch (e) {
// Logger.log(e);
// throw new Error(
// "Failed to download. Please check your network connection." +
// " Please upload the file again if problem persists and/or contact Akord support."
// );
// }
// }

private getFileTags(file: FileLike, options: FileUploadOptions = {}): Tags {
const tags = [] as Tags;
if (this.isPublic) {
Expand Down
2 changes: 2 additions & 0 deletions src/core/membership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ class MembershipService extends Service {

protected async setVaultContextFromMembershipId(membershipId: string, vaultId?: string) {
const membership = await this.api.getMembership(membershipId, vaultId);
const vault = await this.api.getVault(membership.vaultId);
this.setVault(vault);
this.setVaultId(membership.vaultId);
this.setIsPublic(membership.__public__);
await this.setMembershipKeys(membership);
Expand Down
2 changes: 2 additions & 0 deletions src/core/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ class NodeService<T> extends Service {

protected async setVaultContextFromNodeId(nodeId: string, type: NodeType, vaultId?: string) {
const object = await this.api.getNode<NodeLike>(nodeId, type, vaultId);
const vault = await this.api.getVault(object.vaultId);
this.setVault(vault);
this.setVaultId(object.vaultId);
this.setIsPublic(object.__public__);
await this.setMembershipKeys(object);
Expand Down

0 comments on commit d47a6f3

Please sign in to comment.