mirror of
https://github.com/Lifeforge-app/lifeforge.git
synced 2026-06-28 06:46:24 +00:00
25w32
Former-commit-id: fdfcdd448252f83750bfc4cc9c96cd71b50a1de8 [formerly d8851261213d137b7033f6c5463ed9ebcd8702b6] [formerly 412fc672a3cc15d14804d81b8a6ba90b2e564017 [formerly 12391a582c230f1d9fa4ea6c84ee2062d3d8805b]] Former-commit-id: 034eeb80e5b9121c5cc68b21356b4807def94a92 [formerly 830833354a52b04ef1ebf2e9b16663ac5c702610] Former-commit-id: 2163c17f0b2e4221f90731b0ecd8a8a8b9d4d692
This commit is contained in:
@@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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`,
|
||||
|
||||
@@ -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(),
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user