Skip to content

Commit

Permalink
feat: rename some props
Browse files Browse the repository at this point in the history
BREAKING CHANGE: rename 'URI' to 'url' and  'getFileURI' to 'getFileUrl'
  • Loading branch information
kukhariev committed May 20, 2019
1 parent ebfb3e4 commit de03db4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
8 changes: 1 addition & 7 deletions src/uploadx/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface UploadState {
speed: number;
status: UploadStatus;
uploadId: string;
URI: string;
url: string;
}

export interface UploadItem {
Expand All @@ -58,12 +58,6 @@ export interface UploadItem {
* @defaultValue '/upload'
*/
endpoint?: string;
/**
* URL to create new uploads.
* @defaultValue '/upload'
* @deprecated Use {@link UploadItem.endpoint} instead.
*/
url?: string;
/**
* Headers to be appended to each HTTP request
*/
Expand Down
12 changes: 6 additions & 6 deletions src/uploadx/src/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export abstract class Uploader {
return;
}
(s === 'cancelled' || s === 'paused') && this.abort();
s === 'cancelled' && this.URI && this.onCancel();
s === 'cancelled' && this.url && this.onCancel();

this._status = s;
this.notifyState();
Expand Down Expand Up @@ -87,7 +87,7 @@ export abstract class Uploader {
/**
* File URI
*/
URI: string;
url: string;
/**
* Custom headers
*/
Expand Down Expand Up @@ -181,7 +181,7 @@ export abstract class Uploader {
this.status = 'uploading';
try {
await this.refreshToken();
this.URI = await this.getFileURI();
this.url = await this.getFileUrl();
this.retry.reset();
this.startTime = new Date().getTime();
this.start();
Expand All @@ -199,7 +199,7 @@ export abstract class Uploader {
/**
* Get file URI
*/
protected abstract getFileURI(): Promise<string>;
protected abstract getFileUrl(): Promise<string>;
/**
* Send file content
*/
Expand All @@ -225,7 +225,7 @@ export abstract class Uploader {
speed: this.speed,
status: this.status,
uploadId: this.uploadId,
URI: this.URI
url: this.url
};

this.stateChange(state);
Expand Down Expand Up @@ -329,7 +329,7 @@ export abstract class Uploader {
}): Promise<number> {
return new Promise((resolve, reject) => {
const xhr: XMLHttpRequest = new XMLHttpRequest();
xhr.open(method, url || this.URI, true);
xhr.open(method, url || this.url, true);
if (progress && body) {
xhr.upload.onprogress = this.onProgress((body as any).size);
}
Expand Down
6 changes: 3 additions & 3 deletions src/uploadx/src/uploaderx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class UploaderX extends Uploader {
this.responseType = 'json' as XMLHttpRequestResponseType;
}

async getFileURI(): Promise<string> {
async getFileUrl(): Promise<string> {
const headers = {
'Content-Type': 'application/json; charset=UTF-8',
'X-Upload-Content-Length': `${this.size}`,
Expand Down Expand Up @@ -40,7 +40,7 @@ export class UploaderX extends Uploader {
const _ = await this.request({
method: 'PUT',
body,
url: this.URI,
url: this.url,
headers,
progress: true
});
Expand All @@ -52,7 +52,7 @@ export class UploaderX extends Uploader {
'Content-Type': 'application/octet-stream',
'Content-Range': `bytes */${this.size}`
};
const _ = await this.request({ method: 'PUT', url: this.URI, headers });
const _ = await this.request({ method: 'PUT', url: this.url, headers });
return this.getOffsetFromResponse();
}

Expand Down

0 comments on commit de03db4

Please sign in to comment.