GithubHelp home page GithubHelp logo

lodapi's Introduction

Lodapi

Node.js API for Lodel

Note: The implementation of this toolbox is done according to my personal needs and this library is not intended to offer an exhaustive API. Feel free to contribute if you want to add your own features.

Installation

npm i lodapi

or clone this repo and run:

npm install
npm run build

Usage

const LodelSession = require("lodapi");

const options = {
  concurrency: 2, // Default: Infinity
  timeout: 10000 // Default: 30000
};

(async () => {
  // Instantiate the class
  const session = new LodelSession("https://url-to-lodel-website.com", options);

  try {
    // Authenticate in Lodel
    await session.auth({ login: "user", password: "pwd" });

    // Then do stuff
    const output = await session.getChildren(0);
    console.log(output);

  } catch (e) {
    console.error(e);
  }
})();

Warning

Methods which submit data using the Lodel entity form can cause data loss depending on which type of field is visible in the form. This is due to some weird fields used by Lodel, especially for adding entities to entries. The safest way to avoid such problems is to hide those fields from the admin panel before using any dangerous method.

LodelSession methods

auth({login: string, password: string})

Authenticate in Lodel. See "Usage" on top.

setConcurrency(concurrency: number)

Set request concurrency setting.

checkLodelAdmin(noCache = false)

Check if the current account has lodeladmin rights. The return boolean value is stored in session.isLodelAdmin.

createEntity({ idParent: number, idType: number, data: {} }, defaultData: {})

Create a new entity with type idType in parent idParent. data parameter contains the data sent in the form.

createPublication({ idParent: number, idType: number, data: {}})

Alias to createEntity().

Create a new publication with type idType in parent idParent. data parameter contains the data sent in the form.

getAvailableTypes(idParent: number)

List possible types for children of idParent.

getChildren(idParent: number)

List children entities of idParent.

uploadDoc({ filepath: string, idParent: string, idType: string })

Upload a document (using OTX) located at filepath in publication idParent with type idType.

uploadPdf({ filepath: string, docId: number })

WARNING: this feature is still experimental and can potentially cause data loss.

Upload a PDF located a filepath as docId alterfichier.

getIndex(id: number, type: "entries" | "persons")

Get information about index id:

{
  id: number,
  idType: number;
  relatedEntities?: number[],
  data?: { [key: string]: string }
}

This method has two aliases: getEntry(id: number) and getPerson(id: number).

editIndex(id: number, type: "entries" | "persons", data: {})

Edit index id by posting data in the related edit form.

deleteIndex(id: number, type: "entries" | "persons")

Delete index id with type "entries" or "persons".

This method has two aliases: deleteEntry(id: number) and deletePerson(id: number).

getEntryIdByName(name: string, idType: number)

Get the id of an entry from its name.

editEntryName(id: number, name: string)

Set entry id name to name.

editEntryType(id: number, type: number)

Move entry id to index type (it has to be within the same class). If an entry with the same name already exists in the target index, then the entry id will be merged into it.

associateEntries(idEntities: number[], idEntries: number[], idType?: number)

Connect entities with entries.

If idType is declared then it will be used as idtype for all entries. Otherwise the script will run getEntry() on each individual entry in order to find its type (= additional requests).

dissociateAllEntities(idEntry: number, idType?: number)

Remove association of idEntry with all entries.

If idType is not declared the script will run getEntry() to find it from idEntry (= additional request).

deleteEntry(id: number)

Delete entry id.

editPersonName(id: number, name?: string, familyName?: string)

Set person id name and/ou family name.

resubmitEntity(docId: number)

Resubmit entity form.

This is a workaround used in mergePersons(). When resubmitting an entity form, Lodel recreates the relations between entries and this entity. This is useful to remove duplicate entries : 1) rename all duplicate entries with the same (expected) name, 2) resubmit every associated entity. At the end all the entities will be related to the same entry (= the lowest id).

Since this method submits the entity form, it can cause data loss so be careful.

mergePersons(idBase: number, idPersons: number[])

Merge persons listed in idPerson in a person which will have the idBase data (the lowest id among all those persons will be kept by Lodel). It comes in very handy when cleaning the duplicates among authors.

Since this method submits the entity form, it can cause data loss so be careful.

mergeEntries(idTargetEntry: number, idEntries: number[])

Merge entries listed in idEntries in the entry with the id idTargetEntry. It comes in very handy when cleaning the duplicates among entries.

restoreBackup(file: string)

Restore a backup. file is the path to the backup archive on the host.

WARNING: initial data will be lost after this.

sortEntities(sitename: string, list: number[])

Sort entities according to list of ids. sitename, which is the name of the site in Lodel database, is required.

listOptionsIds()

Return a list of available options ids.

listClasses(classType: "entities" | "entries" | "persons")

List classes defined in editorial model. getDetail() can be used to get more information about each individual class.

getClassesData(classType: "entities" | "entries" | "persons")

Lodeladmin access level is required.

Get the full data about fields and types of all classes.

getTypes(classType: "entities" | "entries" | "persons", classname: string, deap: boolean)

