{WIP} #96
This commit is contained in:
parent
e321691daf
commit
67934bed64
8 changed files with 5169 additions and 6493 deletions
|
@ -5,7 +5,12 @@ import Mastodon from "mastodon";
|
|||
import { v4 } from "uuid";
|
||||
import axios from "axios";
|
||||
import Pages from "./Pages";
|
||||
import Export from "./Export";
|
||||
import {
|
||||
convertToCsv,
|
||||
convertToMusicTopus,
|
||||
convertToXls,
|
||||
convertToXml,
|
||||
} from "../helpers/export";
|
||||
|
||||
import AlbumsModel from "../models/albums";
|
||||
import JobsModel from "../models/jobs";
|
||||
|
@ -273,13 +278,13 @@ Publié automatiquement via #musictopus`;
|
|||
|
||||
switch (exportFormat) {
|
||||
case "csv":
|
||||
return Export.convertToCsv(rows);
|
||||
return convertToCsv(rows);
|
||||
case "xls":
|
||||
return Export.convertToXls(rows);
|
||||
return convertToXls(rows);
|
||||
case "xml":
|
||||
return Export.convertToXml(rows);
|
||||
return convertToXml(rows);
|
||||
case "musictopus":
|
||||
return Export.convertToMusicTopus(rows);
|
||||
return convertToMusicTopus(rows);
|
||||
case "json":
|
||||
default:
|
||||
return {
|
||||
|
|
|
@ -1,456 +0,0 @@
|
|||
import { utcToZonedTime } from "date-fns-tz";
|
||||
import setHours from "date-fns/setHours";
|
||||
import xl from "excel4node";
|
||||
|
||||
class Export {
|
||||
/**
|
||||
* Méthode permettant de remplacer certains cartactères par leur équivalents html
|
||||
* @param {String} str
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
static async convertToCsv(rows) {
|
||||
let data =
|
||||
"Artiste;Titre;Genre;Styles;Pays;Année;Date de sortie;Format\n\r";
|
||||
|
||||
for (let i = 0; i < rows.length; i += 1) {
|
||||
const {
|
||||
artists_sort,
|
||||
title,
|
||||
genres,
|
||||
styles,
|
||||
country,
|
||||
year,
|
||||
released,
|
||||
formats,
|
||||
} = rows[i];
|
||||
|
||||
let format = "";
|
||||
for (let j = 0; j < formats.length; j += 1) {
|
||||
format += `${format !== "" ? ", " : ""}${formats[j].name}`;
|
||||
}
|
||||
|
||||
data += `${artists_sort};${title};${genres.join()};${styles.join()};${country};${year};${released};${format}\n\r`;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Méthode permettant de convertir les rows en fichier xls
|
||||
* @param {Array} rows
|
||||
*
|
||||
* @return {Object}
|
||||
*/
|
||||
static async convertToXls(rows) {
|
||||
const wb = new xl.Workbook();
|
||||
const ws = wb.addWorksheet("MusicTopus");
|
||||
|
||||
const headerStyle = wb.createStyle({
|
||||
font: {
|
||||
color: "#FFFFFF",
|
||||
size: 11,
|
||||
},
|
||||
fill: {
|
||||
type: "pattern",
|
||||
patternType: "solid",
|
||||
bgColor: "#595959",
|
||||
fgColor: "#595959",
|
||||
},
|
||||
});
|
||||
const style = wb.createStyle({
|
||||
font: {
|
||||
color: "#000000",
|
||||
size: 11,
|
||||
},
|
||||
numberFormat: "0000",
|
||||
});
|
||||
|
||||
const header = [
|
||||
"Artiste",
|
||||
"Titre",
|
||||
"Genre",
|
||||
"Styles",
|
||||
"Pays",
|
||||
"Année",
|
||||
"Date de sortie",
|
||||
"Format",
|
||||
];
|
||||
for (let i = 0; i < header.length; i += 1) {
|
||||
ws.cell(1, i + 1)
|
||||
.string(header[i])
|
||||
.style(headerStyle);
|
||||
}
|
||||
|
||||
for (let i = 0; i < rows.length; i += 1) {
|
||||
const currentRow = i + 2;
|
||||
const {
|
||||
artists_sort,
|
||||
title,
|
||||
genres,
|
||||
styles,
|
||||
country,
|
||||
year,
|
||||
released,
|
||||
formats,
|
||||
} = rows[i];
|
||||
|
||||
let format = "";
|
||||
for (let j = 0; j < formats.length; j += 1) {
|
||||
format += `${format !== "" ? ", " : ""}${formats[j].name}`;
|
||||
}
|
||||
|
||||
ws.cell(currentRow, 1).string(artists_sort).style(style);
|
||||
ws.cell(currentRow, 2).string(title).style(style);
|
||||
ws.cell(currentRow, 3).string(genres.join(", ")).style(style);
|
||||
ws.cell(currentRow, 4).string(styles.join(", ")).style(style);
|
||||
if (country) {
|
||||
ws.cell(currentRow, 5).string(country).style(style);
|
||||
}
|
||||
if (year) {
|
||||
ws.cell(currentRow, 6).number(year).style(style);
|
||||
}
|
||||
if (released) {
|
||||
ws.cell(currentRow, 7)
|
||||
.date(
|
||||
setHours(utcToZonedTime(released, "Europe/Paris"), 12)
|
||||
)
|
||||
.style({ numberFormat: "dd/mm/yyyy" });
|
||||
}
|
||||
ws.cell(currentRow, 8).string(format).style(style);
|
||||
}
|
||||
|
||||
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>${Export.replaceSpecialChars(artists[j].name)}</name>
|
||||
<anv>${Export.replaceSpecialChars(artists[j].anv)}</anv>
|
||||
<join>${Export.replaceSpecialChars(artists[j].join)}</join>
|
||||
<role>${Export.replaceSpecialChars(artists[j].role)}</role>
|
||||
<tracks>${Export.replaceSpecialChars(artists[j].tracks)}</tracks>
|
||||
<id>${Export.replaceSpecialChars(artists[j].id)}</id>
|
||||
<resource_url>${Export.replaceSpecialChars(
|
||||
artists[j].resource_url
|
||||
)}</resource_url>
|
||||
<thumbnail_url>${Export.replaceSpecialChars(
|
||||
artists[j].thumbnail_url
|
||||
)}</thumbnail_url>
|
||||
</artist>`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < labels.length; j += 1) {
|
||||
labelList += `<label>
|
||||
<name>${Export.replaceSpecialChars(labels[j].name)}</name>
|
||||
<catno>${Export.replaceSpecialChars(labels[j].catno)}</catno>
|
||||
<entity_type>${Export.replaceSpecialChars(
|
||||
labels[j].entity_type
|
||||
)}</entity_type>
|
||||
<entity_type_name>${Export.replaceSpecialChars(
|
||||
labels[j].entity_type
|
||||
)}</entity_type_name>
|
||||
<id>${Export.replaceSpecialChars(labels[j].id)}</id>
|
||||
<resource_url>${Export.replaceSpecialChars(
|
||||
labels[j].resource_url
|
||||
)}</resource_url>
|
||||
<thumbnail_url>${Export.replaceSpecialChars(
|
||||
labels[j].thumbnail_url
|
||||
)}</thumbnail_url>
|
||||
</label>
|
||||
`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < series.length; j += 1) {
|
||||
serieList += `<serie>
|
||||
<name>${Export.replaceSpecialChars(series[j].name)}</name>
|
||||
<catno>${Export.replaceSpecialChars(series[j].catno)}</catno>
|
||||
<entity_type>${Export.replaceSpecialChars(
|
||||
series[j].entity_type
|
||||
)}</entity_type>
|
||||
<entity_type_name>${Export.replaceSpecialChars(
|
||||
series[j].entity_type_name
|
||||
)}</entity_type_name>
|
||||
<id>${Export.replaceSpecialChars(series[j].id)}</id>
|
||||
<resource_url>${Export.replaceSpecialChars(
|
||||
series[j].resource_url
|
||||
)}</resource_url>
|
||||
<thumbnail_url>${Export.replaceSpecialChars(
|
||||
series[j].thumbnail_url
|
||||
)}</thumbnail_url>
|
||||
</serie>
|
||||
`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < companies.length; j += 1) {
|
||||
companiesList += `<company>
|
||||
<name>${Export.replaceSpecialChars(companies[j].name)}</name>
|
||||
<catno>${Export.replaceSpecialChars(companies[j].catno)}</catno>
|
||||
<entity_type>${Export.replaceSpecialChars(
|
||||
companies[j].entity_type
|
||||
)}</entity_type>
|
||||
<entity_type_name>${Export.replaceSpecialChars(
|
||||
companies[j].entity_type_name
|
||||
)}</entity_type_name>
|
||||
<id>${Export.replaceSpecialChars(companies[j].id)}</id>
|
||||
<resource_url>${Export.replaceSpecialChars(
|
||||
companies[j].resource_url
|
||||
)}</resource_url>
|
||||
<thumbnail_url>${Export.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>${Export.replaceSpecialChars(formats[j].name)}</name>
|
||||
<qte>${Export.replaceSpecialChars(formats[j].qty)}</qte>
|
||||
<text>${Export.replaceSpecialChars(formats[j].text)}</text>
|
||||
<descriptions>
|
||||
${descriptions}
|
||||
</descriptions>
|
||||
</format>
|
||||
`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < identifiers.length; j += 1) {
|
||||
identifiersList += `<identifier>
|
||||
<type>${Export.replaceSpecialChars(identifiers[j].type)}</type>
|
||||
<value>${Export.replaceSpecialChars(identifiers[j].value)}</value>
|
||||
<description>${Export.replaceSpecialChars(
|
||||
identifiers[j].description
|
||||
)}</description>
|
||||
</identifier>
|
||||
`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < videos.length; j += 1) {
|
||||
videosList += `<video embed="${videos[j].embed}">
|
||||
<uri>${Export.replaceSpecialChars(videos[j].uri)}</uri>
|
||||
<title>${Export.replaceSpecialChars(videos[j].title)}</title>
|
||||
<description>${Export.replaceSpecialChars(
|
||||
videos[j].description
|
||||
)}</description>
|
||||
<duration>${Export.replaceSpecialChars(
|
||||
videos[j].duration
|
||||
)}</duration>
|
||||
</video>
|
||||
`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < genres.length; j += 1) {
|
||||
genresList += `<genre>${Export.replaceSpecialChars(
|
||||
genres[j]
|
||||
)}</genre>
|
||||
`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < styles.length; j += 1) {
|
||||
stylesList += `<style>${Export.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
|
||||
}">
|
||||
${Export.replaceSpecialChars(tracklist[j].title)}
|
||||
</tracklist>
|
||||
`;
|
||||
}
|
||||
|
||||
for (let j = 0; j < extraartists.length; j += 1) {
|
||||
extraartistsList += `<extraartist>
|
||||
<name>${Export.replaceSpecialChars(extraartists[j].name)}</name>
|
||||
<anv>${Export.replaceSpecialChars(extraartists[j].anv)}</anv>
|
||||
<join>${Export.replaceSpecialChars(extraartists[j].join)}</join>
|
||||
<role>${Export.replaceSpecialChars(extraartists[j].role)}</role>
|
||||
<tracks>${Export.replaceSpecialChars(
|
||||
extraartists[j].tracks
|
||||
)}</tracks>
|
||||
<id>${Export.replaceSpecialChars(extraartists[j].id)}</id>
|
||||
<resource_url>${Export.replaceSpecialChars(
|
||||
extraartists[j].resource_url
|
||||
)}</resource_url>
|
||||
<thumbnail_url>${Export.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>${Export.replaceSpecialChars(images[j].uri)}</uri>
|
||||
<resource_url>${Export.replaceSpecialChars(
|
||||
images[j].resource_url
|
||||
)}</resource_url>
|
||||
<uri150>${Export.replaceSpecialChars(
|
||||
images[j].resource_url
|
||||
)}</uri150>
|
||||
</image>
|
||||
`;
|
||||
}
|
||||
|
||||
data += `
|
||||
<album>
|
||||
<discogId>${discogsId}</discogId>
|
||||
<title>${Export.replaceSpecialChars(title)}</title>
|
||||
<artists_sort>${Export.replaceSpecialChars(artists_sort)}</artists_sort>
|
||||
<artists>
|
||||
${artistsList}
|
||||
</artists>
|
||||
<year>${year}</year>
|
||||
<country>${Export.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>${Export.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
|
||||
*
|
||||
* @return {string}
|
||||
*/
|
||||
static async convertToMusicTopus(rows) {
|
||||
let data = "itemId;createdAt;updatedAt\n\r";
|
||||
|
||||
for (let i = 0; i < rows.length; i += 1) {
|
||||
const { discogsId, createdAt, updatedAt } = rows[i];
|
||||
|
||||
data += `${discogsId};${createdAt};${updatedAt}\n\r`;
|
||||
}
|
||||
|
||||
data += "v1.0";
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
export default Export;
|
|
@ -5,7 +5,12 @@ import Mastodon from "mastodon";
|
|||
import { v4 } from "uuid";
|
||||
import axios from "axios";
|
||||
import Pages from "./Pages";
|
||||
import Export from "./Export";
|
||||
import {
|
||||
convertToCsv,
|
||||
convertToMusicTopus,
|
||||
convertToXls,
|
||||
convertToXml,
|
||||
} from "../helpers/export";
|
||||
|
||||
import WantListModel from "../models/wantlist";
|
||||
import JobsModel from "../models/jobs";
|
||||
|
@ -274,13 +279,13 @@ Publié automatiquement via #musictopus`;
|
|||
|
||||
switch (exportFormat) {
|
||||
case "csv":
|
||||
return Export.convertToCsv(rows);
|
||||
return convertToCsv(rows);
|
||||
case "xls":
|
||||
return Export.convertToXls(rows);
|
||||
return convertToXls(rows);
|
||||
case "xml":
|
||||
return Export.convertToXml(rows);
|
||||
return convertToXml(rows);
|
||||
case "musictopus":
|
||||
return Export.convertToMusicTopus(rows);
|
||||
return convertToMusicTopus(rows);
|
||||
case "json":
|
||||
default:
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue