@yachteye/uploader
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

YachtEye Uploader

This small library implements the SYT Uploader and abstracts the details away into a single call to the back-end to upload a file.

Installation

npm install --save @yachteye/uploader

Usage

import YachtEyeUploader from '@yachteye/uploader'

// set to true to enable debug logs
const enableDebugLogs = false

const onProgress = (progress) => {
  // This is currently not yet used
  console.log('Progress: ' + progress)
}

const onUploaded = ({ id, file, result }) => {
  // the file was uploaded successfully
}

/*
 * @Param {String} Collector base URL
 * @Param {String} NodeJS API base URL
 * @Param {String} NodeJS API upload API token
 * @Param {Function} Callback that gets called when progress changes. Doesn't yet work
 * @Param {Function} Callback that gets called when the upload itself completes
 * @Param {Bool} Enable or disable debug logs
 */
const uploader = new YachtEyeUploader('https://collector-dev.superyachtapi.com', 'https://api0.superyachtapi.com', 'MY_API_KEY', onProgress, onUploaded, enableDebugLogs)

/*
 * @Param {Job} Collector job information. See interfaces below
 * @Param {File} file
 * @Param {string} owner - e.g. current yacht ID
 *
 * @Returns {JobResult}
 */
await uploader.uploadWithJob(job, file, owner)

/*
 * OTHER INSTANCE METHODS
 */

// Get the status of a previously created file job
await uploader.getFileJobStatus(jobId) // => Promise<JobResult>

// Manually create a job for an uploaded file
await uploader.createFileJob(fileId, jobName, jobEntityType, jobEntityId, jobMemoryId, photoIndex) // => Promise<JobResult>

// Manually upload a file, without creating a job
await uploader.upload(file, owner) // => Promise<FileJobResult>

// Sequentially upload files, for a single job (useful with attach-gallery-item)
await uploader.uploadMultipleWithJob(job, files, owner) // => Promise<JobResult[]>

NB The uploader will throw an error if anything fails along the way.

Interfaces

export interface Job {
  jobName: string
  jobEntityType: string
  jobEntityId: string
  jobMemoryId?: string
  photoIndex?: number
}

export interface JobFileEndpoints {
  getUploadUrl: string
  getFileUrl: string
  getFile: string
  downloadFile: string
  updateFile: string
  registerVariant: string
}

export interface JobResult extends Job {
  upstreamErrorCount: number
  status: string
  fileId: string
  mediaIds: string[]
  endpoints: JobFileEndpoints
  createdAt: string
  updatedAt: string
  date: string
  time: string
  _id: string
}

Readme

Keywords

none

Package Sidebar

Install

npm i @yachteye/uploader

Weekly Downloads

160

Version

1.0.3

License

UNLICENSED

Unpacked Size

13.7 kB

Total Files

6

Last publish

Collaborators

  • fabdrol
  • willem_syt