OpenTechStrategies / SimpleBook

A fork of the Collection Extension to print books from MediaWiki instances
1 stars 1 forks source link

Add MediaWiki authentication to node #19

Closed slifty closed 3 years ago

slifty commented 3 years ago

This PR sets the stage for moving MediaWiki authentication logic out of shell and into the mw2pdf code base. Specifically, it introduces a new MediaWikiSession module which will allow us to separate the auth + rendering of a given page from the collation logic.

This also begins to refactor the code base a bit, moving us to node modules and starting to add some directory structure for code organization.

The new code is not integrated / run by a calling agent, but I confirmed it works by running the following in a sandbox.js file (node sandbox.js) against an instance of torque-devenv.

import { MediaWikiSession } from './classes/MediaWikiSession.js'

async function x() {
  const session = new MediaWikiSession()
  const apiUrl = 'http://127.0.0.1/LLIIA2020/api.php'
  await session.authenticate('admin', 'admin_password', apiUrl)
  await session.generatePdf('http://127.0.0.1/LLIIA2020/index.php')
}

x()
slifty commented 3 years ago

I decided not to add docblocks to individual methods since I believe they're somewhat auto-documented, but would be happy to add that in if desired.

slifty commented 3 years ago

An overall thought: some methods use "options" objects (e.g. `function doSomething({ firstParam, secondParam}) where others use traditional parameters. This is not inherently incorrect, but I want to do a pass to make sure there is a rhyme / reason to it.

This StackOverflow thread is a good resource when identifying rules of thumb

UPDATE: I decided to only use the options object in one method that had more than 4 parameters.

slifty commented 3 years ago

Gonna merge this in!