Socket
Socket
Sign inDemoInstall

ozone-api-upload

Package Overview
Dependencies
Maintainers
8
Versions
143
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ozone-api-upload - npm Package Compare versions

Comparing version 5.4.22 to 5.4.26

7

dist/ozone-api-upload.d.ts
import { OzoneAPIRequest } from 'ozone-api-request';
import { OzoneClient } from 'ozone-typescript-client';
import TaskHandlerOption = OzoneClient.TaskHandlerOption;
export interface UploadSessionResult {

@@ -162,5 +164,6 @@ file: FormData;

* @param {string} folderId
* @param options TaskHandlerOption
* @return {Promise<string | void>}
*/
uploadFile(file: FormData, folderId?: string): Promise<string | null>;
uploadFile(file: FormData, folderId?: string, options?: TaskHandlerOption): Promise<TaskResult | null>;
private notifyOnError;

@@ -171,3 +174,3 @@ _startUploadSession(file: FormData, folderId: string): Promise<UploadSessionResult>;

_endUploadSession(data: UploadIdResult): Promise<UploadEndResult>;
_waitForTask(uploadEndResult: UploadFileId): Promise<string | undefined>;
_waitForTask(taskId: string, options: TaskHandlerOption): Promise<TaskResult | undefined>;
}

@@ -40,3 +40,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

