Fix #32
This commit is contained in:
@ -40,6 +40,8 @@ type SongRow = {
|
||||
title?: string;
|
||||
artistName?: string;
|
||||
thumbnailUrl?: string;
|
||||
thumbnailWidth?: number;
|
||||
thumbnailHeight?: number;
|
||||
};
|
||||
|
||||
type AccountAvatarRow = {
|
||||
@ -91,8 +93,8 @@ if (enableVerboseLog) {
|
||||
});
|
||||
}
|
||||
|
||||
async function applyDbMigration(migration: Migration): Promise<void> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
function applyDbMigration(migration: Migration): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.exec(migration.statement, (err) => {
|
||||
if (err !== null) {
|
||||
log.error(`Failed to apply migration ${migration.name}`, err);
|
||||
@ -110,7 +112,7 @@ async function applyMigration(migration: Migration) {
|
||||
// so filtering won't help
|
||||
const posts = await getPostsInternal(null, null, 10000);
|
||||
let current = 0;
|
||||
let total = posts.length.toString().padStart(4, '0');
|
||||
const total = posts.length.toString().padStart(4, '0');
|
||||
for (const post of posts) {
|
||||
current++;
|
||||
if (post.songs && post.songs.length) {
|
||||
@ -304,6 +306,13 @@ function getMigrations(): Migration[] {
|
||||
kind INTEGER NOT NULL,
|
||||
FOREIGN KEY (song_thumbnailUrl) REFERENCES songs(thumbnailUrl)
|
||||
);`
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
name: 'song thumbnail size',
|
||||
statement: `
|
||||
ALTER TABLE songs ADD COLUMN thumbnailWidth INTEGER NULL;
|
||||
ALTER TABLE songs ADD COLUMN thumbnailHeight INTEGER NULL;`
|
||||
}
|
||||
];
|
||||
}
|
||||
@ -435,8 +444,8 @@ function saveSongInfoData(postUrl: string, songs: SongInfo[]): Promise<void> {
|
||||
for (const song of songs) {
|
||||
db.run(
|
||||
`
|
||||
INSERT INTO songs (postedUrl, overviewUrl, type, youtubeUrl, title, artistName, thumbnailUrl, post_url)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
INSERT INTO songs (postedUrl, overviewUrl, type, youtubeUrl, title, artistName, thumbnailUrl, post_url, thumbnailWidth, thumbnailHeight)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`,
|
||||
[
|
||||
song.postedUrl,
|
||||
@ -446,7 +455,9 @@ function saveSongInfoData(postUrl: string, songs: SongInfo[]): Promise<void> {
|
||||
song.title,
|
||||
song.artistName,
|
||||
song.thumbnailUrl,
|
||||
postUrl
|
||||
postUrl,
|
||||
song.thumbnailWidth,
|
||||
song.thumbnailHeight
|
||||
],
|
||||
(songErr) => {
|
||||
if (songErr !== null) {
|
||||
@ -481,7 +492,10 @@ export async function savePost(post: Post, songs: SongInfo[]) {
|
||||
await savePostTagData(post);
|
||||
log.debug(`Saved ${post.tags.length} tag data ${post.url}`);
|
||||
await saveSongInfoData(post.url, songs);
|
||||
log.debug(`Saved ${songs.length} song info data ${post.url}`);
|
||||
log.debug(
|
||||
`Saved ${songs.length} song info data ${post.url}`,
|
||||
songs.map((s) => s.thumbnailHeight)
|
||||
);
|
||||
}
|
||||
|
||||
function getPostData(filterQuery: string, params: FilterParameter): Promise<PostRow[]> {
|
||||
@ -534,17 +548,17 @@ function getTagData(postIdsParams: string, postIds: string[]): Promise<Map<strin
|
||||
});
|
||||
}
|
||||
|
||||
function getSongData(postIdsParams: String, postIds: string[]): Promise<Map<string, SongInfo[]>> {
|
||||
function getSongData(postIdsParams: string, postIds: string[]): Promise<Map<string, SongInfo[]>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.all(
|
||||
`SELECT post_url, songs.postedUrl, songs.overviewUrl, songs.type, songs.youtubeUrl,
|
||||
songs.title, songs.artistName, songs.thumbnailUrl, songs.post_url
|
||||
songs.title, songs.artistName, songs.thumbnailUrl, songs.post_url, songs.thumbnailWidth, songs.thumbnailHeight
|
||||
FROM songs
|
||||
WHERE post_url IN (${postIdsParams});`,
|
||||
postIds,
|
||||
(tagErr, tagRows: SongRow[]) => {
|
||||
if (tagErr != null) {
|
||||
log.error('Error loading post tags', tagErr);
|
||||
log.error('Error loading post songs', tagErr);
|
||||
reject(tagErr);
|
||||
return;
|
||||
}
|
||||
@ -557,13 +571,16 @@ function getSongData(postIdsParams: String, postIds: string[]): Promise<Map<stri
|
||||
title: item.title,
|
||||
artistName: item.artistName,
|
||||
thumbnailUrl: item.thumbnailUrl,
|
||||
postedUrl: item.postedUrl
|
||||
postedUrl: item.postedUrl,
|
||||
thumbnailHeight: item.thumbnailHeight,
|
||||
thumbnailWidth: item.thumbnailWidth
|
||||
} as SongInfo;
|
||||
result.set(item.post_url, [...(result.get(item.post_url) || []), info]);
|
||||
return result;
|
||||
},
|
||||
new Map()
|
||||
);
|
||||
log.verbose('songMap', songMap);
|
||||
resolve(songMap);
|
||||
}
|
||||
);
|
||||
|
Reference in New Issue
Block a user