Lodeladmin access level is required.

List available types for an entity, entry or person class. getDetail() can be used to get more information about each individual type. If deap is true, a request is performed for each type to get its full details.

getDetails(lo: "entities" | "entries" | "persons" | "tablefields" | "options", id: number)

Lodeladmin access level is required.

Get information from the field definition form:

  • When lo is "entities", "entries" or "persons", get information about a type.
  • When lo is "tablefields", get information about a field.
  • When lo is "options", get information about an option field.

getFields(classname: string, deap: boolean)

Lodeladmin access level is required.

Get type fields. If deap is true, a request is performed for each field to get its full details.

getEntityFieldsGroups()

Lodeladmin access level is required.

Get groups of fields of the specified entity.

listOptions()

Lodeladmin access level is required.

List options defined in editorial model. getDetail() can be used to get more information about each individual option.

listInternalStyles()

Lodeladmin access level is required.

List internal styles defined in editorial model. getDetail() is not needed since this method already returns all the data about internal styles.

Examples

See examples/ directory.

MIT License

Copyright (c) 2022 Thomas Brouard

lodapi's People

Contributors

brrd avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

lodapi's Issues

Harmonisation de l'API

  1. Les arguments sont nommés ou anonymes selon la méthode, ce qui n'est pas logique.
  2. La forme du paramètre data n'est pas identique partout. Certaines méthodes utilisent la forme field: value, d'autres la forme data[field]: value.

Exemple (deux en un) :

await session.createPublication({ idParent: 0, idType: 12, data: { "titre": "Foo bar" } });

await session.editIndex(123, "entries", { "data[definition]": "Foo bar" });

mergePersons() method is broken

The workaround (= resubmitting an entity to remove its related duplicate persons) does not seam to work anymore.
This needs further investigation.

Concurrency setting

Support concurrency out of the box with a concurrency option.

Instantiate a p-limit in LodelSession constructor and store it as a property + use it in methods.

Détecter les erreur de login/sites bloqués

Lorsque le site est bloqué, lodapi échoue sur un timeout:

code: 'ESOCKETTIMEDOUT',
connect: false,
level: 'error',
timestamp: '2023-02-19T11:03:46.624Z',
[Symbol(level)]: 'error',
[Symbol(message)]: '2023-02-19T11:03:46.624Z error: ESOCKETTIMEDOUT'

Il faudrait parser la page de réponse du formulaire et logger le message d'échec d'authentification.

Upload cover

Déplace la méthode d'import des images d'accroche depuis emfixer vers lodapi.

Add move() method

Example: site/lodel/edition/index.php?do=move&id=74&idparent=3698

mergeEntries error

Long URL like:

lodel/admin/index.php?do=massassoc&lo=entries&edit=1&associate=1&identities[0]=5992&identities[1]=3727&identities[2]=4975&identities[3]=5618&identities[4]=2225&identities[5]=5835&identities[6]=4158&identities[7]=6163&identities[8]=4124&identities[9]=4103&identities[10]=5301&identities[11]=6190&identities[12]=4111&identities[13]=2405&identities[14]=4329&identities[15]=6000&identities[16]=4295&identities[17]=3452&identities[18]=5567&identities[19]=4107&identities[20]=4109&identries[0]=7637_6263

returns an error 500 with this message:

PHP Error (Notice) in file '/var/www/dev/lodel/lodel/scripts/context.php' on line 202 : 
Uninitialized string offset: 10

PHP Error (Notice) in file '/var/www/dev/lodel/lodel/scripts/context.php' on line 202 : 
Uninitialized string offset: 11

PHP Error (Notice) in file '/var/www/dev/lodel/lodel/scripts/context.php' on line 202 : 
Uninitialized string offset: 12

PHP Error (Notice) in file '/var/www/dev/lodel/lodel/scripts/context.php' on line 202 : 
Uninitialized string offset: 13

PHP Error (Notice) in file '/var/www/dev/lodel/lodel/scripts/context.php' on line 202 : 
Uninitialized string offset: 14

PHP Error (Notice) in file '/var/www/dev/lodel/lodel/scripts/context.php' on line 202 : 
Uninitialized string offset: 15

PHP Error (Notice) in file '/var/www/dev/lodel/lodel/scripts/context.php' on line 202 : 
Uninitialized string offset: 16

PHP Error (Notice) in file '/var/www/dev/lodel/lodel/scripts/context.php' on line 202 : 
Uninitialized string offset: 17

PHP Error (Notice) in file '/var/www/dev/lodel/lodel/scripts/context.php' on line 202 : 
Uninitialized string offset: 18

PHP Error (Notice) in file '/var/www/dev/lodel/lodel/scripts/context.php' on line 202 : 
Uninitialized string offset: 19

PHP Error (Notice) in file '/var/www/dev/lodel/lodel/scripts/context.php' on line 202 : 
Uninitialized string offset: 20

Looks like Lodel massassoc doesn't work well with more than 10 entities to move.
Possible workaround: split this in multiple requests.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.