update
This commit is contained in:
@@ -2,25 +2,30 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const requestUtils = require('../../../utils/requestUtils');
|
||||
const sleepUtils = require('../../../utils/sleepUtils');
|
||||
|
||||
const dbUtils = global.dbUtils;
|
||||
|
||||
// 从数据库中查询
|
||||
async function getFromDatabase({ artistId }) {
|
||||
// 查询出专辑
|
||||
let infoResultSet = await dbUtils.query('SELECT * FROM artist WHERE artist_id = ?', [artistId]);
|
||||
if (infoResultSet.length == 0) return {};
|
||||
|
||||
// 查出专辑与歌曲对应关系
|
||||
let relationResultSet = await dbUtils.query('SELECT * FROM song_artist_relation WHERE artist_id = ?', [artistId]);
|
||||
|
||||
// 拼装
|
||||
let artistInfo = JSON.parse(JSON.stringify(infoResultSet[0]));
|
||||
artistInfo.songIds = relationResultSet.map(song => song.song_id);
|
||||
return artistInfo;
|
||||
}
|
||||
|
||||
// 获取音乐人详情
|
||||
async function fetch({ artistId }) {
|
||||
let result = await dbUtils.query('SELECT count(*) as count FROM artist WHERE artist_id = ?', [artistId]);
|
||||
if (result[0].count > 0) {
|
||||
console.log(`数据库中已有数据,跳过 artistId: ${artistId}`);
|
||||
return;
|
||||
|
||||
// // let artistResult = await dbUtils.query('SELECT * FROM artist LEFT JOIN song_artist_relation ON artist.artist_id = song_artist_relation.artist_id WHERE artist.artist_id = ?', [artistId]);
|
||||
// let artistResult = await dbUtils.query('SELECT * FROM artist WHERE artist_id = ?', [artistId]);
|
||||
// artistResult = JSON.parse(JSON.stringify(artistResult));
|
||||
// let songArtistResult = await dbUtils.query('SELECT * FROM song_artist_relation WHERE artist_id = ?', [artistId]);
|
||||
// songArtistResult = JSON.parse(JSON.stringify(songArtistResult));
|
||||
// artistResult.songIds = songArtistResult.map(song => song.song_id);
|
||||
// // console.log(artistResult);
|
||||
// return artistResult;
|
||||
}
|
||||
|
||||
let url = `https://music.163.com/artist?id=${artistId}`;
|
||||
@@ -78,5 +83,6 @@ async function fetch({ artistId }) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getFromDatabase: getFromDatabase,
|
||||
fetch: fetch,
|
||||
}
|
Reference in New Issue
Block a user