Add download location settings

This commit is contained in:
Geomitron
2024-07-12 15:42:41 -05:00
parent 91e80aed52
commit 7968592893
13 changed files with 168 additions and 52 deletions

View File

@@ -1,5 +1,6 @@
import { interpolate as culoriInterpolate, oklch, wcagContrast } from 'culori'
import _ from 'lodash'
import sanitize from 'sanitize-filename'
import { Difficulty, Instrument } from 'scan-chart'
import { ChartData } from './interfaces/search.interface'
@@ -169,6 +170,63 @@ export function hasIssues(chart: Pick<ChartData, 'metadataIssues' | 'folderIssue
return false
}
export function resolveChartFolderName(
chartFolderName: string,
chart: { name: string; artist: string; album: string; genre: string; year: string; charter: string },
) {
if (_.sumBy(chartFolderName.split('/'), n => n.length) === 0) {
chartFolderName = '{artist} - {name} ({charter})'
}
const pathParts = chartFolderName.split('/')
const resolvedPathParts: string[] = []
for (const pathPart of pathParts) {
const resolvedPath = sanitizeNonemptyFilename(pathPart
.replace(/\{name\}/g, chart.name)
.replace(/\{artist\}/g, chart.artist)
.replace(/\{album\}/g, chart.album)
.replace(/\{genre\}/g, chart.genre)
.replace(/\{year\}/g, chart.year)
.replace(/\{charter\}/g, chart.charter))
if (resolvedPath.length > 0) {
resolvedPathParts.push(resolvedPath)
}
}
return resolvedPathParts.join('/')
}
/**
* @returns `filename` with all invalid filename characters replaced. Assumes `filename` has at least one valid filename character already.
*/
export function sanitizeNonemptyFilename(filename: string) {
return sanitize(filename, {
replacement: (invalidChar: string) => {
switch (invalidChar) {
case '<':
return ''
case '>':
return ''
case ':':
return ''
case '"':
return "'"
case '/':
return ''
case '\\':
return ''
case '|':
return '⏐'
case '?':
return ''
case '*':
return ''
default:
return '_'
}
},
})
}
/* eslint-disable @typescript-eslint/naming-convention */
export const colorNames = {
"primary": "--p",