#2 {xml}
This commit is contained in:
parent
e7858c9870
commit
4e911e82ab
3 changed files with 313 additions and 1 deletions
|
@ -16,7 +16,7 @@ module.exports = {
|
|||
'no-underscore-dangle': [
|
||||
'error',
|
||||
{
|
||||
allow: ['_id', 'artists_sort'],
|
||||
allow: ['_id', 'artists_sort', 'type_'],
|
||||
},
|
||||
],
|
||||
'camelcase': [
|
||||
|
|
|
@ -11,6 +11,21 @@ import ErrorEvent from "../libs/error";
|
|||
* Classe permettant la gestion des albums d'un utilisateur
|
||||
*/
|
||||
class Albums extends Pages {
|
||||
static replaceSpecialChars(str) {
|
||||
if (!str) {
|
||||
return "";
|
||||
}
|
||||
let final = str.toString();
|
||||
const find = ["&", "<", ">"];
|
||||
const replace = ["&", "<", ">"];
|
||||
|
||||
for (let i = 0; i < find.length; i += 1) {
|
||||
final = final.replace(new RegExp(find[i], "g"), replace[i]);
|
||||
}
|
||||
|
||||
return final;
|
||||
}
|
||||
|
||||
/**
|
||||
* Méthode permettant de convertir les rows en csv
|
||||
* @param {Array} rows
|
||||
|
@ -129,6 +144,298 @@ class Albums extends Pages {
|
|||
return wb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Méthode permettant de convertir les rows en csv pour importer dans MusicTopus
|
||||
* @param {Array} rows
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
static async convertToXml(rows) {
|
||||
let data = '<?xml version="1.0" encoding="UTF-8"?>\n\r<albums>';
|
||||
|
||||
for (let i = 0; i < rows.length; i += 1) {
|
||||
const {
|
||||
discogsId,
|
||||
year,
|
||||
released,
|
||||
uri,
|
||||
artists,
|
||||
artists_sort,
|
||||
labels,
|
||||
series,
|
||||
companies,
|
||||
formats,
|
||||
title,
|
||||
country,
|
||||
notes,
|
||||
identifiers,
|
||||
videos,
|
||||
genres,
|
||||
styles,
|
||||
tracklist,
|
||||
extraartists,
|
||||
images,
|
||||
thumb,
|
||||
} = rows[i];
|
||||
|
||||
let artistsList = "";
|
||||
let labelList = "";
|
||||
let serieList = "";
|
||||
let companiesList = "";
|
||||
let formatsList = "";
|
||||
let identifiersList = "";
|
||||
let videosList = "";
|
||||
let genresList = "";
|
||||
let stylesList = "";
|
||||
let tracklistList = "";
|
||||
let extraartistsList = "";
|
||||
let imagesList = "";
|
||||
|
||||
for (let j = 0; j < artists.length; j += 1) {
|
||||
artistsList += `<artist>
|
||||
<name>${Albums.replaceSpecialChars(artists[j].name)}</name>
|
||||
<anv>${Albums.replaceSpecialChars(artists[j].anv)}</anv>
|
||||
<join>${Albums.replaceSpecialChars(artists[j].join)}</join>
|
||||
<role>${Albums.replaceSpecialChars(artists[j].role)}</role>
|
||||
<tracks>${Albums.replaceSpecialChars(
|
||||
artists[j].tracks
|
||||
)}</tracks>
|
||||
<id>${Albums.replaceSpecialChars(artists[j].id)}</id>
|
||||
<resource_url>${Albums.replaceSpecialChars(
|
||||
artists[j].resource_url
|
||||
)}</resource_url>
|
||||
<thumbnail_url>${Albums.replaceSpecialChars(
|
||||
artists[j].thumbnail_url
|
||||
)}</thumbnail_url>
|
||||
</artist>`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < labels.length; j += 1) {
|
||||
labelList += `<label>
|
||||
<name>${Albums.replaceSpecialChars(labels[j].name)}</name>
|
||||
<catno>${Albums.replaceSpecialChars(labels[j].catno)}</catno>
|
||||
<entity_type>${Albums.replaceSpecialChars(
|
||||
labels[j].entity_type
|
||||
)}</entity_type>
|
||||
<entity_type_name>${Albums.replaceSpecialChars(
|
||||
labels[j].entity_type
|
||||
)}</entity_type_name>
|
||||
<id>${Albums.replaceSpecialChars(labels[j].id)}</id>
|
||||
<resource_url>${Albums.replaceSpecialChars(
|
||||
labels[j].resource_url
|
||||
)}</resource_url>
|
||||
<thumbnail_url>${Albums.replaceSpecialChars(
|
||||
labels[j].thumbnail_url
|
||||
)}</thumbnail_url>
|
||||
</label>
|
||||
`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < series.length; j += 1) {
|
||||
serieList += `<serie>
|
||||
<name>${Albums.replaceSpecialChars(series[j].name)}</name>
|
||||
<catno>${Albums.replaceSpecialChars(series[j].catno)}</catno>
|
||||
<entity_type>${Albums.replaceSpecialChars(
|
||||
series[j].entity_type
|
||||
)}</entity_type>
|
||||
<entity_type_name>${Albums.replaceSpecialChars(
|
||||
series[j].entity_type_name
|
||||
)}</entity_type_name>
|
||||
<id>${Albums.replaceSpecialChars(series[j].id)}</id>
|
||||
<resource_url>${Albums.replaceSpecialChars(
|
||||
series[j].resource_url
|
||||
)}</resource_url>
|
||||
<thumbnail_url>${Albums.replaceSpecialChars(
|
||||
series[j].thumbnail_url
|
||||
)}</thumbnail_url>
|
||||
</serie>
|
||||
`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < companies.length; j += 1) {
|
||||
companiesList += `<company>
|
||||
<name>${Albums.replaceSpecialChars(companies[j].name)}</name>
|
||||
<catno>${Albums.replaceSpecialChars(companies[j].catno)}</catno>
|
||||
<entity_type>${Albums.replaceSpecialChars(
|
||||
companies[j].entity_type
|
||||
)}</entity_type>
|
||||
<entity_type_name>${Albums.replaceSpecialChars(
|
||||
companies[j].entity_type_name
|
||||
)}</entity_type_name>
|
||||
<id>${Albums.replaceSpecialChars(companies[j].id)}</id>
|
||||
<resource_url>${Albums.replaceSpecialChars(
|
||||
companies[j].resource_url
|
||||
)}</resource_url>
|
||||
<thumbnail_url>${Albums.replaceSpecialChars(
|
||||
companies[j].thumbnail_url
|
||||
)}</thumbnail_url>
|
||||
</company>
|
||||
`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < formats.length; j += 1) {
|
||||
let descriptions = "";
|
||||
if (formats[j].descriptions) {
|
||||
for (
|
||||
let k = 0;
|
||||
k < formats[j].descriptions.length;
|
||||
k += 1
|
||||
) {
|
||||
descriptions += `<description>${formats[j].descriptions[k]}</description>
|
||||
`;
|
||||
}
|
||||
}
|
||||
formatsList += `<format>
|
||||
<name>${Albums.replaceSpecialChars(formats[j].name)}</name>
|
||||
<qte>${Albums.replaceSpecialChars(formats[j].qty)}</qte>
|
||||
<text>${Albums.replaceSpecialChars(formats[j].text)}</text>
|
||||
<descriptions>
|
||||
${descriptions}
|
||||
</descriptions>
|
||||
</format>
|
||||
`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < identifiers.length; j += 1) {
|
||||
identifiersList += `<identifier>
|
||||
<type>${Albums.replaceSpecialChars(identifiers[j].type)}</type>
|
||||
<value>${Albums.replaceSpecialChars(
|
||||
identifiers[j].value
|
||||
)}</value>
|
||||
<description>${Albums.replaceSpecialChars(
|
||||
identifiers[j].description
|
||||
)}</description>
|
||||
</identifier>
|
||||
`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < videos.length; j += 1) {
|
||||
videosList += `<video embed="${videos[j].embed}">
|
||||
<uri>${Albums.replaceSpecialChars(videos[j].uri)}</uri>
|
||||
<title>${Albums.replaceSpecialChars(videos[j].title)}</title>
|
||||
<description>${Albums.replaceSpecialChars(
|
||||
videos[j].description
|
||||
)}</description>
|
||||
<duration>${Albums.replaceSpecialChars(
|
||||
videos[j].duration
|
||||
)}</duration>
|
||||
</video>
|
||||
`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < genres.length; j += 1) {
|
||||
genresList += `<genre>${Albums.replaceSpecialChars(
|
||||
genres[j]
|
||||
)}</genre>
|
||||
`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < styles.length; j += 1) {
|
||||
stylesList += `<style>${Albums.replaceSpecialChars(
|
||||
styles[j]
|
||||
)}</style>
|
||||
`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < tracklist.length; j += 1) {
|
||||
tracklistList += `<tracklist position="${
|
||||
tracklist[j].position
|
||||
}" type="${tracklist[j].type_}" duration="${
|
||||
tracklist[j].duration
|
||||
}">
|
||||
${Albums.replaceSpecialChars(tracklist[j].title)}
|
||||
</tracklist>
|
||||
`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < extraartists.length; j += 1) {
|
||||
extraartistsList += `<extraartist>
|
||||
<name>${Albums.replaceSpecialChars(extraartists[j].name)}</name>
|
||||
<anv>${Albums.replaceSpecialChars(extraartists[j].anv)}</anv>
|
||||
<join>${Albums.replaceSpecialChars(extraartists[j].join)}</join>
|
||||
<role>${Albums.replaceSpecialChars(extraartists[j].role)}</role>
|
||||
<tracks>${Albums.replaceSpecialChars(
|
||||
extraartists[j].tracks
|
||||
)}</tracks>
|
||||
<id>${Albums.replaceSpecialChars(extraartists[j].id)}</id>
|
||||
<resource_url>${Albums.replaceSpecialChars(
|
||||
extraartists[j].resource_url
|
||||
)}</resource_url>
|
||||
<thumbnail_url>${Albums.replaceSpecialChars(
|
||||
extraartists[j].thumbnail_url
|
||||
)}</thumbnail_url>
|
||||
</extraartist>
|
||||
`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < images.length; j += 1) {
|
||||
imagesList += `<image type="${images[j].type}" width="${
|
||||
images[j].width
|
||||
}" height="${images[j].height}">
|
||||
<uri>${Albums.replaceSpecialChars(images[j].uri)}</uri>
|
||||
<resource_url>${Albums.replaceSpecialChars(
|
||||
images[j].resource_url
|
||||
)}</resource_url>
|
||||
<uri150>${Albums.replaceSpecialChars(
|
||||
images[j].resource_url
|
||||
)}</uri150>
|
||||
</image>
|
||||
`;
|
||||
}
|
||||
|
||||
data += `
|
||||
<album>
|
||||
<discogId>${discogsId}</discogId>
|
||||
<title>${Albums.replaceSpecialChars(title)}</title>
|
||||
<artists_sort>${Albums.replaceSpecialChars(artists_sort)}</artists_sort>
|
||||
<artists>
|
||||
${artistsList}
|
||||
</artists>
|
||||
<year>${year}</year>
|
||||
<country>${Albums.replaceSpecialChars(country)}</country>
|
||||
<released>${released}</released>
|
||||
<uri>${uri}</uri>
|
||||
<thumb>${thumb}</thumb>
|
||||
<labels>
|
||||
${labelList}
|
||||
</labels>
|
||||
<series>
|
||||
${serieList}
|
||||
</series>
|
||||
<companies>
|
||||
${companiesList}
|
||||
</companies>
|
||||
<formats>
|
||||
${formatsList}
|
||||
</formats>
|
||||
<notes>${Albums.replaceSpecialChars(notes)}</notes>
|
||||
<identifiers>
|
||||
${identifiersList}
|
||||
</identifiers>
|
||||
<videos>
|
||||
${videosList}
|
||||
</videos>
|
||||
<genres>
|
||||
${genresList}
|
||||
</genres>
|
||||
<styles>
|
||||
${stylesList}
|
||||
</styles>
|
||||
<tracklist>
|
||||
${tracklistList}
|
||||
</tracklist>
|
||||
<extraartists>
|
||||
${extraartistsList}
|
||||
</extraartists>
|
||||
<images>
|
||||
${imagesList}
|
||||
</images>
|
||||
</album>`;
|
||||
}
|
||||
|
||||
return `${data}</albums>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Méthode permettant de convertir les rows en csv pour importer dans MusicTopus
|
||||
* @param {Array} rows
|
||||
|
@ -252,6 +559,8 @@ class Albums extends Pages {
|
|||
return Albums.convertToCsv(rows);
|
||||
case "xls":
|
||||
return Albums.convertToXls(rows);
|
||||
case "xml":
|
||||
return Albums.convertToXml(rows);
|
||||
case "musictopus":
|
||||
return Albums.convertToMusicTopus(rows);
|
||||
case "json":
|
||||
|
|
|
@ -20,6 +20,9 @@ router
|
|||
case "musictopus":
|
||||
res.header("Content-Type", "text/csv");
|
||||
return res.status(200).send(data);
|
||||
case "xml":
|
||||
res.header("Content-type", "text/xml");
|
||||
return res.status(200).send(data);
|
||||
case "xls":
|
||||
return data.write("musictopus.xls", res);
|
||||
case "json":
|
||||
|
|
Loading…
Reference in a new issue