mirror of
https://github.com/logos-storage/logos-storage-js.git
synced 2026-01-02 13:33:07 +00:00
Fix typo
This commit is contained in:
parent
6b04d115c1
commit
2cb0c9fadc
12
README.md
12
README.md
@ -313,7 +313,7 @@ Upload a file in a streaming manner
|
||||
|
||||
#### Browser
|
||||
|
||||
- stategy [BrowserUploadStategy](./src/data/browser-upload.ts#L5)
|
||||
- strategy [BrowserUploadStrategy](./src/data/browser-upload.ts#L5)
|
||||
- returns [UploadResponse](./src/data/types.ts#L17)
|
||||
|
||||
Example:
|
||||
@ -327,9 +327,9 @@ const onProgress = (loaded, total) => {
|
||||
|
||||
const metadata = { filename: "foo.xt", mimetype: "text/plain" };
|
||||
|
||||
const stategy = new BrowserUploadStategy(file, onProgress, metadata);
|
||||
const strategy = new BrowserUploadStrategy(file, onProgress, metadata);
|
||||
|
||||
const uploadResponse = data.upload(stategy);
|
||||
const uploadResponse = data.upload(strategy);
|
||||
|
||||
const res = await uploadResponse.result;
|
||||
|
||||
@ -343,14 +343,14 @@ console.info("CID is", res.data);
|
||||
|
||||
#### Node
|
||||
|
||||
- stategy [NodeUploadStategy](./src/data/node-upload.ts#L9)
|
||||
- strategy [NodeUploadStrategy](./src/data/node-upload.ts#L9)
|
||||
- returns [UploadResponse](./src/data/types.ts#L17)
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
const stategy = new NodeUploadStategy("Hello World !");
|
||||
const uploadResponse = data.upload(stategy);
|
||||
const strategy = new NodeUploadStrategy("Hello World !");
|
||||
const uploadResponse = data.upload(strategy);
|
||||
|
||||
const res = await uploadResponse.result;
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Codex } from "@codex-storage/sdk-js";
|
||||
import { BrowserUploadStategy } from "@codex-storage/sdk-js/browser";
|
||||
import { BrowserUploadStrategy } from "@codex-storage/sdk-js/browser";
|
||||
|
||||
async function main() {
|
||||
const codex = new Codex(process.env.CODEX_NODE_URL);
|
||||
@ -19,9 +19,9 @@ async function main() {
|
||||
mimetype: "text/plain",
|
||||
};
|
||||
|
||||
const stategy = new BrowserUploadStategy(file, onProgress, metadata);
|
||||
const strategy = new BrowserUploadStrategy(file, onProgress, metadata);
|
||||
|
||||
const uploadResponse = data.upload(stategy);
|
||||
const uploadResponse = data.upload(strategy);
|
||||
|
||||
const res = await uploadResponse.result;
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
const { Codex } = require("@codex-storage/sdk-js");
|
||||
const { NodeUploadStategy } = require("@codex-storage/sdk-js/node");
|
||||
const { NodeUploadStrategy } = require("@codex-storage/sdk-js/node");
|
||||
|
||||
async function main() {
|
||||
const codex = new Codex(
|
||||
@ -7,8 +7,8 @@ async function main() {
|
||||
);
|
||||
const data = codex.data;
|
||||
|
||||
const stategy = new NodeUploadStategy("Hello World !");
|
||||
const uploadResponse = data.upload(stategy);
|
||||
const strategy = new NodeUploadStrategy("Hello World !");
|
||||
const uploadResponse = data.upload(strategy);
|
||||
|
||||
const res = await uploadResponse.result;
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { CodexError } from "../errors/errors";
|
||||
import type { SafeValue } from "../values/values";
|
||||
import type { UploadStategy, UploadStategyOptions } from "./types";
|
||||
import type { UploadStrategy, UploadStrategyOptions } from "./types";
|
||||
|
||||
export class BrowserUploadStategy implements UploadStategy {
|
||||
export class BrowserUploadStrategy implements UploadStrategy {
|
||||
private readonly file: Document | XMLHttpRequestBodyInit;
|
||||
private readonly onProgress:
|
||||
| ((loaded: number, total: number) => void)
|
||||
@ -24,7 +24,7 @@ export class BrowserUploadStategy implements UploadStategy {
|
||||
|
||||
upload(
|
||||
url: string,
|
||||
{ auth }: UploadStategyOptions
|
||||
{ auth }: UploadStrategyOptions
|
||||
): Promise<SafeValue<string>> {
|
||||
const xhr = new XMLHttpRequest();
|
||||
this.xhr = xhr;
|
||||
|
||||
@ -7,7 +7,7 @@ import {
|
||||
import type { SafeValue } from "../values/values";
|
||||
import type {
|
||||
CodexDataResponse,
|
||||
UploadStategy,
|
||||
UploadStrategy,
|
||||
UploadResponse,
|
||||
CodexSpaceResponse,
|
||||
CodexNodeSpace,
|
||||
@ -70,13 +70,13 @@ export class CodexData {
|
||||
* XMLHttpRequest is used instead of fetch for this case, to obtain progress information.
|
||||
* A callback onProgress can be passed to receive upload progress data information.
|
||||
*/
|
||||
upload(stategy: UploadStategy): UploadResponse {
|
||||
upload(strategy: UploadStrategy): UploadResponse {
|
||||
const url = this.url + Api.config.prefix + "/data";
|
||||
|
||||
return {
|
||||
result: stategy.upload(url, { auth: this.auth }),
|
||||
result: strategy.upload(url, { auth: this.auth }),
|
||||
abort: () => {
|
||||
stategy.abort();
|
||||
strategy.abort();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -3,10 +3,10 @@ import { CodexError } from "../errors/errors";
|
||||
import type { SafeValue } from "../values/values";
|
||||
import Undici from "undici";
|
||||
import { type FormData } from "undici";
|
||||
import type { UploadStategy, UploadStategyOptions } from "./types";
|
||||
import type { UploadStrategy, UploadStrategyOptions } from "./types";
|
||||
import { FetchAuthBuilder } from "../fetch-safe/fetch-safe";
|
||||
|
||||
export class NodeUploadStategy implements UploadStategy {
|
||||
export class NodeUploadStrategy implements UploadStrategy {
|
||||
private readonly body:
|
||||
| string
|
||||
| Buffer
|
||||
@ -29,7 +29,7 @@ export class NodeUploadStategy implements UploadStategy {
|
||||
|
||||
async upload(
|
||||
url: string,
|
||||
{ auth }: UploadStategyOptions
|
||||
{ auth }: UploadStrategyOptions
|
||||
): Promise<SafeValue<string>> {
|
||||
const headers: Record<string, string> = FetchAuthBuilder.build(auth);
|
||||
|
||||
|
||||
@ -29,14 +29,14 @@ export type CodexFetchManifestResponse =
|
||||
|
||||
export type CodexManifest = CodexFetchManifestResponse;
|
||||
|
||||
export type UploadStategyOptions = {
|
||||
export type UploadStrategyOptions = {
|
||||
auth?: FetchAuth;
|
||||
};
|
||||
|
||||
export interface UploadStategy {
|
||||
export interface UploadStrategy {
|
||||
upload(
|
||||
url: string,
|
||||
options?: UploadStategyOptions
|
||||
options?: UploadStrategyOptions
|
||||
): Promise<SafeValue<string>>;
|
||||
abort(): void;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user