-
Notifications
You must be signed in to change notification settings - Fork 26
Upload improve #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Upload improve #99
Changes from 8 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
f2ce24b
feat: add upload progress callback and abort signal support
manu4543 10ae4cd
feat: implement abort signal support and upload progress tracking in …
manu4543 b4daa29
add test cases for onProgress and abort
manu4543 09c47d2
expose url, upload static functions. Other updates
manu4543 990cf29
update test cases
manu4543 b15ed76
refactor: update test descriptions to use 'src' instead of 'path'
manu4543 74b3073
refactor: update export types and remove unused ImageKitOptions inter…
manu4543 9341aa2
working upload test cases
manu4543 af7bef3
update node js version and build libs
manu4543 9ad887e
fix: enable terser for code minification in rollup configuration
manu4543 c2edc0b
fix: update codecov version to 3.8.3 and modify coverage reporting sc…
manu4543 cb7c135
ci: add Codecov upload step to GitHub Actions workflow
manu4543 b40208d
fix: remove coverage reporting step from startSampleApp script
manu4543 990b74d
test: add upload error handling tests for abort signal and invalid re…
manu4543 4d30974
improve test coverage
manu4543 bbe982b
chore: update package version to 5.0.0.beta.1 and add .npmignore
manu4543 ed16142
refactor: remove IKResponse interface and update related imports; int…
manu4543 c989e4a
refactor: update package name to @imagekit/javascript and modify desc…
manu4543 0b1463e
chore: add publishConfig with beta tag in package.json
manu4543 aae9934
update readme
manu4543 b7018e2
refactor: rename signal to abortSignal in upload options and update J…
manu4543 200fb8f
fix: update documentation link to point to the live ImageKit site
manu4543 a7655f4
refactor: re-export all interfaces for improved TypeDoc documentation
manu4543 7e3d812
fix links in JSDocs
manu4543 064596c
fix: correct version format in package.json and package-lock.json
manu4543 27a92f2
fix: update version to 5.0.0-beta.2 and adjust publish configuration
manu4543 b59f621
fix: update version to 5.0.0-beta.3 and enhance npm publish workflow
manu4543 8d31d57
test: add assertion for requestId in file upload response
manu4543 42345c3
refactor: remove unused error messages and delete test data file
manu4543 6b32005
test: add unit tests for buildTransformationString function
manu4543 814af9d
fix: update version to 5.0.0-beta.4 in package.json and package-lock.…
manu4543 c6b9f80
fix: update version to 5.0.0-beta.5 in package.json and package-lock.…
manu4543 0efc78d
fix: make encoding property optional in overlay interfaces
manu4543 4721a80
fix: update version to 5.0.0-beta.6 in package.json and package-lock.…
manu4543 dc4e067
Revert "fix: update version to 5.0.0-beta.6 in package.json and packa…
manu4543 32c07ce
fix: update version to 5.0.0-beta.6 in package.json and package-lock.…
manu4543 e6308cb
fix: replace formData.append with formData.set for upload options
manu4543 63ebc6d
Update src/interfaces/UploadOptions.ts
imagekitio d8a2d11
Update src/interfaces/UploadOptions.ts
imagekitio d3e5718
fix: change imports to type imports for better type checking
manu4543 b76ba5e
fix: update version to 5.0.0 in package.json and package-lock.json
manu4543 3153f03
fix: remove src from files array in package.json
manu4543 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,24 @@ | ||
| export default { | ||
| MANDATORY_INITIALIZATION_MISSING: { message: "Missing urlEndpoint during SDK initialization", help: "" }, | ||
| INVALID_TRANSFORMATION_POSITION: { message: "Invalid transformationPosition parameter", help: "" }, | ||
| PRIVATE_KEY_CLIENT_SIDE: { message: "privateKey should not be passed on the client side", help: "" }, | ||
| MISSING_UPLOAD_DATA: { message: "Missing data for upload", help: "" }, | ||
| MISSING_UPLOAD_FILE_PARAMETER: { message: "Missing file parameter for upload", help: "" }, | ||
| MISSING_UPLOAD_FILENAME_PARAMETER: { message: "Missing fileName parameter for upload", help: "" }, | ||
| MISSING_AUTHENTICATION_ENDPOINT: { message: "Missing authentication endpoint for upload", help: "" }, | ||
| MISSING_PUBLIC_KEY: { message: "Missing public key for upload", help: "" }, | ||
| AUTH_ENDPOINT_TIMEOUT: { message: "The authenticationEndpoint you provided timed out in 60 seconds", help: "" }, | ||
| AUTH_ENDPOINT_NETWORK_ERROR: { message: "Request to authenticationEndpoint failed due to network error", help: "" }, | ||
| AUTH_INVALID_RESPONSE: { message: "Invalid response from authenticationEndpoint. The SDK expects a JSON response with three fields i.e. signature, token and expire.", help: "" }, | ||
| MANDATORY_INITIALIZATION_MISSING: { message: "Missing urlEndpoint during SDK initialization" }, | ||
| INVALID_TRANSFORMATION_POSITION: { message: "Invalid transformationPosition parameter" }, | ||
| PRIVATE_KEY_CLIENT_SIDE: { message: "privateKey should not be passed on the client side" }, | ||
| MISSING_UPLOAD_DATA: { message: "Missing data for upload" }, | ||
| MISSING_UPLOAD_FILE_PARAMETER: { message: "Missing file parameter for upload" }, | ||
| MISSING_UPLOAD_FILENAME_PARAMETER: { message: "Missing fileName parameter for upload" }, | ||
| MISSING_AUTHENTICATION_ENDPOINT: { message: "Missing authentication endpoint for upload" }, | ||
| MISSING_PUBLIC_KEY: { message: "Missing public key for upload" }, | ||
| AUTH_ENDPOINT_TIMEOUT: { message: "The authenticationEndpoint you provided timed out in 60 seconds" }, | ||
| AUTH_ENDPOINT_NETWORK_ERROR: { message: "Request to authenticationEndpoint failed due to network error" }, | ||
| AUTH_INVALID_RESPONSE: { message: "Invalid response from authenticationEndpoint. The SDK expects a JSON response with three fields i.e. signature, token and expire." }, | ||
| UPLOAD_ENDPOINT_NETWORK_ERROR: { | ||
| message: "Request to ImageKit upload endpoint failed due to network error", | ||
| help: "", | ||
| message: "Request to ImageKit upload endpoint failed due to network error" | ||
| }, | ||
| INVALID_UPLOAD_OPTIONS: { message: "Invalid uploadOptions parameter", help: "" }, | ||
| MISSING_SIGNATURE: { message: "Missing signature for upload. The SDK expects token, signature and expire for authentication.", help: ""}, | ||
| MISSING_TOKEN: { message: "Missing token for upload. The SDK expects token, signature and expire for authentication.", help: ""}, | ||
| MISSING_EXPIRE: { message: "Missing expire for upload. The SDK expects token, signature and expire for authentication.", help: ""}, | ||
| INVALID_TRANSFORMATION: { message: "Invalid transformation parameter. Please include at least pre, post, or both.", help: ""}, | ||
| INVALID_PRE_TRANSFORMATION: { message: "Invalid pre transformation parameter.", help: ""}, | ||
| INVALID_POST_TRANSFORMATION: { message: "Invalid post transformation parameter.", help: ""}, | ||
| INVALID_UPLOAD_OPTIONS: { message: "Invalid uploadOptions parameter" }, | ||
| MISSING_SIGNATURE: { message: "Missing signature for upload. The SDK expects token, signature and expire for authentication." }, | ||
| MISSING_TOKEN: { message: "Missing token for upload. The SDK expects token, signature and expire for authentication." }, | ||
| MISSING_EXPIRE: { message: "Missing expire for upload. The SDK expects token, signature and expire for authentication." }, | ||
| INVALID_TRANSFORMATION: { message: "Invalid transformation parameter. Please include at least pre, post, or both." }, | ||
| INVALID_PRE_TRANSFORMATION: { message: "Invalid pre transformation parameter." }, | ||
| INVALID_POST_TRANSFORMATION: { message: "Invalid post transformation parameter." }, | ||
| UPLOAD_ABORTED: { message: "Request aborted by the user" }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,91 +1,11 @@ | ||
| import { version } from "../package.json"; | ||
| import errorMessages from "./constants/errorMessages"; | ||
| import { ImageKitOptions, UploadOptions, UploadResponse, UrlOptions } from "./interfaces"; | ||
| import IKResponse from "./interfaces/IKResponse"; | ||
| import { upload } from "./upload/index"; | ||
| import respond from "./utils/respond"; | ||
| import { url } from "./url/index"; | ||
| import transformationUtils from "./utils/transformation"; | ||
| import { UploadOptions, UploadResponse, UrlOptions } from "./interfaces"; | ||
| import { upload } from "./upload"; | ||
| import { buildURL, generateTransformationString } from "./url"; | ||
|
|
||
| function mandatoryParametersAvailable(options: ImageKitOptions) { | ||
| return options.urlEndpoint; | ||
| } | ||
| export { buildURL, generateTransformationString, upload }; | ||
|
|
||
| const promisify = function <T = void>(thisContext: ImageKit, fn: Function) { | ||
| return function (...args: any[]): Promise<T> | void { | ||
| if (args.length === fn.length && typeof args[args.length - 1] !== "undefined") { | ||
| if (typeof args[args.length - 1] !== "function") { | ||
| throw new Error("Callback must be a function."); | ||
| } | ||
| fn.call(thisContext, ...args); | ||
| } else { | ||
| return new Promise<T>((resolve, reject) => { | ||
| const callback = function (err: Error, ...results: any[]) { | ||
| if (err) { | ||
| return reject(err); | ||
| } else { | ||
| resolve(results.length > 1 ? results : results[0]); | ||
| } | ||
| }; | ||
| args.pop() | ||
| args.push(callback); | ||
| fn.call(thisContext, ...args); | ||
| }); | ||
| } | ||
| }; | ||
| export type { | ||
| UrlOptions, | ||
| UploadOptions, | ||
| UploadResponse | ||
| }; | ||
|
|
||
| class ImageKit { | ||
| options: ImageKitOptions = { | ||
| publicKey: "", | ||
| urlEndpoint: "", | ||
| transformationPosition: transformationUtils.getDefault(), | ||
| }; | ||
|
|
||
| constructor(opts: ImageKitOptions) { | ||
| this.options = { ...this.options, ...(opts || {}) }; | ||
| if (!mandatoryParametersAvailable(this.options)) { | ||
| throw errorMessages.MANDATORY_INITIALIZATION_MISSING; | ||
| } | ||
|
|
||
| if (!transformationUtils.validParameters(this.options)) { | ||
| throw errorMessages.INVALID_TRANSFORMATION_POSITION; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * A utility function to generate asset URL. It applies the specified transformations and other parameters to the URL. | ||
| */ | ||
| url(urlOptions: UrlOptions): string { | ||
| return url(urlOptions, this.options); | ||
| } | ||
|
|
||
| /** | ||
| * For uploading files directly from the browser to ImageKit.io. | ||
| * | ||
| * {@link https://imagekit.io/docs/api-reference/upload-file/upload-file#how-to-implement-client-side-file-upload} | ||
| */ | ||
| upload(uploadOptions: UploadOptions, options?: Partial<ImageKitOptions>): Promise<IKResponse<UploadResponse>> | ||
| upload(uploadOptions: UploadOptions, callback: (err: Error | null, response: IKResponse<UploadResponse> | null) => void, options?: Partial<ImageKitOptions>): void; | ||
| upload(uploadOptions: UploadOptions, callbackOrOptions?: ((err: Error | null, response: IKResponse<UploadResponse> | null) => void) | Partial<ImageKitOptions>, options?: Partial<ImageKitOptions>): void | Promise<IKResponse<UploadResponse>> { | ||
| let callback; | ||
| if (typeof callbackOrOptions === 'function') { | ||
| callback = callbackOrOptions; | ||
| } else { | ||
| options = callbackOrOptions || {}; | ||
| } | ||
| if (!uploadOptions || typeof uploadOptions !== "object") { | ||
| return respond(true, errorMessages.INVALID_UPLOAD_OPTIONS, callback); | ||
| } | ||
| var mergedOptions = { | ||
| ...this.options, | ||
| ...options, | ||
| }; | ||
| const { xhr: userProvidedXHR } = uploadOptions || {}; | ||
| delete uploadOptions.xhr; | ||
| const xhr = userProvidedXHR || new XMLHttpRequest(); | ||
| return promisify<IKResponse<UploadResponse>>(this, upload)(xhr, uploadOptions, mergedOptions, callback); | ||
| } | ||
| } | ||
|
|
||
| export default ImageKit; |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.