...
 
Commits (2)
......@@ -52,6 +52,25 @@ class KaraDownload extends Component {
this.api_read_kara_queue();
}
downloadAll() {
this.props.loading(true);
got(
`https://kara.moe/api/karas?filter=${this.state.filter}`,
{ json : true }
).then(res => {
let karas = res.body.content;
karas.forEach((kara) => {
kara.name = kara.subfile.replace('.ass', '');
this.downloadKara(kara)
})
this.props.loading(false);
})
.catch(err => {
this.props.loading(false);
this.props.errorMessage(`${err.response.status}: ${err.response.statusText}. ${err.response.data}`);
});
}
async api_get_local_karas() {
this.setState({karas_local: await getLocalKaras()});
}
......@@ -77,8 +96,8 @@ class KaraDownload extends Component {
});
})
.catch(err => {
//this.props.loading(false);
//this.props.errorMessage(`${err.response.status}: ${err.response.statusText}. ${err.response.data}`);
this.props.loading(false);
this.props.errorMessage(`${err.response.status}: ${err.response.statusText}. ${err.response.data}`);
});
}
......@@ -116,12 +135,14 @@ class KaraDownload extends Component {
/>
</Layout.Header>
<Layout.Content>
<button type="button" onClick={this.downloadAll.bind(this)}><Icon type='download'/></button>
<Table
onChange={this.handleTableChange}
dataSource={this.state.karas_online}
columns={this.columns}
rowKey='kid'
pagination={{
position:"both",
current: this.state.currentPage || 0,
defaultPageSize: this.state.currentPageSize,
pageSize: this.state.currentPageSize,
......
......@@ -83,7 +83,9 @@ export async function integrateSeriesFile(file) {
try {
const seriesDBData = await getSerie(seriesFileData.sid);
await editSerie(seriesDBData.sid, seriesFileData, { refresh: false });
if (seriesDBData.name !== seriesFileData.name) await asyncUnlink(await resolveFileInDirs(seriesDBData.seriefile, getConfig().PathSeries.split('|')));
if (seriesDBData.name !== seriesFileData.name) {
await asyncUnlink(await resolveFileInDirs(seriesDBData.seriefile, getConfig().PathSeries.split('|')));
}
} catch(err) {
await addSerie(seriesFileData, { refresh: false });
}
......
......@@ -3,8 +3,8 @@
export const getSeriesByName = `
SELECT
name,
sid
FROM all_series
pk_sid AS sid
FROM serie
WHERE name = :name
;`;
......
......@@ -144,11 +144,21 @@ async function processDownload(download) {
// Now adding our newly downloaded kara
try {
for (const serie of bundle.series) {
await integrateSeriesFile(serie);
logger.info(`[Download] Series "${serie}" added to database`);
try {
await integrateSeriesFile(serie);
logger.info(`[Download] Series "${serie}" added to database`);
} catch(err) {
logger.error(`[Download] Series "${serie}" not properly added to database`);
throw err;
}
}
try {
await integrateKaraFile(bundle.kara);
logger.info(`[Download] Song "${download.name}" added to database`);
} catch(err) {
logger.error(`[Download] Song "${download.name}" not properly added to database`);
throw err;
}
await integrateKaraFile(bundle.kara);
logger.info(`[Download] Song "${download.name}" added to database`);
} catch(err) {
logger.error(`[Download] Song "${download.name}" downloaded but not properly added to database. Regenerate your database manually after fixing errors`);
throw err;
......
......@@ -172,10 +172,18 @@ export async function getKaraLyrics(kid) {
}
async function updateSeries(kara) {
// statements
if (!kara.series) return true;
let lang = 'und';
if (kara.lang) lang = kara.lang.split(',')[0];
let sids = [];
// Remove this when we'll update .kara file format to version 4
if (kara.KID)
{
kara.kid = kara.KID;
}
for (const s of kara.series.split(',')) {
let langObj = {};
langObj[lang] = s;
......@@ -184,9 +192,10 @@ async function updateSeries(kara) {
};
seriesObj.i18n = {...langObj};
const sid = await getOrAddSerieID(seriesObj);
sids.push(sid);
// Remove this when we'll update .kara file format to version 4
if (kara.KID) kara.kid = kara.KID;
if(sid)
{
sids.push(sid);
}
}
await updateKaraSeries(kara.kid,sids);
}
......
import {removeSeriesFile, writeSeriesFile} from '../_dao/seriesfile';
import {refreshSeries, insertSeriei18n, removeSerie, updateSerie, insertSerie, selectSerieByName, selectSerie, selectAllSeries, refreshKaraSeries} from '../_dao/series';
import {profile} from '../_utils/logger';
import logger from 'winston';
import {removeSerieInKaras, replaceSerieInKaras} from '../_dao/karafile';
import uuidV4 from 'uuid/v4';
import { sanitizeFile } from '../_utils/files';
......@@ -57,7 +58,10 @@ export async function deleteSerie(sid) {
export async function addSerie(serieObj, opts = {refresh: true}) {
if (serieObj.name.includes(',')) throw 'Commas not allowed in series name';
const serie = await selectSerieByName(serieObj.name);
if (serie) throw 'Series original name already exists';
if (serie) {
logger.warning(`Series original name already exists "${serieObj.name}"`);
return serie.sid;
}
if (!serieObj.sid) serieObj.sid = uuidV4();
if (!serieObj.seriefile) serieObj.seriefile = `${sanitizeFile(serieObj.name)}.series.json`;
......