Skip to content

Commit

Permalink
Refactor media file handling in exportActorProfile for improved modul…
Browse files Browse the repository at this point in the history
…arity
  • Loading branch information
0marSalah authored and dmitrizagidulin committed Dec 12, 2024
1 parent df2d6d9 commit 2ed6ff0
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,7 @@ export async function exportActorProfile({

return {
addMediaFile(fileName: string, buffer: ArrayBuffer, contentType: string) {
pack.entry(
{
name: `media/${fileName}`,
size: buffer.byteLength
},
Buffer.from(buffer)
)

// Add media metadata to the manifest
manifest.contents.media.contents[fileName] = {
type: contentType,
size: buffer.byteLength,
lastModified: new Date().toISOString()
}
addMediaFile(pack, manifest, fileName, buffer, contentType)
},

finalize() {
Expand Down Expand Up @@ -244,3 +231,26 @@ export async function importActorProfile(tarBuffer: Buffer): Promise<any> {
stream.pipe(extract)
})
}

function addMediaFile(
pack: Pack,
manifest: any,
fileName: string,
buffer: ArrayBuffer,
contentType: string
): void {
pack.entry(
{
name: `media/${fileName}`,
size: buffer.byteLength
},
Buffer.from(buffer)
)

// Add media metadata to the manifest
manifest.contents.media.contents[fileName] = {
type: contentType,
size: buffer.byteLength,
lastModified: new Date().toISOString()
}
}

0 comments on commit 2ed6ff0

Please sign in to comment.