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.
npm i lodapi
or clone this repo and run:
npm install
npm run build
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);
}
})();
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.
Authenticate in Lodel. See "Usage" on top.
Set request concurrency
setting.
Check if the current account has lodeladmin rights. The return boolean value is stored in session.isLodelAdmin
.
Create a new entity with type idType
in parent idParent
. data
parameter contains the data sent in the form.
Alias to createEntity()
.
Create a new publication with type idType
in parent idParent
. data
parameter contains the data sent in the form.
List possible types for children of idParent
.
List children entities of idParent
.
Upload a document (using OTX) located at filepath
in publication idParent
with type idType
.
WARNING: this feature is still experimental and can potentially cause data loss.
Upload a PDF located a filepath
as docId
alterfichier.
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)
.
Edit index id
by posting data
in the related edit form.
Delete index id
with type "entries" or "persons".
This method has two aliases: deleteEntry(id: number)
and deletePerson(id: number)
.
Get the id of an entry from its name.
Set entry id
name to name
.
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.
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).
Remove association of idEntry
with all entries.
If idType
is not declared the script will run getEntry()
to find it from idEntry (= additional request).
Delete entry id
.
Set person id
name and/ou family name.
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.
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.
Merge entries listed in idEntries
in the entry with the id idTargetEntry
. It comes in very handy when cleaning the duplicates among entries.
Restore a backup. file
is the path to the backup archive on the host.
WARNING: initial data will be lost after this.
Sort entities according to list
of ids. sitename
, which is the name of the site in Lodel database, is required.
Return a list of available options ids.
List classes defined in editorial model. getDetail()
can be used to get more information about each individual class.
Lodeladmin access level is required.
Get the full data about fields and types of all classes.
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.
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.
Lodeladmin access level is required.
Get type fields. If deap
is true, a request is performed for each field to get its full details.
Lodeladmin access level is required.
Get groups of fields of the specified entity.
Lodeladmin access level is required.
List options defined in editorial model. getDetail()
can be used to get more information about each individual option.
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.
See examples/
directory.
Copyright (c) 2022 Thomas Brouard