mirror of
https://github.com/Myxelium/Bridge-Multi.git
synced 2026-07-07 10:35:09 +00:00
Add download location settings
This commit is contained in:
@@ -28,6 +28,7 @@ export interface Settings {
|
||||
customTheme: ThemeColors | null // The colors of a custom theme
|
||||
customThemePath: string | null // The last folder that contained the `customTheme`'s file
|
||||
libraryPath: string | undefined // The path to the user's library
|
||||
chartFolderName: string // The relative path and name of the chart that is saved in `libraryPath`
|
||||
isSng: boolean // If the chart should be downloaded as a .sng file or as a chart folder
|
||||
isCompactTable: boolean // If the search result table should have reduced padding
|
||||
visibleColumns: string[] // The search result columns to include
|
||||
@@ -45,6 +46,7 @@ export const defaultSettings: Settings = {
|
||||
customTheme: null,
|
||||
customThemePath: null,
|
||||
libraryPath: undefined,
|
||||
chartFolderName: '{artist} - {name} ({charter})',
|
||||
isSng: false,
|
||||
isCompactTable: false,
|
||||
visibleColumns: ['artist', 'album', 'genre', 'year'],
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
export interface Download {
|
||||
action: 'add' | 'remove' | 'retry'
|
||||
md5: string
|
||||
chartName?: string // Should be defined if action === 'add'
|
||||
// Should be defined if action === 'add'
|
||||
chart?: { name: string; artist: string; album: string; genre: string; year: string; charter: string }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -13,7 +14,7 @@ export interface Download {
|
||||
*/
|
||||
export interface DownloadProgress {
|
||||
md5: string
|
||||
chartName: string
|
||||
chart: { name: string; artist: string; album: string; genre: string; year: string; charter: string }
|
||||
header: string
|
||||
body: string
|
||||
percent: number | null
|
||||
|
||||
Reference in New Issue
Block a user