npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dji-log-parser-js

v0.5.4

Published

Javascript bindings for dji-log-parser rust library

Downloads

118

Readme

dji-log-parser-js

A powerful JavaScript library for parsing DJI txt logs with support for all log versions and encryptions.

Features

  • Parse records and extract embedded images from DJI logs
  • Normalize records across different log versions for a consistent frame format
  • Support for all log versions, including encrypted logs (version 13+)
  • Easy-to-use API for accessing general data, frames, and raw records
  • Ability to fetch and store keychains for offline use with encrypted logs
  • Browser support (See Limitations)

Installation

To install the DJI Log Parser library, use npm:

npm install dji-log-parser-js

Or using yarn:

yarn add dji-log-parser-js

Encryption in Version 13 and Later

Starting with version 13, log records are AES encrypted and require a specific keychain for decryption. This keychain must be obtained from DJI using their API. An apiKey is necessary to access the DJI API.

Once keychains are retrieved from DJI API, they can be stored along with the original log for further offline use.

Obtaining an ApiKey

To acquire an apiKey, follow these steps:

  1. Visit DJI Developer Technologies and log in.
  2. Click CREATE APP, choose Open API as the App Type, and provide the necessary details like App Name, Category, and Description.
  3. After creating the app, activate it through the link sent to your email.
  4. On your developer user page, find your app's details to retrieve the ApiKey (labeled as the SDK key).

Library Usage

Initialization

Initialize a DJILog instance from a byte buffer to access version information and metadata:

Node

import { DJILog } from "dji-log-parser-js";
import { readFileSync } from "fs";

const buffer = readFileSync("./DJIFlightRecord.txt");
const parser = new DJILog(buffer);

Browser

Html

<input type="file" id="file" name="file" />

Javascript

import { DJILog } from "dji-log-parser-js";

document
  .getElementById("file")
  .addEventListener("change", handleFileSelect, false);

function handleFileSelect(event) {
  const file = event.target.files[0];
  if (file) {
    const reader = new FileReader();
    reader.onload = async function (e) {
      const bytes = new Uint8Array(e.target.result);
      const parser = new DJILog(bytes);
    };
    reader.readAsArrayBuffer(file);
  }
}

Access general data

General data are not encrypted and can be accessed from the parser for all log versions:

// Print the log version
console.log("Version:", parser.version);

// Print the log details section
console.log("Details:", parser.details);

Retrieve keychains

For logs version 13 and later, keychains must be retrieved from the DJI API to decode the records:

// Replace `__DJI_API_KEY__` with your actual apiKey
const keychains = await parser.fetchKeychains("__DJI_API_KEY__");

Keychains can be retrieved once, serialized, and stored along with the log file for future offline use.

Accessing Frames

Decrypt frames based on the log file version.

A Frame is a standardized representation of log data, normalized across different log versions. It provides a consistent and easy-to-use format for analyzing and processing DJI log information.

For versions prior to 13:

const frames = parser.frames();

For version 13 and later:

const frames = parser.frames(keychains);

Accessing raw Records

Decrypt raw records based on the log file version. For versions prior to 13:

const records = parser.records();

For version 13 and later:

const records = parser.records(keychains);

Limitations

NodeJS

This library requires fetch to be globally available (Node >= 18.0) for retrieving keychains from the DJI endpoint.

For older Node versions, you can manually retrieve the keychains using an alternative method, such as Axios. The library conveniently provides the necessary data for making keychains request through the parser.keychainsRequest() function.

Here’s an example with Axios:

const axios = require("axios");

const body = JSON.stringify(parser.keychainsRequest());

const response = await axios.post(
  "https://dev.dji.com/openapi/v1/flight-records/keychains",
  body,
  {
    headers: {
      "Content-Type": "application/json",
      "Api-Key": "your_api_key_here",
    },
  }
);

const keychains = response.data.data;

Browser

The DJI Keychain API endpoint does not support CORS (Cross-Origin Resource Sharing). This limitation is acknowledged in an open issue on GitHub: https://github.com/dji-sdk/FlightRecordParsingLib/issues/31

While awaiting a resolution, a temporary workaround involves using a CORS proxy server. Below is an example utilizing a free proxy server: https://github.com/Zibri/cloudflare-cors-anywhere

// Replace `__DJI_API_KEY__` with your actual apiKey
// Don't use this in production, only for testing purpose
const keychains = await parser.fetchKeychains(
  "__DJI_API_KEY__",
  "https://test.cors.workers.dev/?https://dev.dji.com/openapi/v1/flight-records/keychains"
);

License

dji-log-parser-js is available under the MIT license. See the LICENSE.txt file for more info.