@@ -2,7 +2,7 @@ import { ref } from 'vue'
22import { createStorage } from 'unstorage'
33import indexedDbDriver from 'unstorage/drivers/indexedb'
44import { joinURL , withLeadingSlash } from 'ufo'
5- import type { DraftItem , StudioHost , GithubFile , MediaItem } from '../types'
5+ import type { DraftItem , StudioHost , GithubFile , MediaItem , RawFile } from '../types'
66import { DraftStatus } from '../types/draft'
77import type { useGit } from './useGit'
88import { getDraftStatus } from '../utils/draft'
@@ -11,7 +11,7 @@ import { useHooks } from './useHooks'
1111
1212const storage = createStorage ( {
1313 driver : indexedDbDriver ( {
14- dbName : 'nuxt- content-studio-media' ,
14+ dbName : 'content-studio-media' ,
1515 storeName : 'drafts' ,
1616 } ) ,
1717} )
@@ -34,7 +34,7 @@ export const useDraftMedias = createSharedComposable((host: StudioHost, git: Ret
3434 }
3535
3636 const fsPath = host . media . getFileSystemPath ( media . id )
37- const githubFile = await git . fetchFile ( fsPath , { cached : true } ) as GithubFile
37+ const githubFile = await git . fetchFile ( joinURL ( 'public' , fsPath ) , { cached : true } ) as GithubFile
3838
3939 const item : DraftItem = {
4040 id : media . id ,
@@ -95,7 +95,7 @@ export const useDraftMedias = createSharedComposable((host: StudioHost, git: Ret
9595 }
9696 else {
9797 // Fetch github file before creating draft to detect non deployed changes
98- const githubFile = await git . fetchFile ( fsPath , { cached : true } ) as GithubFile
98+ const githubFile = await git . fetchFile ( joinURL ( 'public' , fsPath ) , { cached : true } ) as GithubFile
9999 const original = await host . media . get ( id )
100100
101101 const deleteItem : DraftItem = {
@@ -258,6 +258,21 @@ export const useDraftMedias = createSharedComposable((host: StudioHost, git: Ret
258258 } )
259259 }
260260
261+ async function generateRawFiles ( ) : Promise < RawFile [ ] > {
262+ const files = [ ] as RawFile [ ]
263+ for ( const draftItem of list . value ) {
264+ if ( draftItem . status === DraftStatus . Deleted ) {
265+ files . push ( { path : joinURL ( 'public' , draftItem . fsPath ) , content : null , status : draftItem . status , encoding : 'base64' } )
266+ continue
267+ }
268+
269+ const content = ( await draftItem . modified ?. raw as string ) . replace ( / ^ d a t a : \w + \/ \w + ; b a s e 6 4 , / , '' )
270+ files . push ( { path : joinURL ( 'public' , draftItem . fsPath ) , content, status : draftItem . status , encoding : 'base64' } )
271+ }
272+
273+ return files
274+ }
275+
261276 return {
262277 get,
263278 create,
@@ -271,5 +286,6 @@ export const useDraftMedias = createSharedComposable((host: StudioHost, git: Ret
271286 select,
272287 selectById,
273288 upload,
289+ generateRawFiles,
274290 }
275291} )
0 commit comments