File tree Expand file tree Collapse file tree 2 files changed +31
-13
lines changed
Expand file tree Collapse file tree 2 files changed +31
-13
lines changed Original file line number Diff line number Diff line change 1+ import { DefaultException } from '@/utils/exception'
12import { client } from './common'
23
4+ const maxFileSize = 32 * 1024 * 1024 // 32MB
5+
36/**
47 * Convert Scratch project (.sb2/.sb3) to XBuilder project (.xbp) via backend `/scratch-convert` endpoint.
58 * The backend is expected to return the converted xbp as binary response (200).
69 *
710 * Uses shared `client` so token, Sentry headers and timeout behavior are consistent with other APIs.
8- *
9- * @param file - The Scratch project file (.sb2 or .sb3) to convert
10- * @param signal - Optional AbortSignal to cancel the request
11- * @returns Promise that resolves to a Blob containing the converted .xbp file
12- * @throws {ApiException } When the server returns an error response
13- * @throws {TimeoutException } When the request exceeds the timeout duration
1411 */
1512export async function convertScratchToXbp ( file : File , signal ?: AbortSignal ) {
16- const MAX_FILE_SIZE = 32 * 1024 * 1024 // 32MB
17- if ( file . size > MAX_FILE_SIZE ) {
18- throw new Error ( 'File too large. Maximum size is 32MB' )
13+ if ( file . size > maxFileSize ) {
14+ throw new DefaultException ( { en : 'File too large. Maximum size is 32MB' , zh : '文件太大,最大支持 32MB' } )
1915 }
2016 const form = new FormData ( )
2117 form . append ( 'file' , file , file . name )
Original file line number Diff line number Diff line change 2121 <template #icon ><img :src =" importProjectSvg" /></template >
2222 {{ $t({ en: 'Import project file...', zh: '导入项目文件...' }) }}
2323 </UIMenuItem >
24-
25- <UIMenuItem @click =" handleImportFromScratch" >
24+ <UIMenuItem class =" import-scratch" @click =" handleImportFromScratch" >
2625 <template #icon ><img :src =" importScratchSvg" /></template >
27- {{ $t({ en: 'Import Scratch project file', zh: '导入 Scratch 项目文件' }) }}
26+ <span class =" item-text" >
27+ {{ $t({ en: 'Import Scratch project file', zh: '导入 Scratch 项目文件' }) }}
28+ </span >
29+ <!-- TODO: temporary, will be handled uniformly after the tag design specification is complete -->
30+ <div class =" beta" >Beta</div >
2831 </UIMenuItem >
29-
3032 <UIMenuItem @click =" handleImportAssetsFromScratch" >
3133 <template #icon ><img :src =" importAssetsScratchSvg" /></template >
3234 {{ $t({ en: 'Import assets from Scratch', zh: '从 Scratch 项目文件导入素材' }) }}
@@ -388,6 +390,26 @@ const autoSaveStateIcon = computed<AutoSaveStateIcon | null>(() => {
388390 </script >
389391
390392<style lang="scss" scoped>
393+ .import-scratch {
394+ padding : 8px ;
395+
396+ .item-text {
397+ flex : 1 ;
398+ margin-right : 8px ;
399+ }
400+
401+ .beta {
402+ height : 20px ;
403+ border-radius : 4px ;
404+ border : 1px solid var (--ui-color-grey-400 );
405+ background : var (--ui-color-grey-300 );
406+ padding : 0 8px ;
407+ font-size : 12px ;
408+ line-height : 20px ;
409+ color : var (--ui-color-grey-900 );
410+ }
411+ }
412+
391413.owner-info ,
392414.project-name {
393415 overflow : hidden ;
You can’t perform that action at this time.
0 commit comments