🚀 Socket Launch Week Day 4:Socket MCP Adds Org Alerts, Threat Feed Review, and Package Inspection.Learn more
Sign In

operafr

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

operafr

Official package to speed up uploads to the open source service **OperaFR**

latest
npmnpm
Version
1.1.4
Version published
Maintainers
1
Created
Source

operafr

Official package to speed up uploads to the open source service OperaFR

Official OperaFR repository: https://github.com/Logic-Layer-Dev/OperaFR

How to use

The package's functions are centered around 3 main methods: instantiate, allocate and upload.

The instantiate function is responsible for creating an object capable of performing the upload tasks. It necessarily needs the following items to be spawned:

const operaUploaderLib = require("operafr");

{...}

const operaUploader = await operaUploaderLib.instantiate({
    serverUrl: "localhost",
    token: "<token>",
    requestPort: 5555,
    publishPort: 5556,
})

The requestPort and publishPort can be changed if the service is running on different ports on the target server.

KeyExplanation
serverUrlServer where OperaFR service is running
tokenAuthentication token obtained by the login route for the user representing the system.
requestPortPort where the Request/Reply service is running
publishPortPort where the Pull/Req service is running

After instantiation, you can now perform the upload steps. To upload a file, you must use the allocate method.

const initialParams = await operaUploader.allocate("<filepath>", { 
    publicUrl: false,
    folderId: <int> //Destiny folder id from server
});

The initialParams will receive this information structure if communication with the server is successful:

{
  status: 201,
  message: 'File created successfully',
  system_filename: '374bcca8-a564-41b9-a61c-8f9fb3793956.<extension>', //Random string 
  public_url: null //Random string if publicUrl = true
}

The public_url can be used for later consumption of the file in the /files/<public_url> route. The system_filename will be used in the upload method to append the chunks to the correct file.

await operaUploader.upload(initialParams.systemFilename, "<filepath>", 
{
    chunckSize: (1024 * 1024) * 4 // 4MB example
}); 

After this call, the file chunks will go to the destination file created on the Opera server. The "await" can be excluded, since it is not necessarily necessary to wait for a response from the server. This way, the client side can be freed from waiting, making everything more dynamic.

The full code:

const operaUploaderLib = require("operafr");

async function main() {
    const operaUploader = await operaUploaderLib.instantiate({
        serverUrl: "localhost",
        token: "<token>",
        requestPort: 5555, //Default Port
        publishPort: 5556, //Default Port
    })

    const initialParams = await operaUploader.allocate("<filepath>", { 
        publicUrl: false,
        folderId: 4 //Example ID
    });

    await operaUploader.upload(initialParams.systemFilename, "<filepath>", {chunckSize: (1024 * 1024) * 4}); // 4MB example
}

main();

FAQs

Package last updated on 19 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts