Skip to content

Commit

Permalink
feat: up/down progress, share check, fs done
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwynr committed Feb 17, 2024
1 parent 95edf46 commit 7d7aa5f
Show file tree
Hide file tree
Showing 543 changed files with 1,721 additions and 12,543 deletions.
40 changes: 0 additions & 40 deletions dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,12 @@ const filen = new FilenSDK({
})

const main = async () => {
/*const content = await filen.api(3).dir().content({ uuid: "6fc3d024-083f-41ba-906e-638a12a13a71" })
for (const folders of content.folders) {
console.log(await filen.crypto().decrypt().folderMetadata({ metadata: folders.name }))
}
for (const file of content.uploads) {
console.log(await filen.crypto().decrypt().fileMetadata({ metadata: file.metadata }))
}
const inputFile = pathModule.join(__dirname, "dev.config.json")
const outputFile = pathModule.join(__dirname, "dev.config.json.encrypted")
await Promise.all([
fs.rm(pathModule.join(__dirname, "dev.config.json.decrypted"), {
force: true,
maxRetries: 60 * 10,
recursive: true,
retryDelay: 100
}),
fs.rm(pathModule.join(__dirname, "dev.config.json.encrypted"), {
force: true,
maxRetries: 60 * 10,
recursive: true,
retryDelay: 100
})
])
const key = await generateRandomString({ length: 32 })
await filen.crypto().encrypt().dataStream({ inputFile, outputFile, key })
await filen
.crypto()
.decrypt()
.dataStream({ inputFile: outputFile, outputFile: pathModule.join(__dirname, "dev.config.json.decrypted"), key, version: 2 })*/

console.log(
await filen.cloud().uploadFileFromLocal({
parent: "6fc3d024-083f-41ba-906e-638a12a13a71",
source: pathModule.join(__dirname, "folderDownload", "Kylo.jpg")
})
)

/*await filen
.cloud()
.downloadDirectoryToLocal({ uuid: "6fc3d024-083f-41ba-906e-638a12a13a71", to: pathModule.join(__dirname, "folderDownload") })*/
}

main()
3 changes: 0 additions & 3 deletions dist/bundle.browser.js

This file was deleted.

36 changes: 0 additions & 36 deletions dist/bundle.browser.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion dist/bundle.browser.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/bundle.node.js

This file was deleted.

20 changes: 0 additions & 20 deletions dist/bundle.node.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion dist/bundle.node.js.map

This file was deleted.

