refactor: escape filename
This commit is contained in:
		
							parent
							
								
									6926600f45
								
							
						
					
					
						commit
						50ab62fff7
					
				
					 3 changed files with 8 additions and 3 deletions
				
			
		|  | @ -7,6 +7,7 @@ import fs from 'fs' | |||
| import { fetchMscz } from './mscz' | ||||
| import { loadMscore, INDV_DOWNLOADS, WebMscore } from './mscore' | ||||
| import { ScoreInfoHtml } from './scoreinfo' | ||||
| import { escapeFilename } from './utils' | ||||
| import i18n from './i18n' | ||||
| 
 | ||||
| const SCORE_URL_PREFIX = 'https://musescore.com/' | ||||
|  | @ -99,7 +100,7 @@ void (async () => { | |||
|   await Promise.all( | ||||
|     filetypes.map(async (d) => { | ||||
|       const data = await d.action(score) | ||||
|       const f = `${fileName} - ${encodeURIComponent(partName)}.${d.fileExt}` | ||||
|       const f = `${fileName} - ${escapeFilename(partName)}.${d.fileExt}` | ||||
|       await fs.promises.writeFile(f, data) | ||||
|       spinner.info(`Saved ${chalk.underline(f)}`) | ||||
|       spinner.start() | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| 
 | ||||
| import { getFetch } from './utils' | ||||
| import { getFetch, escapeFilename } from './utils' | ||||
| 
 | ||||
| export abstract class ScoreInfo { | ||||
|   private readonly IPNS_KEY = 'QmSdXtvzC8v8iTTZuj5cVmiugnzbR1QATYRcGix4bBsioP'; | ||||
|  | @ -15,7 +15,7 @@ export abstract class ScoreInfo { | |||
|   } | ||||
| 
 | ||||
|   get fileName (): string { | ||||
|     return this.title.replace(/[\s<>:{}"/\\|?*~.\0\cA-\cZ]+/g, '_') | ||||
|     return escapeFilename(this.title) | ||||
|   } | ||||
| 
 | ||||
|   get msczIpfsRef (): string { | ||||
|  |  | |||
|  | @ -1,6 +1,10 @@ | |||
| 
 | ||||
| import isNodeJs from 'detect-node' | ||||
| 
 | ||||
| export const escapeFilename = (s: string): string => { | ||||
|   return s.replace(/[\s<>:{}"/\\|?*~.\0\cA-\cZ]+/g, '_') | ||||
| } | ||||
| 
 | ||||
| export const getIndexPath = (id: number): string => { | ||||
|   const idStr = String(id) | ||||
|   // 获取最后三位,倒序排列
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue