mirror of
				https://ghproxy.com/https://github.com/StreakingMan/solvable-sheep-game
				synced 2025-11-01 00:36:09 +08:00 
			
		
		
		
	fix: 图片文件大小校验逻辑
This commit is contained in:
		
							parent
							
								
									cebf64847f
								
							
						
					
					
						commit
						be0faff9fd
					
				|  | @ -146,10 +146,14 @@ const ConfigDialog: FC<{ | ||||||
|         new Array(10).fill('') |         new Array(10).fill('') | ||||||
|     ); |     ); | ||||||
|     // 文件体积校验开关
 |     // 文件体积校验开关
 | ||||||
|  |     const initEnableFileSizeValidate = localStorage.getItem( | ||||||
|  |         CUSTOM_THEME_FILE_VALIDATE_STORAGE_KEY | ||||||
|  |     ); | ||||||
|     const [enableFileSizeValidate, setEnableFileSizeValidate] = |     const [enableFileSizeValidate, setEnableFileSizeValidate] = | ||||||
|         useState<boolean>( |         useState<boolean>( | ||||||
|             localStorage.getItem(CUSTOM_THEME_FILE_VALIDATE_STORAGE_KEY) !== |             initEnableFileSizeValidate === null | ||||||
|                 'false' |                 ? true | ||||||
|  |                 : initEnableFileSizeValidate === 'true' | ||||||
|         ); |         ); | ||||||
|     useEffect(() => { |     useEffect(() => { | ||||||
|         localStorage.setItem( |         localStorage.setItem( | ||||||
|  | @ -184,16 +188,16 @@ const ConfigDialog: FC<{ | ||||||
|             case 'background': |             case 'background': | ||||||
|                 setBackgroundError(''); |                 setBackgroundError(''); | ||||||
|                 try { |                 try { | ||||||
|                     const compressFile = await canvasToFile({ |                     const _file = enableFileSizeValidate | ||||||
|  |                         ? await canvasToFile({ | ||||||
|                               canvas: await createCanvasByImgSrc({ |                               canvas: await createCanvasByImgSrc({ | ||||||
|                                   imgSrc: await getFileBase64String(file), |                                   imgSrc: await getFileBase64String(file), | ||||||
|                               }), |                               }), | ||||||
|                               maxFileSize: 20 * 1024, |                               maxFileSize: 20 * 1024, | ||||||
|                     }); |                           }) | ||||||
|                     const compressFileBase64 = await getFileBase64String( |                         : file; | ||||||
|                         compressFile |                     const fileBase64 = await getFileBase64String(_file); | ||||||
|                     ); |                     updateCustomTheme('background', fileBase64); | ||||||
|                     updateCustomTheme('background', compressFileBase64); |  | ||||||
|                 } catch (e: any) { |                 } catch (e: any) { | ||||||
|                     setBackgroundError(e); |                     setBackgroundError(e); | ||||||
|                 } |                 } | ||||||
|  | @ -215,20 +219,20 @@ const ConfigDialog: FC<{ | ||||||
|                 if (idx == null) return; |                 if (idx == null) return; | ||||||
|                 setIconErrors(makeIconErrors(idx, '')); |                 setIconErrors(makeIconErrors(idx, '')); | ||||||
|                 try { |                 try { | ||||||
|                     const compressFile = await canvasToFile({ |                     const _file = enableFileSizeValidate | ||||||
|  |                         ? await canvasToFile({ | ||||||
|                               canvas: await createCanvasByImgSrc({ |                               canvas: await createCanvasByImgSrc({ | ||||||
|                                   imgSrc: await getFileBase64String(file), |                                   imgSrc: await getFileBase64String(file), | ||||||
|                               }), |                               }), | ||||||
|                               maxFileSize: 4 * 1024, |                               maxFileSize: 4 * 1024, | ||||||
|                     }); |                           }) | ||||||
|                     const compressFileBase64 = await getFileBase64String( |                         : file; | ||||||
|                         compressFile |                     const fileBase64 = await getFileBase64String(_file); | ||||||
|                     ); |  | ||||||
|                     updateCustomTheme( |                     updateCustomTheme( | ||||||
|                         'icons', |                         'icons', | ||||||
|                         customTheme.icons.map((icon, _idx) => |                         customTheme.icons.map((icon, _idx) => | ||||||
|                             _idx === idx |                             _idx === idx | ||||||
|                                 ? { ...icon, content: compressFileBase64 } |                                 ? { ...icon, content: fileBase64 } | ||||||
|                                 : icon |                                 : icon | ||||||
|                         ) |                         ) | ||||||
|                     ); |                     ); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 streakingman
						streakingman