Skip to content

Ultraviolet-Ninja/Messages-2-The-Castle

Repository files navigation

Messages To The Castle

From Boox -> Dropbox -> Raspberry Pi -> Mega

Description

This README acts as a journal of all the progress I've made on this project and how I continue to develop it.

Attempting to transfer my notes from my Boox notebook to my MEGA cloud storage. The working iteration of the project involves orchestrating CLI commands to download note files from Dropbox to a Raspberry Pi, then upload those files to MEGA. Along the transfer process, we're also adding more PDF features like watermarks with my logo, PDF passwords (more to show that I can add a password rather than it being effective), adding a PDF page outline and making the lines of the PDF highlightable (by adding a bunch of invisible characters to the PDF XD).

Table of Contents

Past Problems in Mk. 1

Evernote

  • Getting a BAD_REQUEST error when creating the NoteStoreClient
    • Decided to stop trying to find the root cause and focus on a Dropbox solution

Dropbox

With Automation

  • Access tokens have a lifetime of 4 hours
  • Currently, don't know how to get a refresh token
    • I think I'll have to manually hit some endpoint, but I don't know what endpoint I have to look for, documentation was unclear
What was the Fix?
  • Manually upload the files whenever I feel like it XD
    • Pretty cringe

OneNote

  • Is there even a Java API??
    • Not that I could find as of writing this

Documentation to Reference

Evernote

Dropbox

Mk. 2 (Fully Autonomous)

Going through several ideas and iterations of the project to make it function without 'human intervention'

HTML Unit - Take 1

Attempt 1 used this library to render the webpage

Citation: GitHub Link

Problem

  • The site would throw an exception when Javascript was enabled; however, Javascript is necessary for the page to render correctly for future use

HBrowser - Take 2

Attempt 2 used the HBrowser library to try to do the same thing as HTML Unit

Citation: GitHub Link

Problem

  • The site wouldn't render completely
    • Not sure how much time I'd want to spend figuring out if it's plausible to get a completely rendered page

Unofficial Dropbox CLI - Take 3

For attempt 3, there is an unofficial Dropbox Command Line Interface written in Go and has compiled versions for Windows and Debian Linux via linux-arm. Perfect!!

Now we can move forward with an idea.

Citation: GitHub Link

Objective

Design a Java wrapper around the CLI similar to Eliux MEGA cmd4J library

What does this solve?

  • This fixes the access lifetime issue
    • You log into the CLI once and that's it
  • The CLI compatibility with Windows and Linux made for easy testing before deploying to the Raspberry Pi

Minor Problem

  • Premise: The program is dysfunctional when running the JAR file on a Raspberry Pi Cron Job
  • Way to look into the problem: Changed the internal logging library to ch.qos.logback:logback-classic (GitHub Link)
    • This contains a dependency to SLF4J-api so that swapping libraries is no problem
    • With the library change, I can output the log events to a file rather than relying on the console for everything
      • Since console logging doesn't work for Cron Jobs anyway
  • Logging event: The error that was occurring was Cannot run program "dbxcli": error=2, No such file or directory
    • This tells me that the dbxcli command is not getting recognized by the system.
      • So, my thought process was 'Is the user different for the Cron Scheduler?'
  • Solution: In Linux, we can prepend a command with sudo -u [USERNAME] so that the command can be executed by a particular user with their set of permissions. In other words, I can substitute myself in as the user running the jar file

Operations

  1. If the Crash-Cloud-Path argument is set True, then we wipe the cloud path where we store notes in MEGA before the transfer
    • Also deletes the revision-list.txt if it exists so that we can conduct a full transfer from Dropbox to MEGA
  2. Fetch the full list of files from Dropbox
    • The Dropbox CLI sometimes would cut the ls command prematurely, so we weren't able to get the list of files
      • The fix for this is to try again with a linear drop-off rate similar to how browsers employ Exponential Backoff for inaccessible websites to prevent heavy traffic
  3. Sort files strictly by filename (Excluding the absolute path)
  4. Detect any file movements within the Dropbox system
    • A file movement is defined as the same file that appears twice in Dropbox with a difference of one directory
      • This indicates that the file was moved to a new directory and the older file should be deleted
  5. If any file movements are found...
    • Determine the older file among the pair (Older files are determined by older ages and smaller file sizes)
      • Delete the older file from Dropbox
      • Remove the older file from the fetched file list
      • If an older file cannot be determined, disregard the pair
  6. If the revision-list.txt file exists, filter out all Dropbox files that haven't changed since last transfer
    • If it filters out all files, the program stops here. (No new files were added to Dropbox)
  7. Rewrite the revision-list.txt file with all new files and hash codes
  8. Prepare files for transfer
    • If the amount of files reaches a certain threshold, conduct the transfers in parallel
    • Download the PDFs from Dropbox (one at a time because some notes will have the same name, and we try to prevent local overwriting as much as possible)
    • Process the files
      • Make the lines of each page highlightable
      • Add a simple table of contents that labels each page with the Page No.
      • Encrypting PDFs and locking permissions for certain operations (more for fun than security. PDF security is garbage, see here)
      • Adding a watermark to each page of the 'Jragon' logo
  9. Log and remove any erroneous files from the revision-list.txt file so that the program can try again at a later time

About

From Boox -> Dropbox -> Raspberry Pi -> Mega

Resources

Stars

Watchers

Forks

Languages