1.1.1 • Published 3 years ago

audio-editor-js v1.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Audio To EditorJs

Allows you to record and upload audio to Editorjs.

Installation

Install NPM

Get the package

npm i audio-editor-js --save

Include module at your application

import Audio from "audio-editor-js";

Usage

Add a new Tool to the tools property of the Editor.js initial config.

var editor = EditorJS({
  ...
  
  tools: {
    ...
    audio: {
      class: Audio,
      config: {
        token: token,
        
        route: `https://test/api/file`,
        routeDelete: `https://test/api/file`,
      },
    },
  }
  ...
});

Config Params

FieldTypeDescription
tokenstringauthorization token
routestringroute for storage on the server
routeDeletestringroute to delete the audio file from the server
saveServercallback functionA function that replaces the standard function of sending to the server
deleteServercallback functionA function that replaces the standard function of deleting a file on the server

output server

the server must give this json in response to the save request. If the server works differently, use the saveServer function

{
    "data" : {
        "url" : "https://test/file",
        "name": "audio.webm",
        "id" : "123",
    }
}

delete server

method delete

callback function saveServer

A function that sends a file to a server. receives the file and to send to the server. Return has an object with a file reference and file id.

  tools: {
    ...
    audio: {
      class: Audio,
      config: {
        saveServer: async (file) => {
          try {
            let formData = new FormData();
            formData.append("file", file);
            
            let req = await axios.post(route, formData);

            // such object should return here
            
            //req = {
            //   data: {
            //     url: 'https://test/file/audio.mp3',
            //     name: 'audio.webm',
            //     id: '123',
            //   }
            // }
            return req;
          } catch (e) {
            console.error(e);
          }
        },
      },
    },
  }

callback function deleteServer

The id of the file by means of which it can be deleted from the server is transferred

  tools: {
    ...
    audio: {
      class: Audio,
      config: {
        deleteServer: async (id) => {
          try {
            await axios.delete(route, id)
          } catch (e) {
            console.error(e);
          }
        },
      },
    },
  }