diff --git a/scripts/hmmmmm.ts b/scripts/hmmmmm.ts index 402fc20a2..dff18b61b 100644 --- a/scripts/hmmmmm.ts +++ b/scripts/hmmmmm.ts @@ -1,10 +1,7 @@ -import chalk from 'chalk' import dotenv from 'dotenv' -import fs from 'fs' import _ from 'lodash' import path from 'path' -import Pocketbase, { type CollectionModel } from 'pocketbase' -import prettier from 'prettier' +import Pocketbase from 'pocketbase' dotenv.config({ path: path.resolve(__dirname, '../server/env/.env.local') @@ -33,28 +30,17 @@ try { process.exit(1) } -const allEntries = await pb.collection('idea_box__entries').getFullList() +const allEntries = await pb.collection('scores_library__entries').getFullList() for (const entry of allEntries) { - if (entry.type === 'text') { - await pb.collection('idea_box__entries_text').create({ - base_entry: entry.id, - content: entry.content, - title: entry.title - }) - } else if (entry.type === 'image') { - const image = entry.image - const imageLink = pb.files.getURL(entry, entry.image) - const imageBuffer = await fetch(imageLink).then(res => res.arrayBuffer()) + const firstPart = entry.pdf.split('_')[0] as string + if (firstPart.match(/^\d+$/)) { + const firstPartNumber = parseInt(firstPart, 10) - await pb.collection('idea_box__entries_image').create({ - base_entry: entry.id, - image: new File([imageBuffer], image) - }) - } else { - await pb.collection('idea_box__entries_link').create({ - base_entry: entry.id, - link: entry.content + if (firstPartNumber < 1000) continue + + await pb.collection('scores_library__entries').update(entry.id, { + guitar_world_id: firstPartNumber }) } } diff --git a/server/src/apps/scoresLibrary/routes/guitarWorld.ts b/server/src/apps/scoresLibrary/routes/guitarWorld.ts index 9b5541b81..93405ae3f 100644 --- a/server/src/apps/scoresLibrary/routes/guitarWorld.ts +++ b/server/src/apps/scoresLibrary/routes/guitarWorld.ts @@ -19,7 +19,7 @@ const list = forgeController.query .transform(val => parseInt(val ?? '1', 10) || 1) }) }) - .callback(async ({ query: { cookie, page } }) => { + .callback(async ({ pb, query: { cookie, page } }) => { const data: { data: { list: { @@ -47,7 +47,7 @@ const list = forgeController.query return res.json() }) - return { + const finalData = { data: data.data.list .map(item => item.qupu) .map(item => ({ @@ -57,11 +57,40 @@ const list = forgeController.query category: item.category_txt, mainArtist: item.main_artist, uploader: item.creator_name, - audioUrl: item.audio + audioUrl: item.audio, + existed: false })), totalItems: data.data.total, perPage: data.data.page_size } + + const allIds = finalData.data.map(item => item.id) + + const existingEntries = await pb.getFullList + .collection('scores_library__entries') + .filter([ + { + combination: '||', + filters: allIds.map(e => ({ + field: 'id', + operator: '=', + value: e + })) + } + ]) + .execute() + + for (const entry of existingEntries) { + const index = finalData.data.findIndex( + e => e.id === entry.guitar_world_id + ) + + if (index !== -1) { + finalData.data[index].existed = true + } + } + + return finalData }) const download = forgeController.mutation @@ -78,11 +107,7 @@ const download = forgeController.mutation }) .statusCode(202) .callback( - async ({ - pb, - body: { cookie, id, name, category, mainArtist, audioUrl }, - io - }) => { + async ({ pb, body: { cookie, id, name, mainArtist, audioUrl }, io }) => { const taskId = addToTaskPool(io, { module: 'scoresLibrary', description: `Downloading tab ${name} (${id}) from Guitar World`, diff --git a/server/src/core/schema.ts b/server/src/core/schema.ts index 626d80a7a..246024160 100644 --- a/server/src/core/schema.ts +++ b/server/src/core/schema.ts @@ -384,6 +384,7 @@ export const SCHEMAS = { musescore: z.string(), isFavourite: z.boolean(), collection: z.string(), + guitar_world_id: z.number(), created: z.string(), updated: z.string(), }),