52 changes: 34 additions & 18 deletions dist/types/api/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/// <reference types="node" />
import { ResponseType } from "axios";
import fs from "fs-extra";
import type { ProgressCallback } from "../types";
export type APIClientConfig = {
apiKey: string;
};
Expand All @@ -13,6 +14,9 @@ export type BaseRequestParameters = {
maxRetries?: number;
retryTimeout?: number;
responseType?: ResponseType;
headers?: Record<string, string>;
onUploadProgress?: ProgressCallback;
onDownloadProgress?: ProgressCallback;
};
export type GetRequestParameters = BaseRequestParameters & {
method: "GET";
Expand Down Expand Up @@ -96,7 +100,7 @@ export declare class APIClient {
request<T>(params: RequestParameters): Promise<T>;
/**
* Downloads a file chunk to a local path.
* @date 2/16/2024 - 4:53:34 AM
* @date 2/17/2024 - 6:40:58 AM
*
* @public
* @async
Expand All @@ -107,9 +111,10 @@ export declare class APIClient {
* chunk: number
* to: string
* timeout?: number
* abortSignal?: AbortSignal,
* maxRetries?: number,
* abortSignal?: AbortSignal
* maxRetries?: number
* retryTimeout?: number
* onProgress?: ProgressCallback
* }} param0
* @param {string} param0.uuid
* @param {string} param0.bucket
Expand All @@ -120,9 +125,10 @@ export declare class APIClient {
* @param {AbortSignal} param0.abortSignal
* @param {number} param0.maxRetries
* @param {number} param0.retryTimeout
* @param {ProgressCallback} param0.onProgress
* @returns {Promise<void>}
*/
downloadChunkToLocal({ uuid, bucket, region, chunk, to, timeout, abortSignal, maxRetries, retryTimeout }: {
downloadChunkToLocal({ uuid, bucket, region, chunk, to, timeout, abortSignal, maxRetries, retryTimeout, onProgress }: {
uuid: string;
bucket: string;
region: string;
Expand All @@ -132,10 +138,11 @@ export declare class APIClient {
abortSignal?: AbortSignal;
maxRetries?: number;
retryTimeout?: number;
onProgress?: ProgressCallback;
}): Promise<void>;
/**
* Downloads a file chunk and returns a readable stream.
* @date 2/16/2024 - 4:53:57 AM
* @date 2/17/2024 - 6:40:44 AM
*
* @public
* @async
Expand All @@ -146,8 +153,9 @@ export declare class APIClient {
* chunk: number
* timeout?: number
* abortSignal?: AbortSignal
* maxRetries?: number,
* maxRetries?: number
* retryTimeout?: number
* onProgress?: ProgressCallback
* }} param0
* @param {string} param0.uuid
* @param {string} param0.bucket
Expand All @@ -157,9 +165,10 @@ export declare class APIClient {
* @param {AbortSignal} param0.abortSignal
* @param {number} param0.maxRetries
* @param {number} param0.retryTimeout
* @param {ProgressCallback} param0.onProgress
* @returns {Promise<ReadableStream | fs.ReadStream>}
*/
downloadChunkToStream({ uuid, bucket, region, chunk, timeout, abortSignal, maxRetries, retryTimeout }: {
downloadChunkToStream({ uuid, bucket, region, chunk, timeout, abortSignal, maxRetries, retryTimeout, onProgress }: {
uuid: string;
bucket: string;
region: string;
Expand All @@ -168,10 +177,11 @@ export declare class APIClient {
abortSignal?: AbortSignal;
maxRetries?: number;
retryTimeout?: number;
onProgress?: ProgressCallback;
}): Promise<ReadableStream | fs.ReadStream>;
/**
* Download a chunk buffer.
* @date 2/16/2024 - 4:54:19 AM
* @date 2/17/2024 - 6:40:21 AM
*
* @public
* @async
Expand All @@ -181,9 +191,10 @@ export declare class APIClient {
* region: string
* chunk: number
* timeout?: number
* abortSignal?: AbortSignal,
* maxRetries?: number,
* retryTimeout?: number
* abortSignal?: AbortSignal
* maxRetries?: number
* retryTimeout?: number,
* onProgress: ProgressCallback
* }} param0
* @param {string} param0.uuid
* @param {string} param0.bucket
Expand All @@ -193,9 +204,10 @@ export declare class APIClient {
* @param {AbortSignal} param0.abortSignal
* @param {number} param0.maxRetries
* @param {number} param0.retryTimeout
* @param {ProgressCallback} param0.onProgress
* @returns {Promise<Buffer>}
*/
downloadChunkToBuffer({ uuid, bucket, region, chunk, timeout, abortSignal, maxRetries, retryTimeout }: {
downloadChunkToBuffer({ uuid, bucket, region, chunk, timeout, abortSignal, maxRetries, retryTimeout, onProgress }: {
uuid: string;
bucket: string;
region: string;
Expand All @@ -204,10 +216,11 @@ export declare class APIClient {
abortSignal?: AbortSignal;
maxRetries?: number;
retryTimeout?: number;
onProgress?: ProgressCallback;
}): Promise<Buffer>;
/**
* Upload a chunk buffer.
* @date 2/16/2024 - 4:55:16 AM
* @date 2/17/2024 - 5:08:04 AM
*
* @public
* @async
Expand All @@ -216,11 +229,12 @@ export declare class APIClient {
* index: number
* parent: string
* uploadKey: string
* buffer: Buffer,
* buffer: Buffer
* timeout?: number
* abortSignal?: AbortSignal,
* maxRetries?: number,
* retryTimeout?: number
* abortSignal?: AbortSignal
* maxRetries?: number
* retryTimeout?: number,
* onProgress?: ProgressCallback
* }} param0
* @param {string} param0.uuid
* @param {number} param0.index
Expand All @@ -231,9 +245,10 @@ export declare class APIClient {
* @param {number} param0.maxRetries
* @param {number} param0.timeout
* @param {number} param0.retryTimeout
* @param {ProgressCallback} param0.onProgress
* @returns {Promise<UploadChunkResponse>}
*/
uploadChunkBuffer({ uuid, index, parent, uploadKey, buffer, abortSignal, maxRetries, timeout, retryTimeout }: {
uploadChunkBuffer({ uuid, index, parent, uploadKey, buffer, abortSignal, maxRetries, timeout, retryTimeout, onProgress }: {
uuid: string;
index: number;
parent: string;
Expand All @@ -243,6 +258,7 @@ export declare class APIClient {
abortSignal?: AbortSignal;
maxRetries?: number;
retryTimeout?: number;
onProgress?: ProgressCallback;
}): Promise<UploadChunkResponse>;
}
export default APIClient;
5 changes: 4 additions & 1 deletion dist/types/api/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export declare class API {
uuid: string;
parent: string;
email: string;
type: string;
type: "file" | "folder";
metadata: string;
}) => Promise<void>;
shared: (params_0: {
Expand Down Expand Up @@ -366,6 +366,7 @@ export declare class API {
chunk: number;
timeout?: number | undefined;
abortSignal?: AbortSignal | undefined;
onProgress?: import("../types").ProgressCallback | undefined;
}) => Promise<Buffer>;
stream: (params_0: {
uuid: string;
Expand All @@ -374,6 +375,7 @@ export declare class API {
chunk: number;
timeout?: number | undefined;
abortSignal?: AbortSignal | undefined;
onProgress?: import("../types").ProgressCallback | undefined;
}) => Promise<ReadableStream<any> | import("fs").ReadStream>;
local: (params_0: {
uuid: string;
Expand All @@ -383,6 +385,7 @@ export declare class API {
timeout?: number | undefined;
abortSignal?: AbortSignal | undefined;
to: string;
onProgress?: import("../types").ProgressCallback | undefined;
}) => Promise<void>;
};
};
Expand Down
12 changes: 8 additions & 4 deletions dist/types/api/v3/file/download/chunk/buffer.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="node" />
import type APIClient from "../../../../client";
import type { ProgressCallback } from "../../../../../types";
/**
* FileDownloadChunkBuffer
* @date 2/15/2024 - 4:38:09 AM
Expand All @@ -24,7 +25,7 @@ export declare class FileDownloadChunkBuffer {
});
/**
* Download a file chunk.
* @date 2/15/2024 - 5:10:49 AM
* @date 2/17/2024 - 6:39:08 AM
*
* @public
* @async
Expand All @@ -34,23 +35,26 @@ export declare class FileDownloadChunkBuffer {
* region: string
* chunk: number
* timeout?: number
* abortSignal?: AbortSignal
* abortSignal?: AbortSignal,
* onProgress?: ProgressCallback
* }} param0
* @param {string} param0.uuid
* @param {string} param0.bucket
* @param {string} param0.region
* @param {number} param0.chunk
* @param {number} param0.timeout
* @param {AbortSignal} param0.abortSignal
* @returns {Promise<void | ReadableStream | fs.ReadStream | Buffer>}
* @param {ProgressCallback} param0.onProgress
* @returns {Promise<Buffer>}
*/
fetch({ uuid, bucket, region, chunk, timeout, abortSignal }: {
fetch({ uuid, bucket, region, chunk, timeout, abortSignal, onProgress }: {
uuid: string;
bucket: string;
region: string;
chunk: number;
timeout?: number;
abortSignal?: AbortSignal;
onProgress?: ProgressCallback;
}): Promise<Buffer>;
}
export default FileDownloadChunkBuffer;
Loading

0 comments on commit 7d7aa5f

Please sign in to comment.