refactor: change upload api to return a CID object
This commit is contained in:
parent
cff5c1f10a
commit
8531f2abc9
|
@ -288,23 +288,19 @@ export class Client {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async uploadFile(stream: Blob, size?: bigint): Promise<string>;
|
async uploadFile(stream: Blob, size?: bigint): Promise<CID>;
|
||||||
async uploadFile(
|
async uploadFile(
|
||||||
stream: ReadableStream,
|
stream: ReadableStream,
|
||||||
hashStream: ReadableStream,
|
hashStream: ReadableStream,
|
||||||
size: bigint,
|
size: bigint,
|
||||||
): Promise<string>;
|
): Promise<CID>;
|
||||||
async uploadFile(stream: Uint8Array, size?: bigint): Promise<string>;
|
async uploadFile(stream: Uint8Array, size?: bigint): Promise<CID>;
|
||||||
async uploadFile(
|
async uploadFile(
|
||||||
stream: NodeJS.ReadableStream,
|
stream: NodeJS.ReadableStream,
|
||||||
hashStream: NodeJS.ReadableStream,
|
hashStream: NodeJS.ReadableStream,
|
||||||
size?: bigint,
|
size?: bigint,
|
||||||
): Promise<string>;
|
): Promise<CID>;
|
||||||
async uploadFile(
|
async uploadFile(stream: any, hashStream?: any, size?: bigint): Promise<CID> {
|
||||||
stream: any,
|
|
||||||
hashStream?: any,
|
|
||||||
size?: bigint,
|
|
||||||
): Promise<string> {
|
|
||||||
const Blob = await this.getBlobObject();
|
const Blob = await this.getBlobObject();
|
||||||
|
|
||||||
if (stream instanceof Uint8Array || stream instanceof Blob) {
|
if (stream instanceof Uint8Array || stream instanceof Blob) {
|
||||||
|
@ -324,14 +320,14 @@ export class Client {
|
||||||
return this.uploadFileTus(stream, hashStream, size);
|
return this.uploadFileTus(stream, hashStream, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async uploadFileSmall(stream: Blob): Promise<string>;
|
private async uploadFileSmall(stream: Blob): Promise<CID>;
|
||||||
private async uploadFileSmall(
|
private async uploadFileSmall(
|
||||||
stream: ReadableStream,
|
stream: ReadableStream,
|
||||||
hashStream: ReadableStream,
|
hashStream: ReadableStream,
|
||||||
): Promise<string>;
|
): Promise<CID>;
|
||||||
private async uploadFileSmall(stream: Uint8Array): Promise<string>;
|
private async uploadFileSmall(stream: Uint8Array): Promise<CID>;
|
||||||
private async uploadFileSmall(stream: NodeJS.ReadableStream): Promise<string>;
|
private async uploadFileSmall(stream: NodeJS.ReadableStream): Promise<CID>;
|
||||||
private async uploadFileSmall(stream: any): Promise<string> {
|
private async uploadFileSmall(stream: any): Promise<CID> {
|
||||||
const Blob = await this.getBlobObject();
|
const Blob = await this.getBlobObject();
|
||||||
|
|
||||||
if (stream instanceof ReadableStream) {
|
if (stream instanceof ReadableStream) {
|
||||||
|
@ -373,29 +369,26 @@ export class Client {
|
||||||
{ auth: true },
|
{ auth: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
return response.cid;
|
return CID.decode(response.cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async uploadFileTus(stream: Blob, size?: bigint): Promise<string>;
|
private async uploadFileTus(stream: Blob, size?: bigint): Promise<CID>;
|
||||||
private async uploadFileTus(
|
private async uploadFileTus(
|
||||||
stream: ReadableStream,
|
stream: ReadableStream,
|
||||||
hashStream: ReadableStream,
|
hashStream: ReadableStream,
|
||||||
size?: bigint,
|
size?: bigint,
|
||||||
): Promise<string>;
|
): Promise<CID>;
|
||||||
private async uploadFileTus(
|
private async uploadFileTus(stream: Uint8Array, size?: bigint): Promise<CID>;
|
||||||
stream: Uint8Array,
|
|
||||||
size?: bigint,
|
|
||||||
): Promise<string>;
|
|
||||||
private async uploadFileTus(
|
private async uploadFileTus(
|
||||||
stream: NodeJS.ReadableStream,
|
stream: NodeJS.ReadableStream,
|
||||||
hashStream: ReadableStream,
|
hashStream: ReadableStream,
|
||||||
size?: bigint,
|
size?: bigint,
|
||||||
): Promise<string>;
|
): Promise<CID>;
|
||||||
private async uploadFileTus(
|
private async uploadFileTus(
|
||||||
stream: any,
|
stream: any,
|
||||||
hashStream?: any,
|
hashStream?: any,
|
||||||
size?: bigint,
|
size?: bigint,
|
||||||
): Promise<string> {
|
): Promise<CID> {
|
||||||
if (["bigint", "number"].includes(typeof hashStream)) {
|
if (["bigint", "number"].includes(typeof hashStream)) {
|
||||||
size = BigInt(hashStream);
|
size = BigInt(hashStream);
|
||||||
hashStream = undefined;
|
hashStream = undefined;
|
||||||
|
@ -483,7 +476,7 @@ export class Client {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return cid.toString();
|
return cid;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUploadStatus(cid: string) {
|
async getUploadStatus(cid: string) {
|
||||||
|
|
Loading…
Reference in New Issue