// tslint:disable-next-line:no-empty
this.onreadystatechange = () => { };
this.onreadystatechange = () => {
};
/**

@@ -161,5 +162,6 @@ * set the interval to verify ozone has finish the element processing

* @param {string} folderId
* @param options TaskHandlerOption
* @return {Promise<string | void>}
*/
uploadFile(file, folderId = '0') {
uploadFile(file, folderId = '0', options = {}) {
return this._startUploadSession(file, folderId)

@@ -169,5 +171,6 @@ .then((result) => this._getUploadId(result))

.then((result) => this._endUploadSession(result))
.then((result) => this._waitForTask(result))
.then((mediaId) => {
if (!mediaId) {
.then((result) => this._waitForTask(result.uploadFileId, options))
.then((result) => {
var _a;
if (!((_a = result) === null || _a === void 0 ? void 0 : _a.mediaId)) {
throw Error('No media define in Ozone');

@@ -177,7 +180,7 @@ }

this._readyState = 4;
this._mediaId = mediaId;
this._mediaId = result.mediaId;
if (this.eventTarget) {
this.eventTarget.dispatchEvent(new CustomEvent('ozone-upload-completed', { bubbles: true, detail: { mediaId } }));
this.eventTarget.dispatchEvent(new CustomEvent('ozone-upload-completed', { bubbles: true, detail: { mediaId: result.mediaId } }));
}
return mediaId;
return result;
}).catch((error) => {

@@ -278,10 +281,7 @@ this.status = 555;

}
_waitForTask(uploadEndResult) {
return __awaiter(this, void 0, void 0, function* () {
const taskClient = getDefaultClient().taskClient();
const taskHandler = taskClient.waitForTask(uploadEndResult.uploadFileId);
const result = yield taskHandler.waitResult;
return result && result.mediaId;
});
_waitForTask(taskId, options) {
const taskClient = getDefaultClient().taskClient();
const taskHandler = taskClient.waitForTask(taskId, options);
return taskHandler.waitResult;
}
}
{
"name": "ozone-api-upload",
"version": "5.4.22",
"publishConfig": {
"access": "public"
},
"description": "UploadFileRequest is a JavaScrip class that can be use as an XMLHttpRequest to upload media using ozone v2 upload chanel.",
"main": "dist/ozone-api-upload.js",
"types": "dist/ozone-api-upload.d.ts",
"directories": {
"test": "test"
},
"scripts": {
"build": "../../../node_modules/.bin/tsc",
"prepublish": "../../../node_modules/.bin/tsc",
"tslint": "../../../node_modules/.bin/tslint --project tsconfig.json",
"test": "npm run tslint && npm run build",
"doc": "../../../node_modules/.bin/typedoc --excludeExternals --out doc/ src/"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"ozone-type": "^5.4.22"
},
"dependencies": {
"ozone-api-request": "^5.4.22",
"ozone-config": "^5.4.22",
"ozone-default-client": "^5.4.22"
},
"repository": "https://github.com/taktik/ozone-components/packages/ozone-api/ozone-api-upload",
"gitHead": "113318b0771d22e817278cec8fcf5cba7f098b91"
"name": "ozone-api-upload",
"version": "5.4.26",
"publishConfig": {
"access": "public"
},
"description": "UploadFileRequest is a JavaScrip class that can be use as an XMLHttpRequest to upload media using ozone v2 upload chanel.",
"main": "dist/ozone-api-upload.js",
"types": "dist/ozone-api-upload.d.ts",
"directories": {
"test": "test"
},
"scripts": {
"build": "../../../node_modules/.bin/tsc",
"prepublish": "../../../node_modules/.bin/tsc",
"tslint": "../../../node_modules/.bin/tslint --project tsconfig.json",
"test": "npm run tslint && npm run build",
"doc": "../../../node_modules/.bin/typedoc --excludeExternals --out doc/ src/"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"ozone-type": "^5.4.22"
},
"dependencies": {
"ozone-api-request": "^5.4.22",
"ozone-config": "^5.4.22",
"ozone-default-client": "^5.4.26",
"ozone-typescript-client": "^5.4.26"
},
"repository": "https://github.com/taktik/ozone-components/packages/ozone-api/ozone-api-upload",
"gitHead": "04a319b5ddfcf3e0d99128a0fda16c8685e75cf0"
}
import { OzoneConfig } from 'ozone-config'
import { OzoneAPIRequest } from 'ozone-api-request'
import { getDefaultClient } from 'ozone-default-client'
import { UUID } from 'ozone-type'
import { OzoneClient } from 'ozone-typescript-client'
import TaskHandlerOption = OzoneClient.TaskHandlerOption

@@ -19,4 +20,6 @@ export interface UploadSessionResult {

}
export interface UploadEndResult extends UploadIdResult, UploadFileId {
}
export interface TaskResult {

@@ -26,2 +29,3 @@ mediaId: string

}
export interface TaskExecutions {

@@ -34,2 +38,3 @@ completed?: boolean // API v3

}
export interface WaitResponse {

@@ -100,4 +105,6 @@ groupId: string,

*/
// tslint:disable-next-line:no-empty
onreadystatechange?: { (): void } = () => {}
// tslint:disable-next-line:no-empty
onreadystatechange?: { (): void } = () => {
}
private callOneadystatechange() {

@@ -122,2 +129,3 @@ if (typeof (this.onreadystatechange) === 'function') {

}
private set _readyState(readyState: number) {

@@ -127,2 +135,3 @@ this._internalReadyState = readyState

}
private _internalReadyState: number = 0

@@ -240,5 +249,6 @@

* @param {string} folderId
* @param options TaskHandlerOption
* @return {Promise<string | void>}
*/
uploadFile(file: FormData, folderId: string = '0'): Promise<string | null> {
uploadFile(file: FormData, folderId: string = '0', options: TaskHandlerOption = {}): Promise<TaskResult | null> {

@@ -249,5 +259,5 @@ return this._startUploadSession(file, folderId)

.then((result) => this._endUploadSession(result))
.then((result) => this._waitForTask(result))
.then((mediaId?: string) => {
if (!mediaId) {
.then((result) => this._waitForTask(result.uploadFileId, options))
.then((result) => {
if (!result?.mediaId) {
throw Error('No media define in Ozone')

@@ -258,11 +268,11 @@ }

this._mediaId = mediaId
this._mediaId = result.mediaId
if (this.eventTarget) {
this.eventTarget.dispatchEvent(
new CustomEvent('ozone-upload-completed',
{ bubbles: true, detail: { mediaId } })
)
new CustomEvent('ozone-upload-completed',
{ bubbles: true, detail: { mediaId: result.mediaId } })
)
}
return mediaId
return result
}).catch((error: Error) => {

@@ -289,3 +299,3 @@ this.status = 555

async _startUploadSession(file: FormData, folderId: string): Promise<UploadSessionResult> {
const request = this. _createRequest()
const request = this._createRequest()
request.url = await this._buildUrl('uploadStart')

@@ -312,4 +322,4 @@ request.method = 'POST'

async _getUploadId(data: UploadSessionResult): Promise < UploadIdResult > {
const request = this. _createRequest()
async _getUploadId(data: UploadSessionResult): Promise<UploadIdResult> {
const request = this._createRequest()
request.url = await this._buildUrl('uploadId', data.sessionId)

@@ -321,13 +331,13 @@ request.method = 'GET'

return request.sendRequest()
.then((xhr: XMLHttpRequest) => {
const response = xhr.response
const resultInfo: UploadIdResult = data as UploadIdResult
resultInfo.uploadId = response.result
resultInfo.folderId = response.folderId
return resultInfo
})
.then((xhr: XMLHttpRequest) => {
const response = xhr.response
const resultInfo: UploadIdResult = data as UploadIdResult
resultInfo.uploadId = response.result
resultInfo.folderId = response.folderId
return resultInfo
})
}
async _performUpload(data: UploadIdResult): Promise < UploadIdResult > {
const request = this. _createRequest()
async _performUpload(data: UploadIdResult): Promise<UploadIdResult> {
const request = this._createRequest()
request.url = await this._buildUrl('upload', data.uploadId)

@@ -342,9 +352,9 @@ request.method = 'POST'

return request.sendRequest(xhr)
.then(() => {
return data
})
.then(() => {
return data
})
}
async _endUploadSession(data: UploadIdResult): Promise < UploadEndResult > {
const request = this. _createRequest()
async _endUploadSession(data: UploadIdResult): Promise<UploadEndResult> {
const request = this._createRequest()
request.url = await this._buildUrl('uploadComplete', data.sessionId)

@@ -366,14 +376,14 @@ request.method = 'POST'

return request.sendRequest()
.then((xhr: XMLHttpRequest) => {
const response: UploadEndResult = data as UploadEndResult
response.uploadFileId = xhr.response.file
return response
})
.then((xhr: XMLHttpRequest) => {
const response: UploadEndResult = data as UploadEndResult
response.uploadFileId = xhr.response.file
return response
})
}
async _waitForTask(uploadEndResult: UploadFileId): Promise < string | undefined > {
_waitForTask(taskId: string, options: TaskHandlerOption): Promise<TaskResult | undefined> {
const taskClient = getDefaultClient().taskClient()
const taskHandler = taskClient.waitForTask<TaskResult>(uploadEndResult.uploadFileId)
const result = await taskHandler.waitResult
return result && result.mediaId
const taskHandler = taskClient.waitForTask<TaskResult>(taskId, options)
return taskHandler.waitResult
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc